WMDE-leszek has uploaded a new change for review.
https://gerrit.wikimedia.org/r/322919
Change subject: Use the EntityId instance instead of plain number as entity id
in TermIndexEntry
......................................................................
Use the EntityId instance instead of plain number as entity id in TermIndexEntry
TermSqlIndex uses EntityIdComposer to create the EntityId instance
using the entity type and numeric id read from wb_terms DB table.
EntityId composing logic is removed from TermIndexEntry.
Bug: T151212
Change-Id: I2819090b4759fa1281fcc570b9feb42122ae2442
---
M client/includes/Store/Sql/DirectSqlStore.php
M client/includes/WikibaseClient.php
M client/tests/phpunit/includes/Api/PageTermsTest.php
M client/tests/phpunit/includes/Store/Sql/DirectSqlStoreTest.php
M lib/includes/Store/Sql/TermSqlIndex.php
M lib/includes/TermIndexEntry.php
M lib/tests/phpunit/Interactors/TermIndexSearchInteractorTest.php
M lib/tests/phpunit/NoBadDependencyUsageTest.php
M lib/tests/phpunit/Store/BufferingTermLookupTest.php
M lib/tests/phpunit/Store/EntityTermLookupTest.php
M lib/tests/phpunit/Store/LanguageFallbackLabelDescriptionLookupTest.php
M lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php
M lib/tests/phpunit/Store/TermPropertyLabelResolverTest.php
M lib/tests/phpunit/TermIndexEntryTest.php
M repo/includes/Store/Sql/SqlStore.php
M repo/tests/phpunit/includes/LabelDescriptionDuplicateDetectorTest.php
16 files changed, 135 insertions(+), 125 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/19/322919/2
diff --git a/client/includes/Store/Sql/DirectSqlStore.php
b/client/includes/Store/Sql/DirectSqlStore.php
index 2cfde46..922e232 100644
--- a/client/includes/Store/Sql/DirectSqlStore.php
+++ b/client/includes/Store/Sql/DirectSqlStore.php
@@ -19,6 +19,7 @@
use Wikibase\DataModel\Services\Lookup\RedirectResolvingEntityLookup;
use Wikibase\DataModel\Services\Term\PropertyLabelResolver;
use Wikibase\Lib\Changes\EntityChangeFactory;
+use Wikibase\Lib\EntityIdComposer;
use Wikibase\Lib\Store\CachingEntityRevisionLookup;
use Wikibase\Lib\Store\CachingSiteLinkLookup;
use Wikibase\Lib\Store\EntityChangeLookup;
@@ -59,6 +60,11 @@
* @var EntityIdParser
*/
private $entityIdParser;
+
+ /**
+ * @var EntityIdComposer
+ */
+ private $entityIdComposer;
/**
* @var string|bool The symbolic database name of the repo wiki or
false for the local wiki.
@@ -159,6 +165,7 @@
* @param EntityChangeFactory $entityChangeFactory
* @param EntityContentDataCodec $contentCodec
* @param EntityIdParser $entityIdParser
+ * @param EntityIdComposer $entityIdComposer
* @param EntityNamespaceLookup $entityNamespaceLookup
* @param string|bool $repoWiki The symbolic database name of the repo
wiki or false for the
* local wiki.
@@ -168,6 +175,7 @@
EntityChangeFactory $entityChangeFactory,
EntityContentDataCodec $contentCodec,
EntityIdParser $entityIdParser,
+ EntityIdComposer $entityIdComposer,
EntityNamespaceLookup $entityNamespaceLookup,
$repoWiki = false,
$languageCode
@@ -175,6 +183,7 @@
$this->contentCodec = $contentCodec;
$this->entityChangeFactory = $entityChangeFactory;
$this->entityIdParser = $entityIdParser;
+ $this->entityIdComposer = $entityIdComposer;
$this->entityNamespaceLookup = $entityNamespaceLookup;
$this->repoWiki = $repoWiki;
$this->languageCode = $languageCode;
@@ -352,7 +361,7 @@
if ( $this->termIndex === null ) {
// TODO: Get StringNormalizer from WikibaseClient?
// Can't really pass this via the constructor...
- $this->termIndex = new TermSqlIndex( new
StringNormalizer(), $this->repoWiki );
+ $this->termIndex = new TermSqlIndex( new
StringNormalizer(), $this->entityIdComposer, $this->repoWiki );
}
return $this->termIndex;
diff --git a/client/includes/WikibaseClient.php
b/client/includes/WikibaseClient.php
index cd95980..9f0a255 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -511,6 +511,7 @@
$this->getEntityChangeFactory(),
$this->getEntityContentDataCodec(),
$this->getEntityIdParser(),
+ $this->getEntityIdComposer(),
$this->getEntityNamespaceLookup(),
$repoDatabase,
$this->contentLanguage->getCode()
diff --git a/client/tests/phpunit/includes/Api/PageTermsTest.php
b/client/tests/phpunit/includes/Api/PageTermsTest.php
index ecddfce..e61ae2a 100644
--- a/client/tests/phpunit/includes/Api/PageTermsTest.php
+++ b/client/tests/phpunit/includes/Api/PageTermsTest.php
@@ -184,7 +184,7 @@
'termLanguage' => $lang,
'termText' => $text,
'entityType' =>
$entityId->getEntityType(),
- 'entityId' => $entityId->getNumericId()
+ 'entityId' => $entityId
) );
}
}
diff --git a/client/tests/phpunit/includes/Store/Sql/DirectSqlStoreTest.php
b/client/tests/phpunit/includes/Store/Sql/DirectSqlStoreTest.php
index c13f1d6..a9d5f5c 100644
--- a/client/tests/phpunit/includes/Store/Sql/DirectSqlStoreTest.php
+++ b/client/tests/phpunit/includes/Store/Sql/DirectSqlStoreTest.php
@@ -13,6 +13,7 @@
use Wikibase\DataModel\Services\Term\PropertyLabelResolver;
use Wikibase\DirectSqlStore;
use Wikibase\Lib\Changes\EntityChangeFactory;
+use Wikibase\Lib\EntityIdComposer;
use Wikibase\Lib\Store\EntityChangeLookup;
use Wikibase\Lib\Store\EntityNamespaceLookup;
use Wikibase\Lib\Store\SiteLinkLookup;
@@ -40,6 +41,7 @@
->getMock();
$idParser = new BasicEntityIdParser();
+ $idComposer = new EntityIdComposer( [] );
$contentCodec =
WikibaseClient::getDefaultInstance()->getEntityContentDataCodec();
@@ -49,6 +51,7 @@
$entityChangeFactory,
$contentCodec,
$idParser,
+ $idComposer,
$entityNamespaceLookup,
wfWikiID(),
'en'
diff --git a/lib/includes/Store/Sql/TermSqlIndex.php
b/lib/includes/Store/Sql/TermSqlIndex.php
index 670d913..2e56ce0 100644
--- a/lib/includes/Store/Sql/TermSqlIndex.php
+++ b/lib/includes/Store/Sql/TermSqlIndex.php
@@ -16,6 +16,7 @@
use Wikibase\DataModel\Term\DescriptionsProvider;
use Wikibase\DataModel\Term\LabelsProvider;
use Wikibase\DataModel\Term\TermList;
+use Wikibase\Lib\EntityIdComposer;
use Wikibase\Lib\Store\LabelConflictFinder;
/**
@@ -43,6 +44,11 @@
private $stringNormalizer;
/**
+ * @var EntityIdComposer
+ */
+ private $entityIdComposer;
+
+ /**
* @var int
*/
private $maxConflicts = 500;
@@ -62,14 +68,16 @@
);
/**
- * @since 0.4
+ * @since 0.4
*
* @param StringNormalizer $stringNormalizer
- * @param string|bool $wikiDb
+ * @param EntityIdComposer $entityIdComposer
+ * @param string|bool $wikiDb
*/
- public function __construct( StringNormalizer $stringNormalizer,
$wikiDb = false ) {
+ public function __construct( StringNormalizer $stringNormalizer,
EntityIdComposer $entityIdComposer, $wikiDb = false ) {
parent::__construct( $wikiDb );
$this->stringNormalizer = $stringNormalizer;
+ $this->entityIdComposer = $entityIdComposer;
$this->tableName = 'wb_terms';
}
@@ -184,7 +192,7 @@
$terms = [];
$extraFields = [
'entityType' => $entity->getType(),
- 'entityId' => $id->getNumericId(),
+ 'entityId' => $id,
];
if ( $entity instanceof DescriptionsProvider ) {
@@ -767,7 +775,8 @@
}
if ( $key === 'term_entity_id' ) {
- $value = (int)$value;
+ // TODO: create an EntityId instance,
needs EntityIdComposer injected?
+ $value = $this->getEntityId(
$obtainedTerm );
} elseif ( $key === 'term_weight' ) {
$value = (float)$value;
}
@@ -782,6 +791,17 @@
}
/**
+ * @param object $termRow
+ * @return EntityId|null
+ */
+ private function getEntityId( $termRow ) {
+ if ( !isset( $termRow->term_entity_type ) || !isset(
$termRow->term_entity_id ) ) {
+ return null;
+ }
+ return $this->entityIdComposer->composeEntityId(
$termRow->term_entity_type, $termRow->term_entity_id );
+ }
+
+ /**
* @see TermIndex::clear
*
* @since 0.2
diff --git a/lib/includes/TermIndexEntry.php b/lib/includes/TermIndexEntry.php
index 308334c..4248c86 100644
--- a/lib/includes/TermIndexEntry.php
+++ b/lib/includes/TermIndexEntry.php
@@ -5,10 +5,8 @@
use InvalidArgumentException;
use MWException;
use RuntimeException;
-use Wikibase\Client\WikibaseClient;
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Term\Term;
-use Wikibase\Repo\WikibaseRepo;
/**
* Object representing a term index entry.
@@ -53,29 +51,28 @@
* @throws MWException
*/
public function __construct( array $fields = array() ) {
- foreach ( $fields as $name => $value ) {
- switch ( $name ) {
- case 'termType':
- $this->setType( $value );
- break;
- case 'termLanguage':
- $this->setLanguage( $value );
- break;
- case 'entityId':
- $this->setNumericId( $value );
- break;
- case 'entityType':
- $this->setEntityType( $value );
- break;
- case 'termText':
- $this->setText( $value );
- break;
- case 'termWeight':
- $this->setWeight( $value );
- break;
- default:
- throw new MWException( 'Invalid term
field provided' );
- }
+ $unexpectedFields = array_diff_key( $fields, array_flip(
self::$fieldNames ) );
+ if ( $unexpectedFields ) {
+ throw new MWException( 'Invalid term field provided' );
+ }
+
+ if ( array_key_exists( 'termType', $fields ) ) {
+ $this->setType( $fields['termType'] );
+ }
+ if ( array_key_exists( 'termLanguage', $fields ) ) {
+ $this->setLanguage( $fields['termLanguage'] );
+ }
+ if ( array_key_exists( 'entityId', $fields ) ) {
+ $this->setEntityId( $fields['entityId'] );
+ }
+ if ( array_key_exists( 'entityType', $fields ) ) {
+ $this->setEntityType( $fields['entityType'] );
+ }
+ if ( array_key_exists( 'termText', $fields ) ) {
+ $this->setText( $fields['termText'] );
+ }
+ if ( array_key_exists( 'termWeight', $fields ) ) {
+ $this->setWeight( $fields['termWeight'] );
}
}
@@ -173,6 +170,16 @@
* @throws MWException
*/
private function setEntityType( $entityType ) {
+ if ( isset( $this->fields['entityId'] ) ) {
+ if ( $this->fields['entityId']->getEntityType() !==
$entityType ) {
+ throw new MWException(
+ 'Cannot set entity type to "' .
$entityType . '"" as it does not match the type of entity id: "' .
+
$this->fields['entityId']->getEntityType() . '"'
+ );
+ }
+ return;
+ }
+
if ( !is_string( $entityType ) ) {
throw new MWException( 'Entity type code can only be a
string' );
}
@@ -186,27 +193,15 @@
* @return string|null
*/
public function getEntityType() {
+ if ( array_key_exists( 'entityId', $this->fields ) ) {
+ return $this->fields['entityId']->getEntityType();
+ }
return array_key_exists( 'entityType', $this->fields ) ?
$this->fields['entityType'] : null;
}
- /**
- * @param int $id
- *
- * @throws MWException
- */
- private function setNumericId( $id ) {
- if ( !is_int( $id ) ) {
- throw new MWException( 'Numeric ID can only be an
integer' );
- }
-
+ private function setEntityId( EntityId $id ) {
$this->fields['entityId'] = $id;
- }
-
- /**
- * @return int|null
- */
- private function getNumericId() {
- return array_key_exists( 'entityId', $this->fields ) ?
$this->fields['entityId'] : null;
+ $this->fields['entityType'] = $id->getEntityType();
}
/**
@@ -216,28 +211,7 @@
* @return EntityId|null
*/
public function getEntityId() {
- $entityType = $this->getEntityType();
- $numericId = $this->getNumericId();
-
- if ( $entityType !== null && $numericId !== null ) {
- // TODO: This does not belong to a value object.
Introduce a TermIndexEntryFactory and
- // encapsulate all knowledge about numeric IDs there.
- if ( defined( 'WB_VERSION' ) ) {
- $entityIdComposer =
WikibaseRepo::getDefaultInstance()->getEntityIdComposer();
- } elseif ( defined( 'WBC_VERSION' ) ) {
- $entityIdComposer =
WikibaseClient::getDefaultInstance()->getEntityIdComposer();
- } else {
- throw new RuntimeException( 'Need either client
or repo loaded' );
- }
-
- try {
- return $entityIdComposer->composeEntityId(
$entityType, $numericId );
- } catch ( InvalidArgumentException $ex ) {
- wfLogWarning( 'Unsupported entity type "' .
$entityType . '"' );
- }
- }
-
- return null;
+ return array_key_exists( 'entityId', $this->fields ) ?
$this->fields['entityId'] : null;
}
/**
@@ -259,8 +233,13 @@
if ( $exists !== array_key_exists( $n, $b->fields ) ) {
return $exists ? 1 : -1;
- } elseif ( $exists && $a->fields[$n] !== $b->fields[$n]
) {
- return $a->fields[$n] > $b->fields[$n] ? 1 : -1;
+ }
+ if ( $exists ) {
+ $aValue = $n !== 'entityId' ? $a->fields[$n] :
$a->fields[$n]->getSerialization();
+ $bValue = $n !== 'entityId' ? $b->fields[$n] :
$b->fields[$n]->getSerialization();
+ if ( $aValue !== $bValue ) {
+ return $aValue > $bValue ? 1 : -1;
+ }
}
}
diff --git a/lib/tests/phpunit/Interactors/TermIndexSearchInteractorTest.php
b/lib/tests/phpunit/Interactors/TermIndexSearchInteractorTest.php
index 84100f6..711cd8c 100644
--- a/lib/tests/phpunit/Interactors/TermIndexSearchInteractorTest.php
+++ b/lib/tests/phpunit/Interactors/TermIndexSearchInteractorTest.php
@@ -66,7 +66,7 @@
'termText' => $text,
'termLanguage' => $languageCode,
'termType' => $termType,
- 'entityId' => $entityId->getNumericId(),
+ 'entityId' => $entityId,
'entityType' => $entityId->getEntityType(),
) );
}
diff --git a/lib/tests/phpunit/NoBadDependencyUsageTest.php
b/lib/tests/phpunit/NoBadDependencyUsageTest.php
index 63ccaab..5d6294d 100644
--- a/lib/tests/phpunit/NoBadDependencyUsageTest.php
+++ b/lib/tests/phpunit/NoBadDependencyUsageTest.php
@@ -18,14 +18,14 @@
public function testNoRepoUsageInLib() {
// Increasing this allowance is forbidden
- $this->assertStringNotInLib( 'WikibaseRepo' . '::', 2 );
- $this->assertStringNotInLib( 'Wikibase\\Repo\\', 4 );
+ $this->assertStringNotInLib( 'WikibaseRepo' . '::', 1 );
+ $this->assertStringNotInLib( 'Wikibase\\Repo\\', 3 );
}
public function testNoClientUsageInLib() {
// Increasing this allowance is forbidden
- $this->assertStringNotInLib( 'WikibaseClient' . '::', 2 );
- $this->assertStringNotInLib( 'Wikibase\\Client\\', 2 );
+ $this->assertStringNotInLib( 'WikibaseClient' . '::', 1 );
+ $this->assertStringNotInLib( 'Wikibase\\Client\\', 1 );
}
/**
diff --git a/lib/tests/phpunit/Store/BufferingTermLookupTest.php
b/lib/tests/phpunit/Store/BufferingTermLookupTest.php
index 3401d57..9e08ab9 100644
--- a/lib/tests/phpunit/Store/BufferingTermLookupTest.php
+++ b/lib/tests/phpunit/Store/BufferingTermLookupTest.php
@@ -66,21 +66,21 @@
'termLanguage' => 'en',
'termText' => 'Vienna',
'entityType' => 'item',
- 'entityId' => 123
+ 'entityId' => new ItemId( 'Q123' ),
) ),
'de' => new TermIndexEntry( array(
'termType' => 'label',
'termLanguage' => 'de',
'termText' => 'Wien',
'entityType' => 'item',
- 'entityId' => 123
+ 'entityId' => new ItemId( 'Q123' ),
) ),
'fr' => new TermIndexEntry( array(
'termType' => 'label',
'termLanguage' => 'fr',
'termText' => 'Vienne',
'entityType' => 'item',
- 'entityId' => 123
+ 'entityId' => new ItemId( 'Q123' ),
) ),
);
diff --git a/lib/tests/phpunit/Store/EntityTermLookupTest.php
b/lib/tests/phpunit/Store/EntityTermLookupTest.php
index 12dc57d..e121ee2 100644
--- a/lib/tests/phpunit/Store/EntityTermLookupTest.php
+++ b/lib/tests/phpunit/Store/EntityTermLookupTest.php
@@ -127,28 +127,28 @@
protected function getTermIndex() {
$terms = array(
new TermIndexEntry( array(
- 'entityId' => 116,
+ 'entityId' => new ItemId( 'Q116' ),
'entityType' => 'item',
'termType' => 'label',
'termLanguage' => 'en',
'termText' => 'New York City'
) ),
new TermIndexEntry( array(
- 'entityId' => 116,
+ 'entityId' => new ItemId( 'Q116' ),
'entityType' => 'item',
'termType' => 'label',
'termLanguage' => 'es',
'termText' => 'Nueva York'
) ),
new TermIndexEntry( array(
- 'entityId' => 116,
+ 'entityId' => new ItemId( 'Q116' ),
'entityType' => 'item',
'termType' => 'description',
'termLanguage' => 'en',
'termText' => 'largest city in New York and the
United States of America'
) ),
new TermIndexEntry( array(
- 'entityId' => 116,
+ 'entityId' => new ItemId( 'Q116' ),
'entityType' => 'item',
'termType' => 'description',
'termLanguage' => 'de',
diff --git
a/lib/tests/phpunit/Store/LanguageFallbackLabelDescriptionLookupTest.php
b/lib/tests/phpunit/Store/LanguageFallbackLabelDescriptionLookupTest.php
index 4cb42c7..2510482 100644
--- a/lib/tests/phpunit/Store/LanguageFallbackLabelDescriptionLookupTest.php
+++ b/lib/tests/phpunit/Store/LanguageFallbackLabelDescriptionLookupTest.php
@@ -131,42 +131,42 @@
private function getTermIndex() {
$terms = array(
new TermIndexEntry( array(
- 'entityId' => 116,
+ 'entityId' => new ItemId( 'Q116' ),
'entityType' => 'item',
'termType' => 'label',
'termLanguage' => 'en',
'termText' => 'New York City'
) ),
new TermIndexEntry( array(
- 'entityId' => 116,
+ 'entityId' => new ItemId( 'Q116' ),
'entityType' => 'item',
'termType' => 'label',
'termLanguage' => 'es',
'termText' => 'New York City'
) ),
new TermIndexEntry( array(
- 'entityId' => 116,
+ 'entityId' => new ItemId( 'Q116' ),
'entityType' => 'item',
'termType' => 'description',
'termLanguage' => 'en',
'termText' => 'Big Apple'
) ),
new TermIndexEntry( array(
- 'entityId' => 117,
+ 'entityId' => new ItemId( 'Q117' ),
'entityType' => 'item',
'termType' => 'label',
'termLanguage' => 'en',
'termText' => 'Berlin'
) ),
new TermIndexEntry( array(
- 'entityId' => 118,
+ 'entityId' => new ItemId( 'Q118' ),
'entityType' => 'item',
'termType' => 'label',
'termLanguage' => 'zh-cn',
'termText' => '测试'
) ),
new TermIndexEntry( array(
- 'entityId' => 118,
+ 'entityId' => new ItemId( 'Q118' ),
'entityType' => 'item',
'termType' => 'description',
'termLanguage' => 'zh-cn',
diff --git a/lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php
b/lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php
index 3a8d3ab..1d8ccc2 100644
--- a/lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php
+++ b/lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php
@@ -9,6 +9,7 @@
use Wikibase\DataModel\Term\Fingerprint;
use Wikibase\DataModel\Term\Term;
use Wikibase\DataModel\Term\TermList;
+use Wikibase\Lib\EntityIdComposer;
use Wikibase\StringNormalizer;
use Wikibase\TermIndexEntry;
use Wikibase\TermSqlIndex;
@@ -43,8 +44,7 @@
* @return TermSqlIndex
*/
public function getTermIndex() {
- $normalizer = new StringNormalizer();
- return new TermSqlIndex( $normalizer );
+ return new TermSqlIndex( new StringNormalizer(), new
EntityIdComposer( [] ) );
}
public function termProvider() {
@@ -262,21 +262,21 @@
$expectedTerms = array(
new TermIndexEntry( array(
- 'entityId' => 999,
+ 'entityId' => new ItemId( 'Q999' ),
'entityType' => 'item',
'termText' => 'es un gato!',
'termLanguage' => 'es',
'termType' => 'description'
) ),
new TermIndexEntry( array(
- 'entityId' => 999,
+ 'entityId' => new ItemId( 'Q999' ),
'entityType' => 'item',
'termText' => 'kittens!!!:)',
'termLanguage' => 'en',
'termType' => 'label'
) ),
new TermIndexEntry( array(
- 'entityId' => 999,
+ 'entityId' => new ItemId( 'Q999' ),
'entityType' => 'item',
'termText' => 'kitten-alias',
'termLanguage' => 'en',
diff --git a/lib/tests/phpunit/Store/TermPropertyLabelResolverTest.php
b/lib/tests/phpunit/Store/TermPropertyLabelResolverTest.php
index 3fea28e..abcc6dd 100644
--- a/lib/tests/phpunit/Store/TermPropertyLabelResolverTest.php
+++ b/lib/tests/phpunit/Store/TermPropertyLabelResolverTest.php
@@ -4,6 +4,7 @@
use HashBagOStuff;
use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\Property;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Services\Term\PropertyLabelResolver;
@@ -61,28 +62,28 @@
new TermIndexEntry( array(
'termType' => 'label',
'termLanguage' => 'de',
- 'entityId' => 1,
+ 'entityId' => new PropertyId( 'P1' ),
'entityType' => Property::ENTITY_TYPE,
'termText' => 'Eins',
) ),
new TermIndexEntry( array(
'termType' => 'label',
'termLanguage' => 'de',
- 'entityId' => 2,
+ 'entityId' => new PropertyId( 'P2' ),
'entityType' => Property::ENTITY_TYPE,
'termText' => 'Zwei',
) ),
new TermIndexEntry( array(
'termType' => 'label',
'termLanguage' => 'de',
- 'entityId' => 3,
+ 'entityId' => new PropertyId( 'P3' ),
'entityType' => Property::ENTITY_TYPE,
'termText' => 'Drei',
) ),
new TermIndexEntry( array(
'termType' => 'label',
'termLanguage' => 'de',
- 'entityId' => 4,
+ 'entityId' => new PropertyId( 'P4' ),
'entityType' => Property::ENTITY_TYPE,
'termText' => 'vier', // lower case
) ),
@@ -91,28 +92,28 @@
new TermIndexEntry( array(
'termType' => 'label',
'termLanguage' => 'en',
- 'entityId' => 1,
+ 'entityId' => new PropertyId( 'P1' ),
'entityType' => Property::ENTITY_TYPE,
'termText' => 'One',
) ),
new TermIndexEntry( array(
'termType' => 'label',
'termLanguage' => 'en',
- 'entityId' => 2,
+ 'entityId' => new ItemId( 'Q2' ),
'entityType' => Item::ENTITY_TYPE, // not a
property
'termText' => 'Two',
) ),
new TermIndexEntry( array(
'termType' => 'alias', // not a label
'termLanguage' => 'en',
- 'entityId' => 3,
+ 'entityId' => new PropertyId( 'P3' ),
'entityType' => Property::ENTITY_TYPE,
'termText' => 'Three',
) ),
new TermIndexEntry( array(
'termType' => 'description', // not a label
'termLanguage' => 'en',
- 'entityId' => 4,
+ 'entityId' => new PropertyId( 'P4' ),
'entityType' => Property::ENTITY_TYPE,
'termText' => 'Four',
) ),
diff --git a/lib/tests/phpunit/TermIndexEntryTest.php
b/lib/tests/phpunit/TermIndexEntryTest.php
index f29efc8..9cfdfc0 100644
--- a/lib/tests/phpunit/TermIndexEntryTest.php
+++ b/lib/tests/phpunit/TermIndexEntryTest.php
@@ -4,6 +4,8 @@
use MWException;
use PHPUnit_Framework_TestCase;
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\LegacyIdInterpreter;
use Wikibase\DataModel\Term\Term;
use Wikibase\TermIndexEntry;
@@ -25,7 +27,7 @@
[
[
'entityType' => 'item',
- 'entityId' => 23,
+ 'entityId' => new ItemId( 'Q23' ),
'termType' =>
TermIndexEntry::TYPE_LABEL,
'termLanguage' => 'en',
'termText' => 'foo',
@@ -42,7 +44,7 @@
[
[
'entityType' => 'item',
- 'entityId' => 23,
+ 'entityId' => new ItemId( 'Q23' ),
]
],
];
@@ -54,14 +56,8 @@
public function testConstructor( $fields ) {
$term = new TermIndexEntry( $fields );
- $entityId = null;
- if ( isset( $fields['entityType'] ) && isset(
$fields['entityId'] ) ) {
- // FIXME: This must be removed once we got rid of all
legacy numeric ids.
- $entityId =
LegacyIdInterpreter::newIdFromTypeAndNumber( $fields['entityType'],
$fields['entityId'] );
- }
-
$this->assertEquals( isset( $fields['entityType'] ) ?
$fields['entityType'] : null, $term->getEntityType() );
- $this->assertEquals( $entityId, $term->getEntityId() );
+ $this->assertEquals( isset( $fields['entityId'] ) ?
$fields['entityId'] : null, $term->getEntityId() );
$this->assertEquals( isset( $fields['termType'] ) ?
$fields['termType'] : null, $term->getType() );
$this->assertEquals( isset( $fields['termLanguage'] ) ?
$fields['termLanguage'] : null, $term->getLanguage() );
$this->assertEquals( isset( $fields['termText'] ) ?
$fields['termText'] : null, $term->getText() );
@@ -71,6 +67,11 @@
public function testGivenInvalidField_constructorThrowsException() {
$this->setExpectedException( MWException::class );
new TermIndexEntry( [ 'fooField' => 'bar' ] );
+ }
+
+ public function
testGivenEntityTypeMismatch_constructorThrowsException() {
+ $this->setExpectedException( MWException::class );
+ new TermIndexEntry( [ 'entityId' => new ItemId( 'Q222' ),
'entityType' => 'property' ] );
}
public function testClone() {
@@ -88,7 +89,7 @@
private function newInstance( array $extraFields = [] ) {
return new TermIndexEntry( $extraFields + [
'entityType' => 'item',
- 'entityId' => 23,
+ 'entityId' => new ItemId( 'Q23' ),
'termType' => TermIndexEntry::TYPE_LABEL,
'termLanguage' => 'en',
'termText' => 'foo',
@@ -116,12 +117,7 @@
],
'other entity id' => [
$term,
- $this->newInstance( [ 'entityType' =>
'property', 'entityId' => 11 ] ),
- false
- ],
- 'other entity type' => [
- $term,
- $this->newInstance( [ 'entityType' =>
'property' ] ),
+ $this->newInstance( [ 'entityType' =>
'property', 'entityId' => new PropertyId( 'P11' ) ] ),
false
],
'other language' => [
diff --git a/repo/includes/Store/Sql/SqlStore.php
b/repo/includes/Store/Sql/SqlStore.php
index 7c77a22..351a10a 100644
--- a/repo/includes/Store/Sql/SqlStore.php
+++ b/repo/includes/Store/Sql/SqlStore.php
@@ -222,7 +222,7 @@
//TODO: Get $stringNormalizer from WikibaseRepo?
// Can't really pass this via the constructor...
$stringNormalizer = new StringNormalizer();
- return new TermSqlIndex( $stringNormalizer );
+ return new TermSqlIndex( $stringNormalizer,
$this->entityIdComposer );
}
/**
diff --git
a/repo/tests/phpunit/includes/LabelDescriptionDuplicateDetectorTest.php
b/repo/tests/phpunit/includes/LabelDescriptionDuplicateDetectorTest.php
index 3591672..12e3acf 100644
--- a/repo/tests/phpunit/includes/LabelDescriptionDuplicateDetectorTest.php
+++ b/repo/tests/phpunit/includes/LabelDescriptionDuplicateDetectorTest.php
@@ -6,6 +6,7 @@
use Wikibase\DataModel\Entity\Item;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\Property;
+use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\LabelDescriptionDuplicateDetector;
use Wikibase\Lib\Tests\Store\MockTermIndex;
use Wikibase\Repo\Validators\UniquenessViolation;
@@ -28,7 +29,7 @@
$world[] = new TermIndexEntry( array(
'termType' => TermIndexEntry::TYPE_LABEL,
'termLanguage' => 'en',
- 'entityId' => 42,
+ 'entityId' => new ItemId( 'Q42' ),
'entityType' => Item::ENTITY_TYPE,
'termText' => 'item label',
) );
@@ -36,7 +37,7 @@
$world[] = new TermIndexEntry( array(
'termType' => TermIndexEntry::TYPE_DESCRIPTION,
'termLanguage' => 'en',
- 'entityId' => 42,
+ 'entityId' => new ItemId( 'Q42' ),
'entityType' => Item::ENTITY_TYPE,
'termText' => 'item description',
) );
@@ -44,7 +45,7 @@
$world[] = new TermIndexEntry( array(
'termType' => TermIndexEntry::TYPE_ALIAS,
'termLanguage' => 'en',
- 'entityId' => 42,
+ 'entityId' => new ItemId( 'Q42' ),
'entityType' => Item::ENTITY_TYPE,
'termText' => 'item alias',
) );
@@ -52,7 +53,7 @@
$world[] = new TermIndexEntry( array(
'termType' => TermIndexEntry::TYPE_LABEL,
'termLanguage' => 'en',
- 'entityId' => 17,
+ 'entityId' => new PropertyId( 'P42' ),
'entityType' => Property::ENTITY_TYPE,
'termText' => 'property label',
) );
--
To view, visit https://gerrit.wikimedia.org/r/322919
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2819090b4759fa1281fcc570b9feb42122ae2442
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits