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

Change subject: Add ChangeLookup::loadByChangeIds and use in 
ChangeNotificationJob
......................................................................


Add ChangeLookup::loadByChangeIds and use in ChangeNotificationJob

Bug: T111056
Change-Id: I4a91d41cee3bf5675ffb8b12f81fbd2ee8dbdaa4
---
M client/includes/store/ClientStore.php
M client/includes/store/sql/DirectSqlStore.php
M client/tests/phpunit/MockClientStore.php
M client/tests/phpunit/includes/store/sql/DirectSqlStoreTest.php
M lib/includes/ChangeNotificationJob.php
M lib/includes/store/sql/ChangeLookup.php
M lib/tests/phpunit/store/Sql/ChangeLookupTest.php
7 files changed, 133 insertions(+), 44 deletions(-)

Approvals:
  Aude: Looks good to me, but someone else must approve
  Daniel Kinzler: Checked; Looks good to me, approved
  Jeroen De Dauw: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/client/includes/store/ClientStore.php 
b/client/includes/store/ClientStore.php
index 260f737..4fa6fba 100644
--- a/client/includes/store/ClientStore.php
+++ b/client/includes/store/ClientStore.php
@@ -10,6 +10,7 @@
 use Wikibase\DataModel\Services\Entity\EntityPrefetcher;
 use Wikibase\DataModel\Services\Lookup\EntityLookup;
 use Wikibase\DataModel\Services\Term\PropertyLabelResolver;
+use Wikibase\Lib\Store\ChangeLookup;
 use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Lib\Store\SiteLinkLookup;
 use Wikibase\Store\EntityIdLookup;
@@ -134,4 +135,11 @@
         */
        public function getUsageUpdater();
 
+       /**
+        * @since 0.5
+        *
+        * @return ChangeLookup
+        */
+       public function getChangeLookup();
+
 }
diff --git a/client/includes/store/sql/DirectSqlStore.php 
b/client/includes/store/sql/DirectSqlStore.php
index 5af536f..69e6cd8 100644
--- a/client/includes/store/sql/DirectSqlStore.php
+++ b/client/includes/store/sql/DirectSqlStore.php
@@ -22,6 +22,7 @@
 use Wikibase\DataModel\Services\Term\PropertyLabelResolver;
 use Wikibase\Lib\Store\CachingEntityRevisionLookup;
 use Wikibase\Lib\Store\CachingSiteLinkLookup;
+use Wikibase\Lib\Store\ChangeLookup;
 use Wikibase\Lib\Store\EntityContentDataCodec;
 use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\DataModel\Services\Lookup\RedirectResolvingEntityLookup;
@@ -156,6 +157,11 @@
        private $siteId;
 
        /**
+        * @var string[]
+        */
+       private $changeHandlerClasses;
+
+       /**
         * @param EntityContentDataCodec $contentCodec
         * @param EntityIdParser $entityIdParser
         * @param string|bool $repoWiki The symbolic database name of the repo 
wiki or false for the
@@ -181,6 +187,7 @@
                $this->useLegacyUsageIndex = $settings->getSetting( 
'useLegacyUsageIndex' );
                $this->useLegacyChangesSubscription = $settings->getSetting( 
'useLegacyChangesSubscription' );
                $this->siteId = $settings->getSetting( 'siteGlobalID' );
+               $this->changeHandlerClasses = $settings->getSetting( 
'changeHandlers' );
        }
 
        /**
@@ -476,4 +483,13 @@
                );
        }
 
+       /**
+        * @since 0.5
+        *
+        * @return ChangeLookup
+        */
+       public function getChangeLookup() {
+               return new ChangeLookup( $this->changeHandlerClasses, 
$this->repoWiki );
+       }
+
 }
diff --git a/client/tests/phpunit/MockClientStore.php 
b/client/tests/phpunit/MockClientStore.php
index 2b88494..620c520 100644
--- a/client/tests/phpunit/MockClientStore.php
+++ b/client/tests/phpunit/MockClientStore.php
@@ -214,4 +214,8 @@
                );
        }
 
+       public function getChangeLookup() {
+               // FIXME: Incomplete
+       }
+
 }
diff --git a/client/tests/phpunit/includes/store/sql/DirectSqlStoreTest.php 
b/client/tests/phpunit/includes/store/sql/DirectSqlStoreTest.php
index 3ab55ac..2207e35 100644
--- a/client/tests/phpunit/includes/store/sql/DirectSqlStoreTest.php
+++ b/client/tests/phpunit/includes/store/sql/DirectSqlStoreTest.php
@@ -55,6 +55,7 @@
                        array( 'getSubscriptionManager', 
'Wikibase\Client\Usage\SubscriptionManager' ),
                        array( 'getEntityIdLookup', 
'Wikibase\Store\EntityIdLookup' ),
                        array( 'getEntityPrefetcher', 
'Wikibase\DataModel\Services\Entity\EntityPrefetcher' ),
+                       array( 'getChangeLookup', 
'Wikibase\Lib\Store\ChangeLookup' ),
                );
        }
 
diff --git a/lib/includes/ChangeNotificationJob.php 
b/lib/includes/ChangeNotificationJob.php
index 0397d36..4f73d68 100644
--- a/lib/includes/ChangeNotificationJob.php
+++ b/lib/includes/ChangeNotificationJob.php
@@ -97,9 +97,8 @@
 
                        // load actual change records from the changes table
                        // TODO: allow mock store for testing!
-                       // FIXME: This only works when executed on the client! 
check WBC_VERSION first!
-                       $table = 
WikibaseClient::getDefaultInstance()->getStore()->newChangesTable();
-                       $this->changes = $table->selectObjects( null, array( 
'id' => $ids ), array(), __METHOD__ );
+                       $changeLookup = 
WikibaseClient::getDefaultInstance()->getStore()->getChangeLookup();
+                       $this->changes = $changeLookup->loadByChangeIds( $ids );
 
                        wfDebugLog( __CLASS__, __FUNCTION__ . ": loaded " . 
count( $this->changes )
                                . " of " . count( $ids ) . " changes." );
diff --git a/lib/includes/store/sql/ChangeLookup.php 
b/lib/includes/store/sql/ChangeLookup.php
index 8c7aa0d..88ea755 100644
--- a/lib/includes/store/sql/ChangeLookup.php
+++ b/lib/includes/store/sql/ChangeLookup.php
@@ -56,6 +56,39 @@
         * @return Change[]
         */
        public function loadChunk( $start, $size ) {
+               Assert::parameterType( 'integer', $start, '$start' );
+               Assert::parameterType( 'integer', $size, '$size' );
+
+               return $this->loadChanges(
+                       array( 'change_id >= ' . (int)$start ),
+                       array(
+                               'ORDER BY' => 'change_id ASC',
+                               'LIMIT' => $size
+                       ),
+                       __METHOD__
+               );
+       }
+
+       /**
+        * @param int $ids
+        *
+        * @return Change[]
+        */
+       public function loadByChangeIds( $ids ) {
+               Assert::parameterElementType( 'integer', $ids, '$ids' );
+
+               return $this->loadChanges(
+                       array( 'change_id' => $ids ),
+                       array(),
+                       __METHOD__
+               );
+       }
+
+       /**
+        * @param array $where
+        * @return Change[]
+        */
+       private function loadChanges( array $where, array $options, $method ) {
                $dbr = $this->getConnection( DB_SLAVE );
 
                $rows = $dbr->select(
@@ -64,14 +97,9 @@
                                'change_id', 'change_type', 'change_time', 
'change_object_id',
                                'change_revision_id', 'change_user_id', 
'change_info'
                        ),
-                       array(
-                               'change_id >= ' . (int)$start,
-                       ),
-                       __METHOD__,
-                       array(
-                               'LIMIT' => $size,
-                               'ORDER BY' => 'change_id ASC'
-                       )
+                       $where,
+                       $method,
+                       $options
                );
 
                return $this->changesFromRows( $rows );
