Index: trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php |
— | — | @@ -122,6 +122,11 @@ |
123 | 123 | 'cssclass' => 'commons-input', |
124 | 124 | ); |
125 | 125 | |
| 126 | + $fields['id'] = array( |
| 127 | + 'type' => 'hidden', |
| 128 | + 'default' => $ambassador->getId(), |
| 129 | + ); |
| 130 | + |
126 | 131 | return $fields; |
127 | 132 | } |
128 | 133 | |
— | — | @@ -132,10 +137,9 @@ |
133 | 138 | */ |
134 | 139 | public function onSuccess() { |
135 | 140 | $class = $this->getClassName(); |
136 | | - $ambassador = $class::newFromUser( $this->getUser() ); |
137 | 141 | |
138 | 142 | EPUtils::log( array( |
139 | | - 'type' => $ambassador->getRoleName(), |
| 143 | + 'type' => $class::newFromUser( $this->getUser() )->getRoleName(), |
140 | 144 | 'subtype' => 'profilesave', |
141 | 145 | 'user' => $this->getUser(), |
142 | 146 | 'title' => $this->getTitle(), |
— | — | @@ -155,8 +159,10 @@ |
156 | 160 | */ |
157 | 161 | public function onSubmit( array $data ) { |
158 | 162 | $class = $this->getClassName(); |
| 163 | + |
159 | 164 | $ambassador = $class::newFromUser( $this->getUser() ); |
160 | 165 | $ambassador->setFields( $data ); |
| 166 | + |
161 | 167 | return $ambassador->save() ? true : array(); |
162 | 168 | } |
163 | 169 | |
Index: trunk/extensions/EducationProgram/includes/DBDataObject.php |
— | — | @@ -363,7 +363,7 @@ |
364 | 364 | $success = $dbw->update( |
365 | 365 | $this->table->getDBTable(), |
366 | 366 | $this->getWriteValues(), |
367 | | - array( $this->table->getPrefixedField( 'id' ) => $this->getId() ), |
| 367 | + $this->table->getPrefixedValues( $this->getUpdateConditions() ), |
368 | 368 | is_null( $functionName ) ? __METHOD__ : $functionName |
369 | 369 | ); |
370 | 370 | |
— | — | @@ -371,6 +371,18 @@ |
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
| 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 | + /** |
375 | 387 | * Inserts the object into the database. |
376 | 388 | * |
377 | 389 | * @since 1.20 |
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php |
— | — | @@ -265,7 +265,15 @@ |
266 | 266 | |
267 | 267 | return $courses; |
268 | 268 | } |
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 | + */ |
270 | 278 | protected function getRoleId() { |
271 | 279 | $map = array( |
272 | 280 | 'campus' => EP_CA, |
— | — | @@ -276,5 +284,25 @@ |
277 | 285 | |
278 | 286 | return $map[$this->getRoleName()]; |
279 | 287 | } |
| 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 | + } |
280 | 308 | |
281 | 309 | } |
\ No newline at end of file |