r111498 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111497‎ | r111498 | r111499 >
Date:21:42, 14 February 2012
Author:jeroendedauw
Status:reverted
Tags:
Comment:
follow up to r111468 - fixed various issues caused by refactoring
Modified paths:
  • /trunk/phase3/includes/DBDataObject.php (modified) (history)
  • /trunk/phase3/includes/DBTable.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DBDataObject.php
@@ -129,7 +129,7 @@
130130 }
131131
132132 if ( is_null( $fields ) ) {
133 - $fields = array_keys( $this->getFieldTypes() );
 133+ $fields = array_keys( $this->table->getFieldTypes() );
134134 }
135135
136136 if ( $skipLoaded ) {
@@ -137,14 +137,14 @@
138138 }
139139
140140 if ( count( $fields ) > 0 ) {
141 - $result = $this->rawSelectRow(
142 - $this->getPrefixedFields( $fields ),
143 - array( $this->getPrefixedField( 'id' ) => $this->getId() ),
 141+ $result = $this->table->rawSelectRow(
 142+ $this->table->getPrefixedFields( $fields ),
 143+ array( $this->table->getPrefixedField( 'id' ) => $this->getId() ),
144144 array( 'LIMIT' => 1 )
145145 );
146146
147147 if ( $result !== false ) {
148 - $this->setFields( $this->getFieldsFromDBResult( $result ), $override );
 148+ $this->setFields( $this->table->getFieldsFromDBResult( $result ), $override );
149149 return true;
150150 }
151151
@@ -276,7 +276,7 @@
277277 protected function getWriteValues() {
278278 $values = array();
279279
280 - foreach ( $this->getFieldTypes() as $name => $type ) {
 280+ foreach ( $this->table->getFieldTypes() as $name => $type ) {
281281 if ( array_key_exists( $name, $this->fields ) ) {
282282 $value = $this->fields[$name];
283283
@@ -287,7 +287,7 @@
288288 $value = serialize( $value );
289289 }
290290
291 - $values[$this->getFieldPrefix() . $name] = $value;
 291+ $values[$this->table->getPrefixedField( $name )] = $value;
292292 }
293293 }
294294
@@ -336,7 +336,7 @@
337337 * @param boolean $override
338338 */
339339 public function loadDefaults( $override = true ) {
340 - $this->setFields( $this->getDefaults(), $override );
 340+ $this->setFields( $this->table->getDefaults(), $override );
341341 }
342342
343343 /**
@@ -366,9 +366,9 @@
367367 $dbw = wfGetDB( DB_MASTER );
368368
369369 $success = $dbw->update(
370 - $this->getDBTable(),
 370+ $this->table->getDBTable(),
371371 $this->getWriteValues(),
372 - array( $this->getFieldPrefix() . 'id' => $this->getId() ),
 372+ array( $this->table->getPrefixedField( 'id' ) => $this->getId() ),
373373 __METHOD__
374374 );
375375
@@ -386,7 +386,7 @@
387387 $dbw = wfGetDB( DB_MASTER );
388388
389389 $result = $dbw->insert(
390 - $this->getDBTable(),
 390+ $this->table->getDBTable(),
391391 $this->getWriteValues(),
392392 __METHOD__,
393393 array( 'IGNORE' )
@@ -409,7 +409,7 @@
410410 public function remove() {
411411 $this->beforeRemove();
412412
413 - $success = static::delete( array( 'id' => $this->getId() ) );
 413+ $success = $this->table->delete( array( 'id' => $this->getId() ) );
414414
415415 if ( $success ) {
416416 $this->onRemoved();
@@ -588,12 +588,12 @@
589589
590590 $dbw = wfGetDB( DB_MASTER );
591591
592 - $fullField = $this->getPrefixedField( $field );
 592+ $fullField = $this->table->getPrefixedField( $field );
593593
594594 $success = $dbw->update(
595 - $this->getDBTable(),
 595+ $this->table->getDBTable(),
596596 array( "$fullField=$fullField" . ( $isNegative ? '-' : '+' ) . $absoluteAmount ),
597 - array( $this->getPrefixedField( 'id' ) => $this->getId() ),
 597+ array( $this->table->getPrefixedField( 'id' ) => $this->getId() ),
598598 __METHOD__
599599 );
600600
@@ -605,30 +605,6 @@
606606 }
607607
608608 /**
609 - * Selects the the specified fields of the records matching the provided
610 - * conditions. Field names do NOT get prefixed.
611 - *
612 - * @since 1.20
613 - *
614 - * @param array $fields
615 - * @param array $conditions
616 - * @param array $options
617 - *
618 - * @return ResultWrapper
619 - */
620 - protected static function rawSelectRow( array $fields, array $conditions = array(), array $options = array() ) {
621 - $dbr = wfGetDB( static::getReadDb() );
622 -
623 - return $dbr->selectRow(
624 - static::getDBTable(),
625 - $fields,
626 - $conditions,
627 - __METHOD__,
628 - $options
629 - );
630 - }
631 -
632 - /**
633609 * Return the names of the fields.
634610 *
635611 * @since 1.20
@@ -684,7 +660,7 @@
685661 */
686662 protected function fieldsChanged( DBDataObject $object, $excludeSummaryFields = false ) {
687663 foreach ( $this->fields as $name => $value ) {
688 - $excluded = $excludeSummaryFields && in_array( $name, $this->getSummaryFields() );
 664+ $excluded = $excludeSummaryFields && in_array( $name, $this->table->getSummaryFields() );
689665
690666 if ( !$excluded && $object->getField( $name ) !== $value ) {
691667 return true;
Index: trunk/phase3/includes/DBTable.php
@@ -201,6 +201,30 @@
202202 }
203203
204204 /**
 205+ * Selects the the specified fields of the records matching the provided
 206+ * conditions. Field names do NOT get prefixed.
 207+ *
 208+ * @since 1.20
 209+ *
 210+ * @param array $fields
 211+ * @param array $conditions
 212+ * @param array $options
 213+ *
 214+ * @return ResultWrapper
 215+ */
 216+ public function rawSelectRow( array $fields, array $conditions = array(), array $options = array() ) {
 217+ $dbr = wfGetDB( $this->getReadDb() );
 218+
 219+ return $dbr->selectRow(
 220+ $this->getDBTable(),
 221+ $fields,
 222+ $conditions,
 223+ __METHOD__,
 224+ $options
 225+ );
 226+ }
 227+
 228+ /**
205229 * Selects the the specified fields of the first record matching the provided
206230 * conditions and returns it as an associative array, or false when nothing matches.
207231 * This method makes use of selectFields and expects the same parameters and

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111468follow up to r111264; split up class into one representing a table and one re...jeroendedauw18:11, 14 February 2012

Status & tagging log