@@ -82,7 +110,7 @@
                foreach ( $rows as $row ) {
                        $class = $this->getClassForType( $row->change_type );
                        $data = array(
-                               'id' => $row->change_id,
+                               'id' => (int)$row->change_id,
                                'type' => $row->change_type,
                                'time' => $row->change_time,
                                'info' => $row->change_info,
diff --git a/lib/tests/phpunit/store/Sql/ChangeLookupTest.php 
b/lib/tests/phpunit/store/Sql/ChangeLookupTest.php
index 4428ed1..c6b954e 100644
--- a/lib/tests/phpunit/store/Sql/ChangeLookupTest.php
+++ b/lib/tests/phpunit/store/Sql/ChangeLookupTest.php
@@ -31,37 +31,7 @@
        }
 
        public function loadChunkProvider() {
-               $changeOne = array(
-                       'type' => 'wikibase-item~remove',
-                       'time' => '20121026200049',
-                       'object_id' => 'q42',
-                       'revision_id' => '0',
-                       'user_id' => '0',
-                       'info' => 
'{"diff":{"type":"diff","isassoc":null,"operations":[]}}',
-               );
-
-               $changeTwo = array(
-                       'type' => 'wikibase-item~remove',
-                       'time' => '20151008161232',
-                       'object_id' => 'q4662',
-                       'revision_id' => '0',
-                       'user_id' => '0',
-                       'info' => 
'{"diff":{"type":"diff","isassoc":null,"operations":[]}}',
-               );
-
-               $changeThree = array(
-                       'type' => 'wikibase-item~remove',
-                       'time' => '20141008161232',
-                       'object_id' => 'q123',
-                       'revision_id' => '343',
-                       'user_id' => '34',
-                       'info' => 
'{"metadata":{"user_text":"BlackMagicIsEvil","bot":0,"page_id":2354,"rev_id":343,'
 .
-                               '"parent_id":897,"comment":"Fake data!"}}',
-               );
-
-               $changeOne = new EntityChange( null, $changeOne, false );
-               $changeTwo = new EntityChange( null, $changeTwo, false );
-               $changeThree = new EntityChange( null, $changeThree, false );
+               list( $changeOne, $changeTwo, $changeThree ) = 
$this->getEntityChanges();
 
                return array(
                        'Get one change' => array(
@@ -106,6 +76,33 @@
 
                $changes = $lookup->loadChunk( $start, $size );
 
+               $this->assertChangesEqual( $expected, $changes, $start );
+       }
+
+       /**
+        * @depends testLoadChunk
+        */
+       public function testLoadByChangeIds() {
+               $start = $this->offsetStart( 3 );
+
+               $lookup = new ChangeLookup(
+                       array( 'wikibase-item~remove' => 
'Wikibase\EntityChange' ),
+                       wfWikiID()
+               );
+
+               $changes = $lookup->loadByChangeIds( array( $start, $start + 1, 
$start + 4 ) );
+               list( $changeOne, $changeTwo, $changeThree ) = 
$this->getEntityChanges();
+
+               $this->assertChangesEqual(
+                       array(
+                               $changeOne, $changeTwo, $changeThree
+                       ),
+                       $changes,
+                       $start
+               );
+       }
+
+       private function assertChangesEqual( array $expected, array $changes, 
$start ) {
                $this->assertCount( count( $expected ), $changes );
 
                $i = 0;
@@ -113,7 +110,7 @@
                        $expectedFields = $expected[$i]->getFields();
                        $actualFields = $change->getFields();
 
-                       $this->assertEquals( $start + $i, $actualFields['id'] );
+                       $this->assertGreaterThanOrEqual( $start, 
$actualFields['id'] );
                        unset( $expectedFields['id'] );
                        unset( $actualFields['id'] );
 
@@ -145,4 +142,40 @@
                return $start;
        }
 
+       private function getEntityChanges() {
+               $changeOne = array(
+                       'type' => 'wikibase-item~remove',
+                       'time' => '20121026200049',
+                       'object_id' => 'q42',
+                       'revision_id' => '0',
+                       'user_id' => '0',
+                       'info' => 
'{"diff":{"type":"diff","isassoc":null,"operations":[]}}',
+               );
+
+               $changeTwo = array(
+                       'type' => 'wikibase-item~remove',
+                       'time' => '20151008161232',
+                       'object_id' => 'q4662',
+                       'revision_id' => '0',
+                       'user_id' => '0',
+                       'info' => 
'{"diff":{"type":"diff","isassoc":null,"operations":[]}}',
+               );
+
+               $changeThree = array(
+                       'type' => 'wikibase-item~remove',
+                       'time' => '20141008161232',
+                       'object_id' => 'q123',
+                       'revision_id' => '343',
+                       'user_id' => '34',
+                       'info' => 
'{"metadata":{"user_text":"BlackMagicIsEvil","bot":0,"page_id":2354,"rev_id":343,'
 .
+                               '"parent_id":897,"comment":"Fake data!"}}',
+               );
+
+               $changeOne = new EntityChange( null, $changeOne, false );
+               $changeTwo = new EntityChange( null, $changeTwo, false );
+               $changeThree = new EntityChange( null, $changeThree, false );
+
+               return array( $changeOne, $changeTwo, $changeThree );
+       }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4a91d41cee3bf5675ffb8b12f81fbd2ee8dbdaa4
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: JanZerebecki <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to