Jakob has uploaded a new change for review. https://gerrit.wikimedia.org/r/325307
Change subject: Use ID serialization for PropertyInfoLookup return values. ...................................................................... Use ID serialization for PropertyInfoLookup return values. This is done to avoid collisions when dealing with properties from different repositories. Bug: T152389 Change-Id: I819123a847ba39536c92abc177d18a2bb14d9ba5 --- M lib/includes/Store/CachingPropertyInfoStore.php M lib/includes/Store/Sql/PropertyInfoTable.php M lib/tests/phpunit/Store/MockPropertyInfoStore.php M lib/tests/phpunit/Store/PropertyInfoStoreTestHelper.php M repo/includes/Specials/SpecialListProperties.php 5 files changed, 24 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/07/325307/1 diff --git a/lib/includes/Store/CachingPropertyInfoStore.php b/lib/includes/Store/CachingPropertyInfoStore.php index 4c9c723..3791e31 100644 --- a/lib/includes/Store/CachingPropertyInfoStore.php +++ b/lib/includes/Store/CachingPropertyInfoStore.php @@ -81,7 +81,7 @@ */ public function getPropertyInfo( PropertyId $propertyId ) { $propertyInfo = $this->getAllPropertyInfo(); - $id = $propertyId->getNumericId(); + $id = $propertyId->getSerialization(); if ( isset( $propertyInfo[$id] ) ) { return $propertyInfo[$id]; @@ -153,7 +153,7 @@ // Get local cached version. // NOTE: this may be stale at this point, if it was already loaded $propertyInfo = $this->getAllPropertyInfo(); - $id = $propertyId->getNumericId(); + $id = $propertyId->getSerialization(); // update local cache $propertyInfo[$id] = $info; @@ -172,7 +172,7 @@ * @return bool */ public function removePropertyInfo( PropertyId $propertyId ) { - $id = $propertyId->getNumericId(); + $id = $propertyId->getSerialization(); // if we don't know it, don't delete it. if ( is_array( $this->propertyInfo ) && !array_key_exists( $id, $this->propertyInfo ) ) { diff --git a/lib/includes/Store/Sql/PropertyInfoTable.php b/lib/includes/Store/Sql/PropertyInfoTable.php index aa1916e..7df1dc9 100644 --- a/lib/includes/Store/Sql/PropertyInfoTable.php +++ b/lib/includes/Store/Sql/PropertyInfoTable.php @@ -152,7 +152,7 @@ $this->releaseConnection( $dbr ); - return $infos; + return $this->convertNumericIdKeysToIdSerializations( $infos ); } /** @@ -175,7 +175,17 @@ $this->releaseConnection( $dbr ); - return $infos; + return $this->convertNumericIdKeysToIdSerializations( $infos ); + } + + private function convertNumericIdKeysToIdSerializations( array $infos ) { + $newInfos = []; + + foreach ( $infos as $id => $info ) { + $newInfos[PropertyId::newFromNumber( $id )->getSerialization()] = $info; + } + + return $newInfos; } /** diff --git a/lib/tests/phpunit/Store/MockPropertyInfoStore.php b/lib/tests/phpunit/Store/MockPropertyInfoStore.php index 41a27e4..b281c5f 100644 --- a/lib/tests/phpunit/Store/MockPropertyInfoStore.php +++ b/lib/tests/phpunit/Store/MockPropertyInfoStore.php @@ -38,7 +38,7 @@ } $propertyInfo = $this->getAllPropertyInfo(); - $id = $propertyId->getNumericId(); + $id = $propertyId->getSerialization(); if ( isset( $propertyInfo[$id] ) ) { return $propertyInfo[$id]; @@ -88,7 +88,7 @@ throw new InvalidArgumentException( 'Missing required info field: ' . PropertyInfoStore::KEY_DATA_TYPE ); } - $id = $propertyId->getNumericId(); + $id = $propertyId->getSerialization(); $this->propertyInfo[$id] = $info; } @@ -101,7 +101,7 @@ * @return bool */ public function removePropertyInfo( PropertyId $propertyId ) { - $id = $propertyId->getNumericId(); + $id = $propertyId->getSerialization(); if ( array_key_exists( $id, $this->propertyInfo ) ) { unset( $this->propertyInfo[$id] ); diff --git a/lib/tests/phpunit/Store/PropertyInfoStoreTestHelper.php b/lib/tests/phpunit/Store/PropertyInfoStoreTestHelper.php index 2f3f54d..c2505c2 100644 --- a/lib/tests/phpunit/Store/PropertyInfoStoreTestHelper.php +++ b/lib/tests/phpunit/Store/PropertyInfoStoreTestHelper.php @@ -121,14 +121,14 @@ $table->setPropertyInfo( $p42, $info42 ); $this->test->assertSame( - array( 42 => $info42 ), + array( 'P42' => $info42 ), $table->getPropertyInfoForDataType( 'commonsMedia' ), 'after adding the second property' ); $table->removePropertyInfo( $p23 ); $this->test->assertSame( - array( 42 => $info42 ), + array( 'P42' => $info42 ), $table->getPropertyInfoForDataType( 'commonsMedia' ), 'after removing one property' ); @@ -156,21 +156,21 @@ $table->setPropertyInfo( $p23, $info23 ); $this->test->assertSame( - array( 23 => $info23 ), + array( 'P23' => $info23 ), $table->getAllPropertyInfo(), 'after adding one property' ); $table->setPropertyInfo( $p42, $info42 ); $this->test->assertSame( - array( 23 => $info23, 42 => $info42 ), + array( 'P23' => $info23, 'P42' => $info42 ), $table->getAllPropertyInfo(), 'after adding the second property' ); $table->removePropertyInfo( $p23 ); $this->test->assertSame( - array( 42 => $info42 ), + array( 'P42' => $info42 ), $table->getAllPropertyInfo(), 'after removing one property' ); diff --git a/repo/includes/Specials/SpecialListProperties.php b/repo/includes/Specials/SpecialListProperties.php index 17814cc..e621d8b 100644 --- a/repo/includes/Specials/SpecialListProperties.php +++ b/repo/includes/Specials/SpecialListProperties.php @@ -256,7 +256,7 @@ ); } - // NOTE: $propertyInfo uses numerical property IDs as keys! + // NOTE: $propertyInfo uses serialized property IDs as keys! ksort( $propertyInfo ); return $propertyInfo; } -- To view, visit https://gerrit.wikimedia.org/r/325307 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I819123a847ba39536c92abc177d18a2bb14d9ba5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jakob <jakob.warkot...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits