jenkins-bot has submitted this change and it was merged. Change subject: Narrow the SiteLinkLookup interface ......................................................................
Narrow the SiteLinkLookup interface By moving the getConflictsForItem method to a new SiteLinkConflictLookup interface where it fits in better. Change-Id: Ib4bc24ecfe4094c3ea08401682058bd63535f3f8 --- A lib/includes/store/SiteLinkConflictLookup.php M lib/includes/store/SiteLinkLookup.php M lib/includes/store/sql/SiteLinkTable.php M lib/tests/phpunit/MockRepository.php M repo/includes/Validators/EntityConstraintProvider.php M repo/includes/Validators/SiteLinkUniquenessValidator.php M repo/includes/WikibaseRepo.php M repo/includes/store/Store.php M repo/includes/store/sql/SqlStore.php M repo/tests/phpunit/includes/ChangeOp/ChangeOpFactoryProviderTest.php M repo/tests/phpunit/includes/ChangeOp/ChangeOpTestMockProvider.php M repo/tests/phpunit/includes/Validators/EntityConstraintProviderTest.php M repo/tests/phpunit/includes/Validators/SiteLinkUniquenessValidatorTest.php M repo/tests/phpunit/includes/Validators/TermValidatorFactoryTest.php 14 files changed, 94 insertions(+), 59 deletions(-) Approvals: Daniel Kinzler: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/includes/store/SiteLinkConflictLookup.php b/lib/includes/store/SiteLinkConflictLookup.php new file mode 100644 index 0000000..5ee7eec --- /dev/null +++ b/lib/includes/store/SiteLinkConflictLookup.php @@ -0,0 +1,40 @@ +<?php + +namespace Wikibase\Lib\Store; + +use DatabaseBase; +use Wikibase\DataModel\Entity\Item; + +/** + * Contains methods for looking up SiteLink conflicts + * + * @since 0.5 + * + * @license GNU GPL v2+ + * @author Marius Hoch < h...@online.de > + */ +interface SiteLinkConflictLookup { + + /** + * Returns an array with the conflicts between the item and the sitelinks + * currently in the store. The array is empty if there are no such conflicts. + * + * The items in the return array are arrays with the following elements: + * - int itemId Numeric (unprefixed) item id + * - string siteId + * - string sitePage + * + * @since 0.1 + * + * @param Item $item + * @param DatabaseBase|null $db The database object to use (optional). + * If conflict checking is performed as part of a save operation, + * this should be used to provide the master DB connection that will + * also be used for saving. This will preserve transactional integrity + * and avoid race conditions. + * + * @return array[] + */ + public function getConflictsForItem( Item $item, DatabaseBase $db = null ); + +} diff --git a/lib/includes/store/SiteLinkLookup.php b/lib/includes/store/SiteLinkLookup.php index 74b025c..c2846c9 100644 --- a/lib/includes/store/SiteLinkLookup.php +++ b/lib/includes/store/SiteLinkLookup.php @@ -2,8 +2,6 @@ namespace Wikibase\Lib\Store; -use DatabaseBase; -use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\SiteLink; @@ -16,28 +14,6 @@ * @author Jeroen De Dauw < jeroended...@gmail.com > */ interface SiteLinkLookup { - - /** - * Returns an array with the conflicts between the item and the sitelinks - * currently in the store. The array is empty if there are no such conflicts. - * - * The items in the return array are arrays with the following elements: - * - int itemId Numeric (unprefixed) item id - * - string siteId - * - string sitePage - * - * @since 0.1 - * - * @param Item $item - * @param DatabaseBase|null $db The database object to use (optional). - * If conflict checking is performed as part of a save operation, - * this should be used to provide the master DB connection that will - * also be used for saving. This will preserve transactional integrity - * and avoid race conditions. - * - * @return array[] - */ - public function getConflictsForItem( Item $item, DatabaseBase $db = null ); /** * Returns the id of the item that is equivalent to the diff --git a/lib/includes/store/sql/SiteLinkTable.php b/lib/includes/store/sql/SiteLinkTable.php index a3cb1d0..0556849 100644 --- a/lib/includes/store/sql/SiteLinkTable.php +++ b/lib/includes/store/sql/SiteLinkTable.php @@ -3,6 +3,7 @@ namespace Wikibase\Lib\Store; use DatabaseBase; +use DBAccessBase; use MWException; use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\ItemId; @@ -18,7 +19,7 @@ * @author Jeroen De Dauw < jeroended...@gmail.com > * @author Daniel Kinzler */ -class SiteLinkTable extends \DBAccessBase implements SiteLinkCache { +class SiteLinkTable extends DBAccessBase implements SiteLinkCache, SiteLinkConflictLookup { /** * @since 0.1 @@ -272,7 +273,7 @@ } /** - * @see SiteLinkLookup::getConflictsForItem + * @see SiteLinkConflictLookup::getConflictsForItem * * @param Item $item * @param DatabaseBase|null $db diff --git a/lib/tests/phpunit/MockRepository.php b/lib/tests/phpunit/MockRepository.php index 5b7197c..58b5381 100644 --- a/lib/tests/phpunit/MockRepository.php +++ b/lib/tests/phpunit/MockRepository.php @@ -26,6 +26,7 @@ use Wikibase\Lib\Store\EntityStore; use Wikibase\Lib\Store\GenericEntityInfoBuilder; use Wikibase\Lib\Store\SiteLinkLookup; +use Wikibase\Lib\Store\SiteLinkConflictLookup; use Wikibase\Lib\Store\StorageException; use Wikibase\Lib\Store\UnresolvedRedirectException; @@ -43,7 +44,8 @@ EntityRevisionLookup, EntityStore, PropertyDataTypeLookup, - SiteLinkLookup + SiteLinkLookup, + SiteLinkConflictLookup { /** @@ -169,7 +171,7 @@ } /** - * @see SiteLinkLookup::getConflictsForItem + * @see SiteLinkConflictLookup::getConflictsForItem * * @param Item $item * @param DatabaseBase|null $db diff --git a/repo/includes/Validators/EntityConstraintProvider.php b/repo/includes/Validators/EntityConstraintProvider.php index 4df1851..648b653 100644 --- a/repo/includes/Validators/EntityConstraintProvider.php +++ b/repo/includes/Validators/EntityConstraintProvider.php @@ -5,7 +5,7 @@ use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\Property; use Wikibase\LabelDescriptionDuplicateDetector; -use Wikibase\Lib\Store\SiteLinkLookup; +use Wikibase\Lib\Store\SiteLinkConflictLookup; /** * Provides constraints for each entity type. @@ -24,20 +24,20 @@ private $duplicateDetector; /** - * @var SiteLinkLookup + * @var SiteLinkConflictLookup */ - private $siteLinkLookup; + private $siteLinkConflictLookup; /** * @param LabelDescriptionDuplicateDetector $duplicateDetector - * @param SiteLinkLookup $siteLinkLookup + * @param SiteLinkConflictLookup $siteLinkConflictLookup */ public function __construct( LabelDescriptionDuplicateDetector $duplicateDetector, - SiteLinkLookup $siteLinkLookup + SiteLinkConflictLookup $siteLinkConflictLookup ) { $this->duplicateDetector = $duplicateDetector; - $this->siteLinkLookup = $siteLinkLookup; + $this->siteLinkConflictLookup = $siteLinkConflictLookup; //TODO: Make validators configurable. Allow more types to register. } @@ -59,7 +59,7 @@ break; case Item::ENTITY_TYPE: - $validators[] = new SiteLinkUniquenessValidator( $this->siteLinkLookup ); + $validators[] = new SiteLinkUniquenessValidator( $this->siteLinkConflictLookup ); break; } diff --git a/repo/includes/Validators/SiteLinkUniquenessValidator.php b/repo/includes/Validators/SiteLinkUniquenessValidator.php index 36bd35d..73b6405 100644 --- a/repo/includes/Validators/SiteLinkUniquenessValidator.php +++ b/repo/includes/Validators/SiteLinkUniquenessValidator.php @@ -8,7 +8,7 @@ use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\SiteLink; -use Wikibase\Lib\Store\SiteLinkLookup; +use Wikibase\Lib\Store\SiteLinkConflictLookup; /** * Validator for checking that site links are unique across all Items. @@ -21,15 +21,15 @@ class SiteLinkUniquenessValidator implements EntityValidator { /** - * @var SiteLinkLookup + * @var SiteLinkConflictLookup */ - private $siteLinkLookup; + private $siteLinkConflictLookup; /** - * @param SiteLinkLookup $siteLinkLookup + * @param SiteLinkConflictLookup $siteLinkConflictLookup */ - public function __construct( SiteLinkLookup $siteLinkLookup ) { - $this->siteLinkLookup = $siteLinkLookup; + public function __construct( SiteLinkConflictLookup $siteLinkConflictLookup ) { + $this->siteLinkConflictLookup = $siteLinkConflictLookup; } /** @@ -46,7 +46,7 @@ // TODO: do not use global state $db = wfGetDB( DB_MASTER ); - $conflicts = $this->siteLinkLookup->getConflictsForItem( $entity, $db ); + $conflicts = $this->siteLinkConflictLookup->getConflictsForItem( $entity, $db ); /* @var ItemId $ignoreConflictsWith */ foreach ( $conflicts as $conflict ) { @@ -60,7 +60,7 @@ /** * Get Message for a conflict * - * @param array $conflict A record as returned by SiteLinkLookup::getConflictsForItem() + * @param array $conflict A record as returned by SiteLinkConflictLookup::getConflictsForItem() * * @return Error */ diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php index 7f5573d..25b2167 100644 --- a/repo/includes/WikibaseRepo.php +++ b/repo/includes/WikibaseRepo.php @@ -717,7 +717,7 @@ public function getEntityConstraintProvider() { return new EntityConstraintProvider( $this->getLabelDescriptionDuplicateDetector(), - $this->getStore()->newSiteLinkCache() + $this->getStore()->getSiteLinkConflictLookup() ); } diff --git a/repo/includes/store/Store.php b/repo/includes/store/Store.php index 34e7104..2daa2ba 100644 --- a/repo/includes/store/Store.php +++ b/repo/includes/store/Store.php @@ -9,6 +9,7 @@ use Wikibase\Lib\Store\EntityStoreWatcher; use Wikibase\Lib\Store\LabelConflictFinder; use Wikibase\Lib\Store\SiteLinkCache; +use Wikibase\Lib\Store\SiteLinkConflictLookup; use Wikibase\Repo\Store\EntityPerPage; /** @@ -130,4 +131,11 @@ */ public function getChangesTable(); + /** + * @since 0.5 + * + * @return SiteLinkConflictLookup + */ + public function getSiteLinkConflictLookup(); + } diff --git a/repo/includes/store/sql/SqlStore.php b/repo/includes/store/sql/SqlStore.php index eb59679..73b1b1d 100644 --- a/repo/includes/store/sql/SqlStore.php +++ b/repo/includes/store/sql/SqlStore.php @@ -22,6 +22,7 @@ use Wikibase\Lib\Store\RedirectResolvingEntityLookup; use Wikibase\Lib\Store\RevisionBasedEntityLookup; use Wikibase\Lib\Store\SiteLinkCache; +use Wikibase\Lib\Store\SiteLinkConflictLookup; use Wikibase\Lib\Store\SiteLinkTable; use Wikibase\Lib\Store\Sql\SqlEntityInfoBuilderFactory; use Wikibase\Lib\Store\WikiPageEntityMetaDataLookup; @@ -697,4 +698,11 @@ return $this->changesTable; } + /** + * @return SiteLinkConflictLookup + */ + public function getSiteLinkConflictLookup() { + return new SiteLinkTable( 'wb_items_per_site', false ); + } + } diff --git a/repo/tests/phpunit/includes/ChangeOp/ChangeOpFactoryProviderTest.php b/repo/tests/phpunit/includes/ChangeOp/ChangeOpFactoryProviderTest.php index 668f971..aef6bdb 100644 --- a/repo/tests/phpunit/includes/ChangeOp/ChangeOpFactoryProviderTest.php +++ b/repo/tests/phpunit/includes/ChangeOp/ChangeOpFactoryProviderTest.php @@ -42,7 +42,7 @@ $constraintProvider = new EntityConstraintProvider( $this->mockProvider->getMockLabelDescriptionDuplicateDetector(), - $this->mockProvider->getMockSitelinkCache() + $this->mockProvider->getMockSiteLinkConflictLookup() ); return new ChangeOpFactoryProvider( diff --git a/repo/tests/phpunit/includes/ChangeOp/ChangeOpTestMockProvider.php b/repo/tests/phpunit/includes/ChangeOp/ChangeOpTestMockProvider.php index b5f5eaf..b3f597b 100644 --- a/repo/tests/phpunit/includes/ChangeOp/ChangeOpTestMockProvider.php +++ b/repo/tests/phpunit/includes/ChangeOp/ChangeOpTestMockProvider.php @@ -434,9 +434,9 @@ /** * @param array $returnValue * - * @return SiteLinkCache + * @return SiteLinkConflictLookup */ - public function getMockSitelinkCache( $returnValue = null ) { + public function getMockSiteLinkConflictLookup( $returnValue = null ) { if ( is_array( $returnValue ) ) { $getConflictsForItem = function() use ( $returnValue ) { return $returnValue; @@ -445,7 +445,7 @@ $getConflictsForItem = array( $this, 'getSiteLinkConflictsForItem' ); } - $mock = $this->getMock( 'Wikibase\Lib\Store\SiteLinkCache' ); + $mock = $this->getMock( 'Wikibase\Lib\Store\SiteLinkConflictLookup' ); $mock->expects( PHPUnit_Framework_TestCase::any() ) ->method( 'getConflictsForItem' ) ->will( PHPUnit_Framework_TestCase::returnCallback( $getConflictsForItem ) ); diff --git a/repo/tests/phpunit/includes/Validators/EntityConstraintProviderTest.php b/repo/tests/phpunit/includes/Validators/EntityConstraintProviderTest.php index 38a20b5..75c3e38 100644 --- a/repo/tests/phpunit/includes/Validators/EntityConstraintProviderTest.php +++ b/repo/tests/phpunit/includes/Validators/EntityConstraintProviderTest.php @@ -22,9 +22,9 @@ ->disableOriginalConstructor() ->getMock(); - $siteLinkLookup = $this->getMock( 'Wikibase\Lib\Store\SiteLinkLookup' ); + $siteLinkConflictLookup = $this->getMock( 'Wikibase\Lib\Store\SiteLinkConflictLookup' ); - return new EntityConstraintProvider( $duplicateDetector, $siteLinkLookup ); + return new EntityConstraintProvider( $duplicateDetector, $siteLinkConflictLookup ); } public function testGetUpdateValidators() { diff --git a/repo/tests/phpunit/includes/Validators/SiteLinkUniquenessValidatorTest.php b/repo/tests/phpunit/includes/Validators/SiteLinkUniquenessValidatorTest.php index 0f9a8ea..82be62c 100644 --- a/repo/tests/phpunit/includes/Validators/SiteLinkUniquenessValidatorTest.php +++ b/repo/tests/phpunit/includes/Validators/SiteLinkUniquenessValidatorTest.php @@ -4,7 +4,7 @@ use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\ItemId; -use Wikibase\Lib\Store\SiteLinkLookup; +use Wikibase\Lib\Store\SiteLinkConflictLookup; use Wikibase\Test\ChangeOpTestMockProvider; use Wikibase\Validators\SiteLinkUniquenessValidator; @@ -22,20 +22,20 @@ class SiteLinkUniquenessValidatorTest extends \PHPUnit_Framework_TestCase { /** - * @return SiteLinkLookup + * @return SiteLinkConflictLookup */ - private function getMockSiteLinkLookup() { + private function getMockSiteLinkConflictLookup() { $mockProvider = new ChangeOpTestMockProvider( $this ); - return $mockProvider->getMockSitelinkCache(); + return $mockProvider->getMockSiteLinkConflictLookup(); } public function testValidateEntity() { $goodEntity = new Item( new ItemId( 'Q5' ) ); $goodEntity->getSiteLinkList()->addNewSiteLink( 'testwiki', 'Foo' ); - $siteLinkLookup = $this->getMockSiteLinkLookup(); + $siteLinkConflictLookup = $this->getMockSiteLinkConflictLookup(); - $validator = new SiteLinkUniquenessValidator( $siteLinkLookup ); + $validator = new SiteLinkUniquenessValidator( $siteLinkConflictLookup ); $result = $validator->validateEntity( $goodEntity ); @@ -46,9 +46,9 @@ $badEntity = new Item( new ItemId( 'Q7' ) ); $badEntity->getSiteLinkList()->addNewSiteLink( 'testwiki', 'DUPE' ); - $siteLinkLookup = $this->getMockSiteLinkLookup(); + $siteLinkConflictLookup = $this->getMockSiteLinkConflictLookup(); - $validator = new SiteLinkUniquenessValidator( $siteLinkLookup ); + $validator = new SiteLinkUniquenessValidator( $siteLinkConflictLookup ); $result = $validator->validateEntity( $badEntity ); diff --git a/repo/tests/phpunit/includes/Validators/TermValidatorFactoryTest.php b/repo/tests/phpunit/includes/Validators/TermValidatorFactoryTest.php index 832f532..5e6271b 100644 --- a/repo/tests/phpunit/includes/Validators/TermValidatorFactoryTest.php +++ b/repo/tests/phpunit/includes/Validators/TermValidatorFactoryTest.php @@ -35,7 +35,7 @@ $mockProvider = new ChangeOpTestMockProvider( $this ); $dupeDetector = $mockProvider->getMockLabelDescriptionDuplicateDetector(); - $siteLinkLookup = $mockProvider->getMockSitelinkCache(); + $siteLinkLookup = $this->getMock( 'Wikibase\Lib\Store\SiteLinkLookup' ); $builders = new TermValidatorFactory( $maxLength, $languages, $idParser, $dupeDetector, $siteLinkLookup ); return $builders; -- To view, visit https://gerrit.wikimedia.org/r/201916 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib4bc24ecfe4094c3ea08401682058bd63535f3f8 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Hoo man <h...@online.de> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Hoo man <h...@online.de> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits