Merge "ORMRow must not ignore failures on insert by deault."
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 6 Nov 2012 20:57:57 +0000 (20:57 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 6 Nov 2012 20:57:57 +0000 (20:57 +0000)
1  2 
includes/db/ORMRow.php

diff --combined includes/db/ORMRow.php
@@@ -263,8 -263,10 +263,10 @@@ abstract class ORMRow implements IORMRo
                                switch ( $type ) {
                                        case 'array':
                                                $value = (array)$value;
+                                               // fall-through!
                                        case 'blob':
                                                $value = serialize( $value );
+                                               // fall-through!
                                }
  
                                $values[$this->table->getPrefixedField( $name )] = $value;
         * @return boolean Success indicator
         */
        protected function saveExisting( $functionName = null ) {
 -              $dbw = wfGetDB( DB_MASTER );
 +              $dbw = $this->table->getWriteDbConnection();
  
                $success = $dbw->update(
                        $this->table->getName(),
                        is_null( $functionName ) ? __METHOD__ : $functionName
                );
  
 +              $this->table->releaseConnection( $dbw );
 +
                // DatabaseBase::update does not always return true for success as documented...
                return $success !== false;
        }
         * @return boolean Success indicator
         */
        protected function insert( $functionName = null, array $options = null ) {
 -              $dbw = wfGetDB( DB_MASTER );
 +              $dbw = $this->table->getWriteDbConnection();
  
                $success = $dbw->insert(
                        $this->table->getName(),
                        $this->getWriteValues(),
                        is_null( $functionName ) ? __METHOD__ : $functionName,
-                       is_null( $options ) ? array( 'IGNORE' ) : $options
+                       $options
                );
  
                // DatabaseBase::insert does not always return true for success as documented...
                        $this->setField( 'id', $dbw->insertId() );
                }
  
 +              $this->table->releaseConnection( $dbw );
 +
                return $success;
        }
  
                $absoluteAmount = abs( $amount );
                $isNegative = $amount < 0;
  
 -              $dbw = wfGetDB( DB_MASTER );
 +              $dbw = $this->table->getWriteDbConnection();
  
                $fullField = $this->table->getPrefixedField( $field );
  
                        $this->setField( $field, $this->getField( $field ) + $amount );
                }
  
 +              $this->table->releaseConnection( $dbw );
 +
                return $success;
        }