https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113927
Revision: 113927
Author: jeroendedauw
Date: 2012-03-15 15:59:15 +0000 (Thu, 15 Mar 2012)
Log Message:
-----------
fix regression. fields are no needlessly loaded now before save, but we still
need the id
Modified Paths:
--------------
trunk/extensions/EducationProgram/includes/DBDataObject.php
trunk/extensions/EducationProgram/includes/EPRoleObject.php
trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php
Modified: trunk/extensions/EducationProgram/includes/DBDataObject.php
===================================================================
--- trunk/extensions/EducationProgram/includes/DBDataObject.php 2012-03-15
15:52:12 UTC (rev 113926)
+++ trunk/extensions/EducationProgram/includes/DBDataObject.php 2012-03-15
15:59:15 UTC (rev 113927)
@@ -363,7 +363,7 @@
$success = $dbw->update(
$this->table->getDBTable(),
$this->getWriteValues(),
- array( $this->table->getPrefixedField( 'id' ) =>
$this->getId() ),
+ $this->table->getPrefixedValues(
$this->getUpdateConditions() ),
is_null( $functionName ) ? __METHOD__ : $functionName
);
@@ -371,6 +371,18 @@
}
/**
+ * Returns the WHERE considtions needed to identify this object so
+ * it can be updated.
+ *
+ * @since 1.20
+ *
+ * @return array
+ */
+ protected function getUpdateConditions() {
+ return array( 'id' => $this->getId() );
+ }
+
+ /**
* Inserts the object into the database.
*
* @since 1.20
Modified: trunk/extensions/EducationProgram/includes/EPRoleObject.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPRoleObject.php 2012-03-15
15:52:12 UTC (rev 113926)
+++ trunk/extensions/EducationProgram/includes/EPRoleObject.php 2012-03-15
15:59:15 UTC (rev 113927)
@@ -265,7 +265,15 @@
return $courses;
}
-
+
+ /**
+ * Returns the role ID for the object by looking it up
+ * in a map using it's name.
+ *
+ * @since 0.1
+ *
+ * @return integer, part of EP_ enum.
+ */
protected function getRoleId() {
$map = array(
'campus' => EP_CA,
@@ -276,5 +284,25 @@
return $map[$this->getRoleName()];
}
+
+ /**
+ * @see DBDataObject::getUpdateConditions()
+ *
+ * Always adding the user ID to the list of consitions,
+ * even when not loaded yet (a new query will be done),
+ * so that it's not possible to update an existing user
+ * with a wrong user ID.
+ *
+ * @since 0.1
+ *
+ * @return array
+ */
+ protected function getUpdateConditions() {
+ $conds = parent::getUpdateConditions();
+
+ $conds['user_id'] = $this->loadAndGetField( 'user_id' );
+
+ return $conds;
+ }
}
\ No newline at end of file
Modified:
trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php
2012-03-15 15:52:12 UTC (rev 113926)
+++ trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php
2012-03-15 15:59:15 UTC (rev 113927)
@@ -122,6 +122,11 @@
'cssclass' => 'commons-input',
);
+ $fields['id'] = array(
+ 'type' => 'hidden',
+ 'default' => $ambassador->getId(),
+ );
+
return $fields;
}
@@ -132,10 +137,9 @@
*/
public function onSuccess() {
$class = $this->getClassName();
- $ambassador = $class::newFromUser( $this->getUser() );
EPUtils::log( array(
- 'type' => $ambassador->getRoleName(),
+ 'type' => $class::newFromUser( $this->getUser()
)->getRoleName(),
'subtype' => 'profilesave',
'user' => $this->getUser(),
'title' => $this->getTitle(),
@@ -155,8 +159,10 @@
*/
public function onSubmit( array $data ) {
$class = $this->getClassName();
+
$ambassador = $class::newFromUser( $this->getUser() );
$ambassador->setFields( $data );
+
return $ambassador->save() ? true : array();
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs