Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -176,7 +176,7 @@ |
177 | 177 | */ |
178 | 178 | public function loadSummaryFields( $summaryFields = null ) { |
179 | 179 | if ( is_null( $summaryFields ) ) { |
180 | | - $summaryFields = array( 'org_id', 'student_count', 'instructor_count', 'oa_count', 'ca_count' ); |
| 180 | + $summaryFields = array( 'org_id' ); |
181 | 181 | } |
182 | 182 | else { |
183 | 183 | $summaryFields = (array)$summaryFields; |
— | — | @@ -188,12 +188,6 @@ |
189 | 189 | $fields['org_id'] = $this->getField( 'org_id' ); |
190 | 190 | } |
191 | 191 | |
192 | | - foreach ( array( 'student_count', 'instructor_count', 'oa_count', 'ca_count' ) as $field ) { |
193 | | - if ( in_array( $field, $summaryFields ) ) { |
194 | | - $fields[$field] = count( $this->getField( self::$countMap[$field] ) ); |
195 | | - } |
196 | | - } |
197 | | - |
198 | 192 | $this->setFields( $fields ); |
199 | 193 | } |
200 | 194 | |
— | — | @@ -231,7 +225,6 @@ |
232 | 226 | */ |
233 | 227 | protected function onUpdated( EPRevisionedObject $originalCourse ) { |
234 | 228 | if ( $this->updateSummaries ) { |
235 | | - $removedIds = array(); |
236 | 229 | $newUsers = array(); |
237 | 230 | $changedSummaries = array(); |
238 | 231 | |
— | — | @@ -244,6 +237,8 @@ |
245 | 238 | |
246 | 239 | $countMap = array_flip( self::$countMap ); |
247 | 240 | |
| 241 | + $dbw = wfGetDB( DB_MASTER ); |
| 242 | + |
248 | 243 | foreach ( array( 'online_ambs', 'campus_ambs', 'students', 'instructors' ) as $usersField ) { |
249 | 244 | if ( $this->hasField( $usersField ) && $originalCourse->getField( $usersField ) !== $this->getField( $usersField ) ) { |
250 | 245 | $removedIds = array_diff( $originalCourse->getField( $usersField ), $this->getField( $usersField ) ); |
— | — | @@ -258,21 +253,19 @@ |
259 | 254 | } |
260 | 255 | |
261 | 256 | if ( !empty( $removedIds ) || !empty( $addedIds ) ) { |
262 | | - $this->loadSummaryFields( $countMap[$usersField] ); |
263 | 257 | $changedSummaries[] = $countMap[$usersField]; |
264 | 258 | } |
| 259 | + |
| 260 | + if ( count( $removedIds ) > 0 ) { |
| 261 | + $dbw->delete( 'ep_users_per_course', array( |
| 262 | + 'upc_course_id' => $this->getId(), |
| 263 | + 'upc_user_id' => $removedIds, |
| 264 | + 'upc_role' => $roleMap[$usersField], |
| 265 | + ) ); |
| 266 | + } |
265 | 267 | } |
266 | 268 | } |
267 | 269 | |
268 | | - $dbw = wfGetDB( DB_MASTER ); |
269 | | - |
270 | | - if ( count( $removedIds ) > 0 ) { |
271 | | - $dbw->delete( 'ep_users_per_course', array( |
272 | | - 'upc_course_id' => $this->getId(), |
273 | | - 'upc_user_id' => $removedIds |
274 | | - ) ); |
275 | | - } |
276 | | - |
277 | 270 | if ( count( $newUsers ) > 0 ) { |
278 | 271 | $dbw->begin(); |
279 | 272 | |
— | — | @@ -283,12 +276,6 @@ |
284 | 277 | $dbw->commit(); |
285 | 278 | } |
286 | 279 | |
287 | | - if ( !empty( $changedSummaries ) ) { |
288 | | - $this->setSummaryMode( true ); |
289 | | - $this->saveExisting(); |
290 | | - $this->setSummaryMode( false ); |
291 | | - } |
292 | | - |
293 | 280 | if ( $this->hasField( 'org_id' ) && $originalCourse->getField( 'org_id' ) !== $this->getField( 'org_id' ) ) { |
294 | 281 | $conds = array( 'id' => array( $originalCourse->getField( 'org_id' ), $this->getField( 'org_id' ) ) ); |
295 | 282 | EPOrg::updateSummaryFields( null, $conds ); |
— | — | @@ -310,6 +297,13 @@ |
311 | 298 | $this->setField( 'name', $GLOBALS['wgLang']->ucfirst( $this->getField( 'name' ) ) ); |
312 | 299 | } |
313 | 300 | |
| 301 | + foreach ( array( 'student_count', 'instructor_count', 'oa_count', 'ca_count' ) as $summaryField ) { |
| 302 | + $field = self::$countMap[$summaryField]; |
| 303 | + if ( $this->hasField( $field ) ) { |
| 304 | + $this->setField( $summaryField, count( $this->getField( $field ) ) ); |
| 305 | + } |
| 306 | + } |
| 307 | + |
314 | 308 | return parent::save(); |
315 | 309 | } |
316 | 310 | |
Index: trunk/extensions/EducationProgram/api/ApiEnlist.php |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | |
25 | 25 | if ( isset( $params['username'] ) ) { |
26 | 26 | $user = User::newFromName( $params['username'] ); |
27 | | - $userId = $user->getId(); |
| 27 | + $userId = $user === false ? 0 : $user->getId(); |
28 | 28 | } |
29 | 29 | else { |
30 | 30 | $userId = $params['userid']; |