diff --git a/src/EntityImporterFactory.php b/src/EntityImporterFactory.php index 9394128..3564133 100644 --- a/src/EntityImporterFactory.php +++ b/src/EntityImporterFactory.php @@ -70,7 +70,7 @@ public function newEntityImporter() { $this->getApiEntityLookup(), $this->entityStore, $this->getImportedEntityMappingStore(), - new PagePropsStatementCountLookup( $this->loadBalancer ), + new PagePropsStatementCountLookup( $this->loadBalancer, $this->getEntityNamespaceLookup() ), $this->logger ); } @@ -127,6 +127,12 @@ private function newSerializerFactory() { new DataValueSerializer() ); } + + private function getEntityNamespaceLookup() { + $wikibaseRepo = WikibaseRepo::getDefaultInstance(); + + return $wikibaseRepo->getEntityNamespaceLookup(); + } } $maintClass = "Wikibase\Import\Maintenance\ImportEntities"; diff --git a/src/PagePropsStatementCountLookup.php b/src/PagePropsStatementCountLookup.php index 3799f46..cc6b65b 100644 --- a/src/PagePropsStatementCountLookup.php +++ b/src/PagePropsStatementCountLookup.php @@ -2,15 +2,21 @@ namespace Wikibase\Import; +use Exception; use LoadBalancer; use Wikibase\DataModel\Entity\EntityId; +use Wikibase\Lib\Store\EntityNamespaceLookup; +use Wikibase\Repo\WikibaseRepo; class PagePropsStatementCountLookup implements StatementsCountLookup { private $loadBalancer; - public function __construct( LoadBalancer $loadBalancer ) { + private $lookup; + + public function __construct( LoadBalancer $loadBalancer, EntityNamespaceLookup $lookup ) { $this->loadBalancer = $loadBalancer; + $this->lookup = $lookup; } public function getStatementCount( EntityId $entityId ) { @@ -20,7 +26,7 @@ public function getStatementCount( EntityId $entityId ) { array( 'page_props', 'page' ), array( 'pp_value' ), array( - 'page_namespace' => 0, + 'page_namespace' => $this->lookup->getEntityNamespace( $entityId->getEntityType() ), 'page_title' => $entityId->getSerialization(), 'pp_propname' => 'wb-claims' ), @@ -32,7 +38,7 @@ public function getStatementCount( EntityId $entityId ) { $this->loadBalancer->closeConnection( $db ); if ( $res === false ) { - return 0; + throw new Exception( 'Could not find entity ' . $entityId->getSerialization() . ' in page_props!' ); } return (int)$res->pp_value;