r111209 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111208‎ | r111209 | r111210 >
Date:22:34, 10 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixed fatal when invalid username provided and fixes to secondary storage stuff
Modified paths:
  • /trunk/extensions/EducationProgram/api/ApiEnlist.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -176,7 +176,7 @@
177177 */
178178 public function loadSummaryFields( $summaryFields = null ) {
179179 if ( is_null( $summaryFields ) ) {
180 - $summaryFields = array( 'org_id', 'student_count', 'instructor_count', 'oa_count', 'ca_count' );
 180+ $summaryFields = array( 'org_id' );
181181 }
182182 else {
183183 $summaryFields = (array)$summaryFields;
@@ -188,12 +188,6 @@
189189 $fields['org_id'] = $this->getField( 'org_id' );
190190 }
191191
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 -
198192 $this->setFields( $fields );
199193 }
200194
@@ -231,7 +225,6 @@
232226 */
233227 protected function onUpdated( EPRevisionedObject $originalCourse ) {
234228 if ( $this->updateSummaries ) {
235 - $removedIds = array();
236229 $newUsers = array();
237230 $changedSummaries = array();
238231
@@ -244,6 +237,8 @@
245238
246239 $countMap = array_flip( self::$countMap );
247240
 241+ $dbw = wfGetDB( DB_MASTER );
 242+
248243 foreach ( array( 'online_ambs', 'campus_ambs', 'students', 'instructors' ) as $usersField ) {
249244 if ( $this->hasField( $usersField ) && $originalCourse->getField( $usersField ) !== $this->getField( $usersField ) ) {
250245 $removedIds = array_diff( $originalCourse->getField( $usersField ), $this->getField( $usersField ) );
@@ -258,21 +253,19 @@
259254 }
260255
261256 if ( !empty( $removedIds ) || !empty( $addedIds ) ) {
262 - $this->loadSummaryFields( $countMap[$usersField] );
263257 $changedSummaries[] = $countMap[$usersField];
264258 }
 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+ }
265267 }
266268 }
267269
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 -
277270 if ( count( $newUsers ) > 0 ) {
278271 $dbw->begin();
279272
@@ -283,12 +276,6 @@
284277 $dbw->commit();
285278 }
286279
287 - if ( !empty( $changedSummaries ) ) {
288 - $this->setSummaryMode( true );
289 - $this->saveExisting();
290 - $this->setSummaryMode( false );
291 - }
292 -
293280 if ( $this->hasField( 'org_id' ) && $originalCourse->getField( 'org_id' ) !== $this->getField( 'org_id' ) ) {
294281 $conds = array( 'id' => array( $originalCourse->getField( 'org_id' ), $this->getField( 'org_id' ) ) );
295282 EPOrg::updateSummaryFields( null, $conds );
@@ -310,6 +297,13 @@
311298 $this->setField( 'name', $GLOBALS['wgLang']->ucfirst( $this->getField( 'name' ) ) );
312299 }
313300
 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+
314308 return parent::save();
315309 }
316310
Index: trunk/extensions/EducationProgram/api/ApiEnlist.php
@@ -23,7 +23,7 @@
2424
2525 if ( isset( $params['username'] ) ) {
2626 $user = User::newFromName( $params['username'] );
27 - $userId = $user->getId();
 27+ $userId = $user === false ? 0 : $user->getId();
2828 }
2929 else {
3030 $userId = $params['userid'];

Status & tagging log