r96284 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96283‎ | r96284 | r96285 >
Date:15:59, 5 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
follow up to r96266
Modified paths:
  • /trunk/extensions/Survey/includes/Survey.class.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyDBClass.php (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialSurvey.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Survey/specials/SpecialSurvey.php
@@ -46,7 +46,7 @@
4747 }
4848
4949 if ( $survey === false ) {
50 - $survey = new Survey( null, $subPage );
 50+ $survey = new Survey( array( 'name' => $subPage ) );
5151 }
5252
5353 $this->showSurvey( $survey );
@@ -74,8 +74,8 @@
7575 $survey = Survey::newFromId( $wgRequest->getInt( 'survey-id' ), null, false );
7676 }
7777
78 - $survey->setName( $wgRequest->getText( 'survey-name' ) );
79 - $survey->setEnabled( $wgRequest->getCheck( 'survey-enabled' ) );
 78+ $survey->setField( 'name', $wgRequest->getText( 'survey-name' ) );
 79+ $survey->setField( 'enabled', $wgRequest->getCheck( 'survey-enabled' ) );
8080
8181 $survey->setQuestions( $this->getSubmittedQuestions() );
8282
@@ -127,16 +127,16 @@
128128 $questionId = "new-$questionId";
129129 }
130130 else {
131 - $questionId = $questionId;
 131+ $questionDbId = $questionId;
132132 }
133133
134 - $question = new SurveyQuestion(
135 - $questionDbId,
136 - 0,
137 - $wgRequest->getText( "survey-question-text-$questionId" ),
138 - $wgRequest->getInt( "survey-question-type-$questionId" ),
139 - $wgRequest->getCheck( "survey-question-required-$questionId" )
140 - );
 134+ $question = new SurveyQuestion( array(
 135+ 'id' => $questionDbId,
 136+ 'removed' => 0,
 137+ 'text' => $wgRequest->getText( "survey-question-text-$questionId" ),
 138+ 'type' => $wgRequest->getInt( "survey-question-type-$questionId" ),
 139+ 'required' => $wgRequest->getCheck( "survey-question-required-$questionId" )
 140+ ) );
141141
142142 return $question;
143143 }
Index: trunk/extensions/Survey/includes/SurveyDBClass.php
@@ -30,9 +30,12 @@
3131 * @param array|null $fields
3232 */
3333 public function __construct( $fields ) {
34 - if ( !is_null( $fields ) ) {
 34+ if ( is_array( $fields ) ) {
3535 $this->setFields( $fields );
3636 }
 37+ else {
 38+ throw new Exception('');
 39+ }
3740 }
3841
3942 /**
@@ -203,11 +206,11 @@
204207 * @return boolean Success indicator
205208 */
206209 public function writeToDB() {
207 - if ( $this->hadIdField() ) {
208 - return $this->insertIntoDB();
 210+ if ( $this->hasIdField() ) {
 211+ return $this->updateInDB();
209212 }
210213 else {
211 - return $this->updateInDB();
 214+ return $this->insertIntoDB();
212215 }
213216 }
214217
@@ -379,6 +382,17 @@
380383 public function getId() {
381384 return $this->getField( static::getIDField() );
382385 }
 386+
 387+ /**
 388+ * Sets the objects database id.
 389+ *
 390+ * @since 0.1
 391+ *
 392+ * @param integere|null $id
 393+ */
 394+ public function setId( $id ) {
 395+ return $this->setField( static::getIDField(), $id );
 396+ }
383397
384398 /**
385399 * Gets if a certain field is set.
@@ -442,14 +456,16 @@
443457 $values = array();
444458
445459 foreach ( static::getFieldTypes() as $name => $type ) {
446 - $value = $this->fields[$name];
447 -
448 - switch ( $type ) {
449 - case 'array':
450 - $value = serialize( (array)$value );
 460+ if ( array_key_exists( $name, $this->fields ) ) {
 461+ $value = $this->fields[$name];
 462+
 463+ switch ( $type ) {
 464+ case 'array':
 465+ $value = serialize( (array)$value );
 466+ }
 467+
 468+ $values[static::getFieldPrefix() . $name] = $value;
451469 }
452 -
453 - $values[static::getFieldPrefix() . $name] = $value;
454470 }
455471
456472 return $values;
Index: trunk/extensions/Survey/includes/Survey.class.php
@@ -134,7 +134,7 @@
135135 $dbw->begin();
136136
137137 foreach ( $this->questions as /* SurveyQuestion */ $question ) {
138 - $question->setSurveyId( $this->getId() );
 138+ $question->setId( $this->getId() );
139139 $success = $question->writeToDB() && $success;
140140 }
141141

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96266work on db object classesjeroendedauw01:45, 5 September 2011

Status & tagging log