jenkins-bot has submitted this change and it was merged.

Change subject: Make ChangeRow not inherit from ORMRow
......................................................................


Make ChangeRow not inherit from ORMRow

This change removes the last bindings to MediaWiki's
ORM.

Bug: T110343
Change-Id: I579b80bea5f304b7785de4061cbfd5236d9e2a3b
---
M lib/includes/changes/ChangeRow.php
M lib/includes/changes/EntityChange.php
M lib/tests/phpunit/changes/DiffChangeTest.php
M lib/tests/phpunit/changes/EntityChangeTest.php
M lib/tests/phpunit/changes/ItemChangeTest.php
5 files changed, 67 insertions(+), 17 deletions(-)

Approvals:
  Jeroen De Dauw: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/includes/changes/ChangeRow.php 
b/lib/includes/changes/ChangeRow.php
index f1d70ff..f59c8fd 100644
--- a/lib/includes/changes/ChangeRow.php
+++ b/lib/includes/changes/ChangeRow.php
@@ -2,9 +2,7 @@
 
 namespace Wikibase;
 
-use IORMTable;
 use MWException;
-use ORMRow;
 use User;
 
 /**
@@ -16,7 +14,7 @@
  * @author Jeroen De Dauw < jeroended...@gmail.com >
  * @author Daniel Kinzler
  */
-class ChangeRow extends ORMRow implements Change {
+class ChangeRow implements Change {
 
        /**
         * Field for caching the linked user.
@@ -25,6 +23,15 @@
         * @var User|bool
         */
        protected $user = false;
+
+       /**
+        * The fields of the object.
+        * field name (w/o prefix) => value
+        *
+        * @since 1.20
+        * @var array
+        */
+       protected $fields = array( 'id' => null );
 
        /**
         * @see Change::getUser
@@ -75,11 +82,11 @@
        }
 
        /**
-        * @param IORMTable|null $table
+        * @param null $table Ignored
         * @param array|null $fields
         */
-       public function __construct( IORMTable $table = null, $fields = null ) {
-               parent::__construct( $table, $fields, false );
+       public function __construct( $table = null, $fields = null ) {
+               $this->setFields( is_array( $fields ) ? $fields : array() );
 
                $this->postConstruct();
        }
@@ -116,8 +123,6 @@
        }
 
        /**
-        * @see ORMRow::getField
-        *
         * Overwritten to unserialize the info field on the fly.
         *
         * @since 0.4
@@ -130,7 +135,13 @@
         * @return mixed
         */
        public function getField( $name, $default = null ) {
-               $value = parent::getField( $name, $default );
+               if ( $this->hasField( $name ) ) {
+                       $value = $this->fields[$name];
+               } elseif ( !is_null( $default ) ) {
+                       $value = $default;
+               } else {
+                       throw new MWException( 'Attempted to get not-set field 
' . $name );
+               }
 
                if ( $name === 'info' && is_string( $value ) ) {
                        $value = $this->unserializeInfo( $value );
@@ -140,8 +151,6 @@
        }
 
        /**
-        * @see ORMRow::getFields
-        *
         * Overwritten to unserialize the info field on the fly.
         *
         * @since 0.4
@@ -149,7 +158,7 @@
         * @return array
         */
        public function getFields() {
-               $fields = parent::getFields();
+               $fields = $this->fields;
 
                if ( isset( $fields['info'] ) && is_string( $fields['info'] ) ) 
{
                        $fields['info'] = $this->unserializeInfo( 
$fields['info'] );
@@ -240,4 +249,50 @@
                return $info;
        }
 
+       /**
+        * Sets the value of a field.
+        * Strings can be provided for other types,
+        * so this method can be called from unserialization handlers.
+        *
+        * @param string $name
+        * @param mixed $value
+        */
+       public function setField( $name, $value ) {
+               $this->fields[$name] = $value;
+       }
+
+       /**
+        * Sets multiple fields.
+        *
+        * @param array $fields The fields to set
+        * @param bool $override Override already set fields with the provided 
values?
+        */
+       public function setFields( array $fields, $override = true ) {
+               foreach ( $fields as $name => $value ) {
+                       if ( $override || !$this->hasField( $name ) ) {
+                               $this->setField( $name, $value );
+                       }
+               }
+       }
+
+       /**
+        * Returns the objects database id.
+        *
+        * @return int|null
+        */
+       public function getId() {
+               return $this->getField( 'id' );
+       }
+
+       /**
+        * Gets if a certain field is set.
+        *
+        * @param string $name
+        *
+        * @return bool
+        */
+       public function hasField( $name ) {
+               return array_key_exists( $name, $this->fields );
+       }
+
 }
diff --git a/lib/includes/changes/EntityChange.php 
b/lib/includes/changes/EntityChange.php
index abb93df..b897338 100644
--- a/lib/includes/changes/EntityChange.php
+++ b/lib/includes/changes/EntityChange.php
@@ -36,8 +36,6 @@
        private $entityId = null;
 
        /**
-        * @see ORMRow::setField
-        *
         * @todo FIXME use uppecase ID, like everywhere else!
         *
         * @param string $name
diff --git a/lib/tests/phpunit/changes/DiffChangeTest.php 
b/lib/tests/phpunit/changes/DiffChangeTest.php
index 2e82807..758c50c 100644
--- a/lib/tests/phpunit/changes/DiffChangeTest.php
+++ b/lib/tests/phpunit/changes/DiffChangeTest.php
@@ -19,7 +19,6 @@
 class DiffChangeTest extends ChangeRowTest {
 
        /**
-        * @see ORMRowTest::getRowClass
         * @since 0.4
         * @return string
         */
diff --git a/lib/tests/phpunit/changes/EntityChangeTest.php 
b/lib/tests/phpunit/changes/EntityChangeTest.php
index eec2485..d3322ee 100644
--- a/lib/tests/phpunit/changes/EntityChangeTest.php
+++ b/lib/tests/phpunit/changes/EntityChangeTest.php
@@ -29,7 +29,6 @@
 class EntityChangeTest extends ChangeRowTest {
 
        /**
-        * @see ORMRowTest::getRowClass
         * @since 0.4
         * @return string
         */
diff --git a/lib/tests/phpunit/changes/ItemChangeTest.php 
b/lib/tests/phpunit/changes/ItemChangeTest.php
index 4767f3b..4fd7b31 100644
--- a/lib/tests/phpunit/changes/ItemChangeTest.php
+++ b/lib/tests/phpunit/changes/ItemChangeTest.php
@@ -27,7 +27,6 @@
 class ItemChangeTest extends EntityChangeTest {
 
        /**
-        * @see ORMRowTest::getRowClass
         * @since 0.4
         * @return string
         */

-- 
To view, visit https://gerrit.wikimedia.org/r/245949
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I579b80bea5f304b7785de4061cbfd5236d9e2a3b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <h...@online.de>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to