Skip to content

Commit 307b44b

Browse files
Search entities in the correct namespace
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), take the actual namespace of the requested entity from an injected EntityNamespaceLookup. 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.
1 parent 3c79baa commit 307b44b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/EntityImporterFactory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function newEntityImporter() {
7070
$this->getApiEntityLookup(),
7171
$this->entityStore,
7272
$this->getImportedEntityMappingStore(),
73-
new PagePropsStatementCountLookup( $this->loadBalancer ),
73+
new PagePropsStatementCountLookup( $this->loadBalancer, $this->getEntityNamespaceLookup() ),
7474
$this->logger
7575
);
7676
}
@@ -127,6 +127,12 @@ private function newSerializerFactory() {
127127
new DataValueSerializer()
128128
);
129129
}
130+
131+
private function getEntityNamespaceLookup() {
132+
$wikibaseRepo = WikibaseRepo::getDefaultInstance();
133+
134+
return $wikibaseRepo->getEntityNamespaceLookup();
135+
}
130136
}
131137

132138
$maintClass = "Wikibase\Import\Maintenance\ImportEntities";

src/PagePropsStatementCountLookup.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22

33
namespace Wikibase\Import;
44

5+
use Exception;
56
use LoadBalancer;
67
use Wikibase\DataModel\Entity\EntityId;
8+
use Wikibase\Lib\Store\EntityNamespaceLookup;
9+
use Wikibase\Repo\WikibaseRepo;
710

811
class PagePropsStatementCountLookup implements StatementsCountLookup {
912

1013
private $loadBalancer;
1114

12-
public function __construct( LoadBalancer $loadBalancer ) {
15+
private $lookup;
16+
17+
public function __construct( LoadBalancer $loadBalancer, EntityNamespaceLookup $lookup ) {
1318
$this->loadBalancer = $loadBalancer;
19+
$this->lookup = $lookup;
1420
}
1521

1622
public function getStatementCount( EntityId $entityId ) {
@@ -20,7 +26,7 @@ public function getStatementCount( EntityId $entityId ) {
2026
array( 'page_props', 'page' ),
2127
array( 'pp_value' ),
2228
array(
23-
'page_namespace' => 0,
29+
'page_namespace' => $this->lookup->getEntityNamespace( $entityId->getEntityType() ),
2430
'page_title' => $entityId->getSerialization(),
2531
'pp_propname' => 'wb-claims'
2632
),
@@ -32,7 +38,7 @@ public function getStatementCount( EntityId $entityId ) {
3238
$this->loadBalancer->closeConnection( $db );
3339

3440
if ( $res === false ) {
35-
return 0;
41+
throw new Exception( 'Could not find entity ' . $entityId->getSerialization() . ' in page_props!' );
3642
}
3743

3844
return (int)$res->pp_value;

0 commit comments

Comments
 (0)