Skip to content

Commit 1e63b56

Browse files
Merge pull request #1 from Wikidata/fix22
Search entities in the correct namespace
2 parents cea6ef3 + 307b44b commit 1e63b56

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

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)