Skip to content

Commit 780cb00

Browse files
Search entities in all entity namespaces
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.
1 parent d9705f1 commit 780cb00

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/PagePropsStatementCountLookup.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public function __construct( LoadBalancer $loadBalancer ) {
1414
}
1515

1616
public function getStatementCount( EntityId $entityId ) {
17+
global $wgWBRepoSettings;
18+
1719
$db = $this->loadBalancer->getConnection( DB_MASTER );
1820

1921
$res = $db->selectRow(
2022
array( 'page_props', 'page' ),
2123
array( 'pp_value' ),
2224
array(
23-
'page_namespace' => 0,
25+
'page_namespace' => array_values( $wgWBRepoSettings['entityNamespaces'] ),
2426
'page_title' => $entityId->getSerialization(),
2527
'pp_propname' => 'wb-claims'
2628
),
@@ -32,7 +34,7 @@ public function getStatementCount( EntityId $entityId ) {
3234
$this->loadBalancer->closeConnection( $db );
3335

3436
if ( $res === false ) {
35-
return 0;
37+
throw new Exception( "Could not find entity in page_props!" );
3638
}
3739

3840
return (int)$res->pp_value;

0 commit comments

Comments
 (0)