Aude has uploaded a new change for review. https://gerrit.wikimedia.org/r/202378
Change subject: Inject idBlacklist setting into SqlIdGenerator ...................................................................... Inject idBlacklist setting into SqlIdGenerator Change-Id: I31cbe617ab85cc7820dd7e87d2e5433a51af92c4 --- M repo/includes/store/sql/SqlIdGenerator.php M repo/includes/store/sql/SqlStore.php M repo/tests/phpunit/includes/store/sql/SqlIdGeneratorTest.php M repo/tests/phpunit/includes/store/sql/WikiPageEntityStoreTest.php 4 files changed, 22 insertions(+), 25 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/78/202378/1 diff --git a/repo/includes/store/sql/SqlIdGenerator.php b/repo/includes/store/sql/SqlIdGenerator.php index 4729159..62c5e19 100644 --- a/repo/includes/store/sql/SqlIdGenerator.php +++ b/repo/includes/store/sql/SqlIdGenerator.php @@ -28,19 +28,12 @@ private $db; /** - * @var int[] - */ - private $idBlacklist; - - /** * @param string $tableName * @param DatabaseBase $database - * @param int[] $idBlacklist */ - public function __construct( $tableName, DatabaseBase $database, array $idBlacklist ) { + public function __construct( $tableName, DatabaseBase $database ) { $this->table = $tableName; $this->db = $database; - $this->idBlacklist = $idBlacklist; } /** @@ -115,7 +108,10 @@ throw new MWException( 'Could not generate a reliably unique ID.' ); } - if ( in_array( $id, $this->idBlacklist ) ) { + $idBlacklist = WikibaseRepo::getDefaultInstance()-> + getSettings()->getSetting( 'idBlacklist' ); + + if ( in_array( $id, $idBlacklist ) ) { $id = $this->generateNewId( $type ); } diff --git a/repo/includes/store/sql/SqlStore.php b/repo/includes/store/sql/SqlStore.php index eb59679..262a224 100644 --- a/repo/includes/store/sql/SqlStore.php +++ b/repo/includes/store/sql/SqlStore.php @@ -119,11 +119,6 @@ private $useRedirectTargetColumn; /** - * @var int[] - */ - private $idBlacklist; - - /** * @param EntityContentDataCodec $contentCodec * @param EntityIdParser $entityIdParser */ @@ -141,7 +136,6 @@ $this->cacheType = $settings->getSetting( 'sharedCacheType' ); $this->cacheDuration = $settings->getSetting( 'sharedCacheDuration' ); $this->useRedirectTargetColumn = $settings->getSetting( 'useRedirectTargetColumn' ); - $this->idBlacklist = $settings->getSetting( 'idBlacklist' ); } /** @@ -464,7 +458,7 @@ * @return IdGenerator */ public function newIdGenerator() { - return new SqlIdGenerator( 'wb_id_counters', wfGetDB( DB_MASTER ), $this->idBlacklist ); + return new SqlIdGenerator( 'wb_id_counters', wfGetDB( DB_MASTER ) ); } /** diff --git a/repo/tests/phpunit/includes/store/sql/SqlIdGeneratorTest.php b/repo/tests/phpunit/includes/store/sql/SqlIdGeneratorTest.php index f44b40a..5d1605b 100644 --- a/repo/tests/phpunit/includes/store/sql/SqlIdGeneratorTest.php +++ b/repo/tests/phpunit/includes/store/sql/SqlIdGeneratorTest.php @@ -2,7 +2,8 @@ namespace Wikibase\Test; -use Wikibase\SqlIdGenerator; +use Wikibase\IdGenerator; +use Wikibase\Repo\WikibaseRepo; /** * @covers Wikibase\SqlIdGenerator @@ -15,22 +16,28 @@ * @group medium * * @licence GNU GPL v2+ - * @author Katie Filbert < aude.w...@gmail.com > + * @author Jeroen De Dauw < jeroended...@gmail.com > */ class SqlIdGeneratorTest extends \MediaWikiTestCase { public function testGetNewId() { - $generator = new SqlIdGenerator( 'wb_id_counters', wfGetDB( DB_MASTER ), array() ); + $generator = WikibaseRepo::getDefaultInstance()->getStore()->newIdGenerator(); - $id = $generator->getNewId( 'wikibase-kittens' ); - $this->assertEquals( 1, $id ); + $idType = 'wikibase-kittens'; + $id = $generator->getNewId( $idType ); + + // 1 is in the blacklist, so count starts with 2 + $this->assertEquals( 2, $id ); } public function testIdBlacklisting() { - $generator = new SqlIdGenerator( 'wb_id_counters', wfGetDB( DB_MASTER ), array( 1, 2 ) ); + $generator = WikibaseRepo::getDefaultInstance()->getStore()->newIdGenerator(); + $idBlacklist = WikibaseRepo::getDefaultInstance()-> + getSettings()->getSetting( 'idBlacklist' ); - $id = $generator->getNewId( 'wikibase-blacklist' ); - $this->assertEquals( 3, $id ); + for ( $i = 0; $i < 45; ++$i ) { + $this->assertFalse( in_array( $generator->getNewId( 'blacklisttest' ), $idBlacklist ) ); + } } } diff --git a/repo/tests/phpunit/includes/store/sql/WikiPageEntityStoreTest.php b/repo/tests/phpunit/includes/store/sql/WikiPageEntityStoreTest.php index dc9d088..2f9539d 100644 --- a/repo/tests/phpunit/includes/store/sql/WikiPageEntityStoreTest.php +++ b/repo/tests/phpunit/includes/store/sql/WikiPageEntityStoreTest.php @@ -70,7 +70,7 @@ $store = new WikiPageEntityStore( new EntityContentFactory( $typeMap ), - new SqlIdGenerator( 'wb_id_counters', wfGetDB( DB_MASTER ), array() ) + new SqlIdGenerator( 'wb_id_counters', wfGetDB( DB_MASTER ) ) ); return array( $store, $lookup ); -- To view, visit https://gerrit.wikimedia.org/r/202378 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I31cbe617ab85cc7820dd7e87d2e5433a51af92c4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aude <aude.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits