Hoo man has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/314182

Change subject: Move EntitiesWithoutTermFinder::getEntitiesWithoutTerm
......................................................................

Move EntitiesWithoutTermFinder::getEntitiesWithoutTerm

from EntityPerPageTable to the new SqlEntitiesWithoutTermFinder.

This just copies code around. Manually tested the affected special
pages (Special:EntitiesWithoutDescription/ Special:EntitiesWithoutLabel).

Bug: T140891
Change-Id: I0c28fb7457ea955310a16791badc68fc6ff75ca4
---
M repo/includes/Store/Sql/EntityPerPageTable.php
A repo/includes/Store/Sql/SqlEntitiesWithoutTermFinder.php
M repo/includes/Store/Sql/SqlStore.php
3 files changed, 101 insertions(+), 54 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/82/314182/1

diff --git a/repo/includes/Store/Sql/EntityPerPageTable.php 
b/repo/includes/Store/Sql/EntityPerPageTable.php
index 5110694..fc07cc6 100644
--- a/repo/includes/Store/Sql/EntityPerPageTable.php
+++ b/repo/includes/Store/Sql/EntityPerPageTable.php
@@ -9,7 +9,6 @@
 use Wikibase\DataModel\Entity\Int32EntityId;
 use Wikibase\Lib\EntityIdComposer;
 use Wikibase\Repo\Store\EntityPerPage;
-use Wikibase\Repo\Store\EntitiesWithoutTermFinder;
 
 /**
  * Represents a lookup database table that makes the link between entities and 
pages.
@@ -21,7 +20,7 @@
  * @author Thomas Pellissier Tanon
  * @author Daniel Kinzler
  */
