From 780cb003f70d5c2b36ba15f1e08191a396b9418b Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Fri, 21 Apr 2017 19:05:42 +0200 Subject: [PATCH] Search entities in all entity namespaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of assuming that all entities are in namespace 0 (which is only true in a Wikidata-like installation, but not in a default Wikibase installation, and even then only for items, not properties), use all entity namespaces from the local configuration. (Use array_values to make the keys numeric to make sure the database wrapper doesn’t try to interpret the string keys ('item', 'property').) Also, if we can’t find the entity, throw an exception instead of returning count 0: it’s better to fail the import than to duplicate statements. Fixes #22. --- src/PagePropsStatementCountLookup.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/PagePropsStatementCountLookup.php b/src/PagePropsStatementCountLookup.php index 3799f46..8bd36bc 100644 --- a/src/PagePropsStatementCountLookup.php +++ b/src/PagePropsStatementCountLookup.php @@ -14,13 +14,15 @@ public function __construct( LoadBalancer $loadBalancer ) { } public function getStatementCount( EntityId $entityId ) { + global $wgWBRepoSettings; + $db = $this->loadBalancer->getConnection( DB_MASTER ); $res = $db->selectRow( array( 'page_props', 'page' ), array( 'pp_value' ), array( - 'page_namespace' => 0, + 'page_namespace' => array_values( $wgWBRepoSettings['entityNamespaces'] ), 'page_title' => $entityId->getSerialization(), 'pp_propname' => 'wb-claims' ), @@ -32,7 +34,7 @@ public function getStatementCount( EntityId $entityId ) { $this->loadBalancer->closeConnection( $db ); if ( $res === false ) { - return 0; + throw new Exception( "Could not find entity in page_props!" ); } return (int)$res->pp_value;