jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/346169 )

Change subject: Writing full IDs to wb_terms on insert
......................................................................


Writing full IDs to wb_terms on insert

Also introduce a setting flag to denote that the column
exists and we can write to the column.

DEPLOY: need to set the setting to false before deploy
for wikidata + test wikidata, if we don't have the column yet.

Bug: T159851
Change-Id: I5faecd02c392dd5a0861f4cc4658856dea7e3ce6
---
M client/config/WikibaseClient.default.php
M client/includes/Store/Sql/DirectSqlStore.php
M lib/includes/Store/Sql/TermSqlIndex.php
M lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php
M repo/config/Wikibase.default.php
M repo/includes/Store/Sql/SqlStore.php
6 files changed, 98 insertions(+), 5 deletions(-)

Approvals:
  WMDE-leszek: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/client/config/WikibaseClient.default.php 
b/client/config/WikibaseClient.default.php
index efb7fc0..873c4f7 100644
--- a/client/config/WikibaseClient.default.php
+++ b/client/config/WikibaseClient.default.php
@@ -89,6 +89,9 @@
                'repositoryServiceWiringFiles' => [ __DIR__ . 
'/../includes/Store/RepositoryServiceWiring.php' ],
                'dispatchingServiceWiringFiles' => [ __DIR__ . 
'/../includes/DispatchingServiceWiring.php' ],
                'foreignRepositories' => [],
+
+               // Enable use of term_full_entity_id column in wb_terms table.
+               'hasFullEntityIdColumn' => true,
        ];
 
        // Some defaults depend on information not available at this time.
diff --git a/client/includes/Store/Sql/DirectSqlStore.php 
b/client/includes/Store/Sql/DirectSqlStore.php
index 208f0da..44830ca 100644
--- a/client/includes/Store/Sql/DirectSqlStore.php
+++ b/client/includes/Store/Sql/DirectSqlStore.php
@@ -161,6 +161,11 @@
        private $siteId;
 
        /**
+        * @var bool
+        */
+       private $hasFullEntityIdColumn;
+
+       /**
         * @param EntityChangeFactory $entityChangeFactory
         * @param EntityContentDataCodec $contentCodec
         * @param EntityIdParser $entityIdParser
@@ -196,6 +201,7 @@
                $this->cacheType = $settings->getSetting( 'sharedCacheType' );
                $this->cacheDuration = $settings->getSetting( 
'sharedCacheDuration' );
                $this->siteId = $settings->getSetting( 'siteGlobalID' );
+               $this->hasFullEntityIdColumn = $settings->getSetting( 
'hasFullEntityIdColumn' );
        }
 
        /**
@@ -361,7 +367,13 @@
                if ( $this->termIndex === null ) {
                        // TODO: Get StringNormalizer from WikibaseClient?
                        // Can't really pass this via the constructor...
-                       $this->termIndex = new TermSqlIndex( new 
StringNormalizer(), $this->entityIdComposer, $this->repoWiki );
+                       $this->termIndex = new TermSqlIndex(
+                               new StringNormalizer(),
+                               $this->entityIdComposer,
+                               $this->repoWiki,
+                               '',
+                               $this->hasFullEntityIdColumn
+                       );
                }
 
                return $this->termIndex;
diff --git a/lib/includes/Store/Sql/TermSqlIndex.php 
b/lib/includes/Store/Sql/TermSqlIndex.php
index 133725b..32e8f6a 100644
--- a/lib/includes/Store/Sql/TermSqlIndex.php
+++ b/lib/includes/Store/Sql/TermSqlIndex.php
@@ -49,6 +49,11 @@
        private $entityIdComposer;
 
        /**
+        * @var bool
+        */
+       private $hasFullEntityIdColumn;
+
+       /**
         * @var int
         */
        private $maxConflicts = 500;
@@ -58,18 +63,22 @@
         * @param EntityIdComposer $entityIdComposer
         * @param string|bool $wikiDb
         * @param string $repositoryName
+        * @param bool $hasFullEntityIdColumn Allow use (e.g. writing) of 
column.
         */
        public function __construct(
                StringNormalizer $stringNormalizer,
                EntityIdComposer $entityIdComposer,
                $wikiDb = false,
-               $repositoryName = ''
+               $repositoryName = '',
+               $hasFullEntityIdColumn = true
        ) {
                RepositoryNameAssert::assertParameterIsValidRepositoryName( 
$repositoryName, '$repositoryName' );
                parent::__construct( $wikiDb );
                $this->repositoryName = $repositoryName;
                $this->stringNormalizer = $stringNormalizer;
                $this->entityIdComposer = $entityIdComposer;
+               $this->hasFullEntityIdColumn = $hasFullEntityIdColumn;
+
                $this->tableName = 'wb_terms';
        }
 