-class EntityPerPageTable implements EntityPerPage, EntitiesWithoutTermFinder {
+class EntityPerPageTable implements EntityPerPage {
 
        /**
         * @var EntityIdParser
@@ -232,57 +231,6 @@
         */
        public function clear() {
                return $this->loadBalancer->getConnection( DB_MASTER )->delete( 
'wb_entity_per_page', '*', __METHOD__ );
-       }
-
-       /**
-        * @see EntityPerPage::getEntitiesWithoutTerm
-        *
-        * @since 0.2
-        *
-        * @param string $termType Can be any member of the 
TermIndexEntry::TYPE_ enum
-        * @param string|null $language Restrict the search for one language. 
By default the search is done for all languages.
-        * @param string|null $entityType Can be "item", "property" or "query". 
By default the search is done for all entities.
-        * @param integer $limit Limit of the query.
-        * @param integer $offset Offset of the query.
-        *
-        * @return EntityId[]
-        */
-       public function getEntitiesWithoutTerm( $termType, $language = null, 
$entityType = null, $limit = 50, $offset = 0 ) {
-               $dbr = wfGetDB( DB_SLAVE );
-               $conditions = array(
-                       'term_entity_type IS NULL'
-               );
-
-               $joinConditions = 'term_entity_id = epp_entity_id' .
-                       ' AND term_entity_type = epp_entity_type' .
-                       ' AND term_type = ' . $dbr->addQuotes( $termType ) .
-                       ' AND epp_redirect_target IS NULL';
-
-               if ( $language !== null ) {
-                       $joinConditions .= ' AND term_language = ' . 
$dbr->addQuotes( $language );
-               }
-
-               if ( $entityType !== null ) {
-                       $conditions[] = 'epp_entity_type = ' . $dbr->addQuotes( 
$entityType );
-               }
-
-               $rows = $dbr->select(
-                       array( 'wb_entity_per_page', 'wb_terms' ),
-                       array(
-                               'entity_id' => 'epp_entity_id',
-                               'entity_type' => 'epp_entity_type',
-                       ),
-                       $conditions,
-                       __METHOD__,
-                       array(
-                               'OFFSET' => $offset,
-                               'LIMIT' => $limit,
-                               'ORDER BY' => 'epp_page_id DESC'
-                       ),
-                       array( 'wb_terms' => array( 'LEFT JOIN', 
$joinConditions ) )
-               );
-
-               return $this->getEntityIdsFromRows( $rows );
        }
 
        protected function getEntityIdsFromRows( $rows ) {
diff --git a/repo/includes/Store/Sql/SqlEntitiesWithoutTermFinder.php 
b/repo/includes/Store/Sql/SqlEntitiesWithoutTermFinder.php
new file mode 100644
index 0000000..8f0487d
--- /dev/null
+++ b/repo/includes/Store/Sql/SqlEntitiesWithoutTermFinder.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace Wikibase\Repo\Store\Sql;
+
+use InvalidArgumentException;
+use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\Lib\EntityIdComposer;
+use Wikibase\Repo\Store\EntitiesWithoutTermFinder;
+
+/**
+ * Service for getting entities without terms.
+ *
+ * @since 0.5
+ *
+ * @license GPL-2.0+
+ * @author Thomas Pellissier Tanon
+ * @author Daniel Kinzler
+ */
+class SqlEntitiesWithoutTermFinder implements EntitiesWithoutTermFinder {
+
+       /**
+        * @var EntityIdComposer
+        */
+       private $entityIdComposer;
+
+       /**
+        * @param EntityIdComposer $entityIdComposer
+        */
+       public function __construct( EntityIdComposer $entityIdComposer ) {
+               $this->entityIdComposer = $entityIdComposer;
+       }
+
+       /**
+        * @see EntitiesWithoutTermFinder::getEntitiesWithoutTerm
+        *
+        * @since 0.2
+        *
+        * @param string $termType Can be any member of the 
TermIndexEntry::TYPE_ enum
+        * @param string|null $language Restrict the search for one language. 
By default the search is done for all languages.
+        * @param string|null $entityType Can be "item", "property" or "query". 
By default the search is done for all entities.
+        * @param integer $limit Limit of the query.
+        * @param integer $offset Offset of the query.
+        *
+        * @return EntityId[]
+        */
+       public function getEntitiesWithoutTerm( $termType, $language = null, 
$entityType = null, $limit = 50, $offset = 0 ) {
+               $dbr = wfGetDB( DB_REPLICA );
+               $conditions = array(
+                       'term_entity_type IS NULL'
+               );
+
+               $joinConditions = 'term_entity_id = epp_entity_id' .
+                       ' AND term_entity_type = epp_entity_type' .
+                       ' AND term_type = ' . $dbr->addQuotes( $termType ) .
+                       ' AND epp_redirect_target IS NULL';
+
+               if ( $language !== null ) {
+                       $joinConditions .= ' AND term_language = ' . 
$dbr->addQuotes( $language );
+               }
+
+               if ( $entityType !== null ) {
+                       $conditions[] = 'epp_entity_type = ' . $dbr->addQuotes( 
$entityType );
+               }
+
+               $rows = $dbr->select(
+                       array( 'wb_entity_per_page', 'wb_terms' ),
+                       array(
+                               'entity_id' => 'epp_entity_id',
+                               'entity_type' => 'epp_entity_type',
+                       ),
+                       $conditions,
+                       __METHOD__,
+                       array(
+                               'OFFSET' => $offset,
+                               'LIMIT' => $limit,
+                               'ORDER BY' => 'epp_page_id DESC'
+                       ),
+                       array( 'wb_terms' => array( 'LEFT JOIN', 
$joinConditions ) )
+               );
+
+               return $this->getEntityIdsFromRows( $rows );
+       }
+
+       private function getEntityIdsFromRows( $rows ) {
+               $entities = array();
+
+               foreach ( $rows as $row ) {
+                       try {
+                               $entities[] = 
$this->entityIdComposer->composeEntityId( $row->entity_type, $row->entity_id );
+                       } catch ( InvalidArgumentException $ex ) {
+                               wfLogWarning( 'Unsupported entity type "' . 
$row->entity_type . '"' );
+                       }
+               }
+
+               return $entities;
+       }
+
+}
diff --git a/repo/includes/Store/Sql/SqlStore.php 
b/repo/includes/Store/Sql/SqlStore.php
index 8910602..46a1edb 100644
--- a/repo/includes/Store/Sql/SqlStore.php
+++ b/repo/includes/Store/Sql/SqlStore.php
@@ -34,6 +34,7 @@
 use Wikibase\Repo\Store\EntitiesWithoutTermFinder;
 use Wikibase\Repo\Store\SiteLinkConflictLookup;
 use Wikibase\Repo\Store\Sql\EntityPerPageTable;
+use Wikibase\Repo\Store\Sql\SqlEntitiesWithoutTermFinder;
 use Wikibase\Repo\Store\Sql\SqlChangeStore;
 use Wikibase\Repo\Store\Sql\SqlItemsWithoutSitelinksFinder;
 use Wikibase\Repo\Store\Sql\SqlSiteLinkConflictLookup;
@@ -307,7 +308,7 @@
         * @return EntitiesWithoutTermFinder
         */
        public function newEntitiesWithoutTermFinder() {
-               return $this->newEntityPerPage();
+               return new SqlEntitiesWithoutTermFinder( 
$this->entityIdComposer );
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0c28fb7457ea955310a16791badc68fc6ff75ca4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <h...@online.de>

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

Reply via email to