r113927 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113926‎ | r113927 | r113928 >
Date:15:59, 15 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fix regression. fields are no needlessly loaded now before save, but we still need the id
Modified paths:
  • /trunk/extensions/EducationProgram/includes/DBDataObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRoleObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php
@@ -122,6 +122,11 @@
123123 'cssclass' => 'commons-input',
124124 );
125125
 126+ $fields['id'] = array(
 127+ 'type' => 'hidden',
 128+ 'default' => $ambassador->getId(),
 129+ );
 130+
126131 return $fields;
127132 }
128133
@@ -132,10 +137,9 @@
133138 */
134139 public function onSuccess() {
135140 $class = $this->getClassName();
136 - $ambassador = $class::newFromUser( $this->getUser() );
137141
138142 EPUtils::log( array(
139 - 'type' => $ambassador->getRoleName(),
 143+ 'type' => $class::newFromUser( $this->getUser() )->getRoleName(),
140144 'subtype' => 'profilesave',
141145 'user' => $this->getUser(),
142146 'title' => $this->getTitle(),
@@ -155,8 +159,10 @@
156160 */
157161 public function onSubmit( array $data ) {
158162 $class = $this->getClassName();
 163+
159164 $ambassador = $class::newFromUser( $this->getUser() );
160165 $ambassador->setFields( $data );
 166+
161167 return $ambassador->save() ? true : array();
162168 }
163169
Index: trunk/extensions/EducationProgram/includes/DBDataObject.php
@@ -363,7 +363,7 @@
364364 $success = $dbw->update(
365365 $this->table->getDBTable(),
366366 $this->getWriteValues(),
367 - array( $this->table->getPrefixedField( 'id' ) => $this->getId() ),
 367+ $this->table->getPrefixedValues( $this->getUpdateConditions() ),
368368 is_null( $functionName ) ? __METHOD__ : $functionName
369369 );
370370
@@ -371,6 +371,18 @@
372372 }
373373
374374 /**
 375+ * Returns the WHERE considtions needed to identify this object so
 376+ * it can be updated.
 377+ *
 378+ * @since 1.20
 379+ *
 380+ * @return array
 381+ */
 382+ protected function getUpdateConditions() {
 383+ return array( 'id' => $this->getId() );
 384+ }
 385+
 386+ /**
375387 * Inserts the object into the database.
376388 *
377389 * @since 1.20
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php
@@ -265,7 +265,15 @@
266266
267267 return $courses;
268268 }
269 -
 269+
 270+ /**
 271+ * Returns the role ID for the object by looking it up
 272+ * in a map using it's name.
 273+ *
 274+ * @since 0.1
 275+ *
 276+ * @return integer, part of EP_ enum.
 277+ */
270278 protected function getRoleId() {
271279 $map = array(
272280 'campus' => EP_CA,
@@ -276,5 +284,25 @@
277285
278286 return $map[$this->getRoleName()];
279287 }
 288+
 289+ /**
 290+ * @see DBDataObject::getUpdateConditions()
 291+ *
 292+ * Always adding the user ID to the list of consitions,
 293+ * even when not loaded yet (a new query will be done),
 294+ * so that it's not possible to update an existing user
 295+ * with a wrong user ID.
 296+ *
 297+ * @since 0.1
 298+ *
 299+ * @return array
 300+ */
 301+ protected function getUpdateConditions() {
 302+ $conds = parent::getUpdateConditions();
 303+
 304+ $conds['user_id'] = $this->loadAndGetField( 'user_id' );
 305+
 306+ return $conds;
 307+ }
280308
281309 }
\ No newline at end of file

Status & tagging log