@@ -168,15 +177,18 @@
        private function insertTerms( EntityDocument $entity, array $terms, 
Database $dbw ) {
                $entityId = $entity->getId();
                $this->assertIsNumericEntityId( $entityId );
-               /** @var Int32EntityId $entityId */
+               /** @var EntityId|Int32EntityId $entityId */
 
                $entityIdentifiers = array(
-                       // FIXME: this will fail for IDs that do not have a 
numeric form
                        'term_entity_id' => $entityId->getNumericId(),
                        'term_entity_type' => $entity->getType(),
                        'term_weight' => $this->getWeight( $entity ),
                );
 
+               if ( $this->hasFullEntityIdColumn === true ) {
+                       $entityIdentifiers['term_full_entity_id'] = 
$entityId->getSerialization();
+               }
+
                wfDebugLog( __CLASS__, __FUNCTION__ . ': inserting terms for ' 
. $entity->getId()->getSerialization() );
 
                $success = true;
diff --git a/lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php 
b/lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php
index 2611ad8..adf4c7c 100644
--- a/lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php
+++ b/lib/tests/phpunit/Store/Sql/TermSqlIndexTest.php
@@ -437,4 +437,55 @@
                $fooTermIndex->deleteTermsOfEntity( new ItemId( 'Q300' ) );
        }
 
+       public function testSaveTermsOfEntity_withoutFullEntityId() {
+               $item = new Item( new ItemId( 'Q11116325' ) );
+               $item->setLabel( 'en', 'kitten-Q11116325' );
+
+               $termIndex = new TermSqlIndex(
+                       new StringNormalizer(),
+                       new EntityIdComposer( [
+                               'item' => function( $repositoryName, 
$uniquePart ) {
+                                       return new ItemId( 'Q' . $uniquePart );
+                               },
+                               'property' => function( $repositoryName, 
$uniquePart ) {
+                                       return new PropertyId( 'P' . 
$uniquePart );
+                               },
+                       ] ),
+                       false,
+                       '',
+                       false
+               );
+
+               $result = $termIndex->saveTermsOfEntity( $item );
+               $this->assertTrue( $result );
+
+               $row = $this->db->selectRow(
+                       'wb_terms',
+                       [ 'term_entity_id', 'term_entity_type', 
'term_full_entity_id' ],
+                       [ 'term_entity_id' => '11116325', 'term_entity_type' => 
'item' ],
+                       __METHOD__
+               );
+
+               $this->assertNull( $row->term_full_entity_id );
+       }
+
+       public function testSaveTermsOfEntity_withFullEntityId() {
+               $item = new Item( new ItemId( 'Q1112362' ) );
+               $item->setLabel( 'en', 'kitten-Q1112362' );
+
+               $termIndex = $this->getTermIndex();
+
+               $result = $termIndex->saveTermsOfEntity( $item );
+               $this->assertTrue( $result );
+
+               $row = $this->db->selectRow(
+                       'wb_terms',
+                       [ 'term_entity_id', 'term_entity_type', 
'term_full_entity_id' ],
+                       [ 'term_entity_id' => '1112362', 'term_entity_type' => 
'item' ],
+                       __METHOD__
+               );
+
+               $this->assertSame( 'Q1112362', $row->term_full_entity_id );
+       }
+
 }
diff --git a/repo/config/Wikibase.default.php b/repo/config/Wikibase.default.php
index 0303e8b..8952526 100644
--- a/repo/config/Wikibase.default.php
+++ b/repo/config/Wikibase.default.php
@@ -209,4 +209,7 @@
 
        // Name of the lock manager for dispatch changes coordinator
        'dispatchingLockManager' => null,
+
+       // Enable use (e.g. writing) of term_full_entity_id column in wb_terms 
table.
+       'hasFullEntityIdColumn' => true,
 ];
diff --git a/repo/includes/Store/Sql/SqlStore.php 
b/repo/includes/Store/Sql/SqlStore.php
index 7e3bf8e..3495211 100644
--- a/repo/includes/Store/Sql/SqlStore.php
+++ b/repo/includes/Store/Sql/SqlStore.php
@@ -180,6 +180,11 @@
        private $idBlacklist;
 
        /**
+        * @var bool
+        */
+       private $hasFullEntityIdColumn;
+
+       /**
         * @param EntityChangeFactory $entityChangeFactory
         * @param EntityContentDataCodec $contentCodec
         * @param EntityIdParser $entityIdParser
@@ -216,6 +221,7 @@
                $this->cacheType = $settings->getSetting( 'sharedCacheType' );
                $this->cacheDuration = $settings->getSetting( 
'sharedCacheDuration' );
                $this->idBlacklist = $settings->getSetting( 'idBlacklist' );
+               $this->hasFullEntityIdColumn = $settings->getSetting( 
'hasFullEntityIdColumn' );
        }
 
        /**
@@ -247,7 +253,13 @@
                //TODO: Get $stringNormalizer from WikibaseRepo?
                //      Can't really pass this via the constructor...
                $stringNormalizer = new StringNormalizer();
-               return new TermSqlIndex( $stringNormalizer, 
$this->entityIdComposer );
+               return new TermSqlIndex(
+                       $stringNormalizer,
+                       $this->entityIdComposer,
+                       false,
+                       '',
+                       $this->hasFullEntityIdColumn
+               );
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/346169
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5faecd02c392dd5a0861f4cc4658856dea7e3ce6
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to