Merge "Send correct HTML when reporting a MWException object and the OuputPage object...
[lhc/web/wiklou.git] / includes / db / ORMRow.php
index a063f72..6f19fe1 100644 (file)
@@ -1,43 +1,35 @@
 <?php
-
 /**
  * Abstract base class for representing objects that are stored in some DB table.
  * This is basically an ORM-like wrapper around rows in database tables that
  * 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.
  *
- * These methods are likely candidates for overriding:
- * * getDefaults
- * * remove
- * * insert
- * * saveExisting
- * * loadSummaryFields
- * * getSummaryFields
+ * 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
+ * (at your option) any later version.
  *
- * Main instance methods:
- * * getField(s)
- * * setField(s)
- * * save
- * * remove
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
  *
- * Main static methods:
- * * select
- * * update
- * * delete
- * * count
- * * has
- * * selectRow
- * * selectFields
- * * selectFieldsRow
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
  *
  * @since 1.20
  *
  * @file ORMRow.php
+ * @ingroup ORM
  *
  * @licence GNU GPL v2 or later
  * @author Jeroen De Dauw < jeroendedauw@gmail.com >
  */
-abstract class ORMRow {
+
+abstract class ORMRow implements IORMRow {
 
        /**
         * The fields of the object.
@@ -80,11 +72,11 @@ abstract class ORMRow {
         *
         * @since 1.20
         *
-        * @param ORMTable $table
+        * @param IORMTable $table
         * @param array|null $fields
         * @param boolean $loadDefaults
         */
-       public function __construct( ORMTable $table, $fields = null, $loadDefaults = false ) {
+       public function __construct( IORMTable $table, $fields = null, $loadDefaults = false ) {
                $this->table = $table;
 
                if ( !is_array( $fields ) ) {
@@ -207,7 +199,7 @@ abstract class ORMRow {
         * @param integer|null $id
         */
        public function setId( $id ) {
-               return $this->setField( 'id', $id );
+               $this->setField( 'id', $id );
        }
 
        /**
@@ -316,7 +308,7 @@ abstract class ORMRow {
        /**
         * Load the default values, via getDefaults.
         *
-        *  @since 1.20
+        * @since 1.20
         *
         * @param boolean $override
         */
@@ -361,7 +353,8 @@ abstract class ORMRow {
                        is_null( $functionName ) ? __METHOD__ : $functionName
                );
 
-               return $success;
+               // DatabaseBase::update does not always return true for success as documented...
+               return $success !== false;
        }
 
        /**
@@ -389,18 +382,21 @@ abstract class ORMRow {
        protected function insert( $functionName = null, array $options = null ) {
                $dbw = wfGetDB( DB_MASTER );
 
-               $result = $dbw->insert(
+               $success = $dbw->insert(
                        $this->table->getName(),
                        $this->getWriteValues(),
                        is_null( $functionName ) ? __METHOD__ : $functionName,
                        is_null( $options ) ? array( 'IGNORE' ) : $options
                );
 
-               if ( $result ) {
+               // DatabaseBase::insert does not always return true for success as documented...
+               $success = $success !== false;
+
+               if ( $success ) {
                        $this->setField( 'id', $dbw->insertId() );
                }
 
-               return $result;
+               return $success;
        }
 
        /**
@@ -415,6 +411,9 @@ abstract class ORMRow {
 
                $success = $this->table->delete( array( 'id' => $this->getId() ) );
 
+               // DatabaseBase::delete does not always return true for success as documented...
+               $success = $success !== false;
+
                if ( $success ) {
                        $this->onRemoved();
                }
@@ -535,6 +534,7 @@ abstract class ORMRow {
 
        /**
         * Add an amount (can be negative) to the specified field (needs to be numeric).
+        * TODO: most off this stuff makes more sense in the table class
         *
         * @since 1.20
         *
@@ -622,14 +622,14 @@ abstract class ORMRow {
         *
         * @since 1.20
         *
-        * @param ORMRow $object
+        * @param IORMRow $object
         * @param boolean|array $excludeSummaryFields
         *  When set to true, summary field changes are ignored.
         *  Can also be an array of fields to ignore.
         *
         * @return boolean
         */
-       protected function fieldsChanged( ORMRow $object, $excludeSummaryFields = false ) {
+       protected function fieldsChanged( IORMRow $object, $excludeSummaryFields = false ) {
                $exclusionFields = array();
 
                if ( $excludeSummaryFields !== false ) {
@@ -648,11 +648,11 @@ abstract class ORMRow {
        }
 
        /**
-        * Returns the table this ORMRow is a row in.
+        * Returns the table this IORMRow is a row in.
         *
         * @since 1.20
         *
-        * @return ORMTable
+        * @return IORMTable
         */
        public function getTable() {
                return $this->table;