Skip to content

Commit

Permalink
Search entities in all entity namespaces
Browse files Browse the repository at this point in the history
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 filbertkm#22.
  • Loading branch information
lucaswerkmeister committed Apr 24, 2017
1 parent d9705f1 commit cbf97a6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/PagePropsStatementCountLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use LoadBalancer;
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\Repo\WikibaseRepo;

class PagePropsStatementCountLookup implements StatementsCountLookup {

Expand All @@ -14,13 +15,15 @@ public function __construct( LoadBalancer $loadBalancer ) {
}

public function getStatementCount( EntityId $entityId ) {
$wikibaseRepo = WikibaseRepo::getDefaultInstance();

$db = $this->loadBalancer->getConnection( DB_MASTER );

$res = $db->selectRow(
array( 'page_props', 'page' ),
array( 'pp_value' ),
array(
'page_namespace' => 0,
'page_namespace' => array_values( $wikibaseRepo->getEntityNamespaces() ),
'page_title' => $entityId->getSerialization(),
'pp_propname' => 'wb-claims'
),
Expand All @@ -32,7 +35,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;
Expand Down

0 comments on commit cbf97a6

Please sign in to comment.