Merge "Make sure that SQLite uses no prefix"
[lhc/web/wiklou.git] / includes / db / ORMRow.php
index 6f19fe1..affd65f 100644 (file)
@@ -5,6 +5,8 @@
  * aims to be both simple and very flexible. It is centered around an associative
  * array of fields and various methods to do common interaction with the database.
  *
+ * Documentation inline and at https://www.mediawiki.org/wiki/Manual:ORMTable
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -25,7 +27,7 @@
  * @file ORMRow.php
  * @ingroup ORM
  *
- * @licence GNU GPL v2 or later
+ * @license GNU GPL v2 or later
  * @author Jeroen De Dauw < jeroendedauw@gmail.com >
  */
 
@@ -136,8 +138,9 @@ abstract class ORMRow implements IORMRow {
         *
         * @since 1.20
         *
-        * @param string $name
-        * @param mixed $default
+        * @param $name string: Field name
+        * @param $default mixed: Default value to return when none is found
+        * (default: null)
         *
         * @throws MWException
         * @return mixed
@@ -157,7 +160,7 @@ abstract class ORMRow implements IORMRow {
         *
         * @since 1.20
         *
-        * @param string$name
+        * @param $name string
         *
         * @return mixed
         */
@@ -260,8 +263,10 @@ abstract class ORMRow implements IORMRow {
                                switch ( $type ) {
                                        case 'array':
                                                $value = (array)$value;
+                                               // fall-through!
                                        case 'blob':
                                                $value = serialize( $value );
+                                               // fall-through!
                                }
 
                                $values[$this->table->getPrefixedField( $name )] = $value;
@@ -344,7 +349,7 @@ abstract class ORMRow implements IORMRow {
         * @return boolean Success indicator
         */
        protected function saveExisting( $functionName = null ) {
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->table->getWriteDbConnection();
 
                $success = $dbw->update(
                        $this->table->getName(),
@@ -353,6 +358,8 @@ abstract class ORMRow implements IORMRow {
                        is_null( $functionName ) ? __METHOD__ : $functionName
                );
 
+               $this->table->releaseConnection( $dbw );
+
                // DatabaseBase::update does not always return true for success as documented...
                return $success !== false;
        }
@@ -380,13 +387,13 @@ abstract class ORMRow implements IORMRow {
         * @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...
@@ -396,6 +403,8 @@ abstract class ORMRow implements IORMRow {
                        $this->setField( 'id', $dbw->insertId() );
                }
 
+               $this->table->releaseConnection( $dbw );
+
                return $success;
        }
 
@@ -555,7 +564,7 @@ abstract class ORMRow implements IORMRow {
                $absoluteAmount = abs( $amount );
                $isNegative = $amount < 0;
 
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->table->getWriteDbConnection();
 
                $fullField = $this->table->getPrefixedField( $field );
 
@@ -570,6 +579,8 @@ abstract class ORMRow implements IORMRow {
                        $this->setField( $field, $this->getField( $field ) + $amount );
                }
 
+               $this->table->releaseConnection( $dbw );
+
                return $success;
        }