[MediaWiki-commits] [Gerrit] mediawiki...WikibaseQualityConstraints[master]: Remove CONSTRAINT_TABLE constant
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/392457 ) Change subject: Remove CONSTRAINT_TABLE constant .. Remove CONSTRAINT_TABLE constant There was never any mechanism to vary the value of the constant, and it makes it harder to find code locations that access the database table directly, so let’s just inline the value in all those locations and then get rid of the constant. (This also makes the generic initialization callback unnecessary, so that’s removed as well.) Change-Id: I2628eb46def19800f6f2f8b0931239de7d226566 --- M WikibaseQualityConstraintsHooks.php M extension.json M includes/ConstraintRepository.php M tests/phpunit/ConstraintRepositoryTest.php M tests/phpunit/ConstraintTest.php M tests/phpunit/DelegatingConstraintCheckerTest.php M tests/phpunit/Job/UpdateConstraintsTableJobTest.php M tests/phpunit/Specials/SpecialConstraintReportTest.php 8 files changed, 28 insertions(+), 34 deletions(-) Approvals: jenkins-bot: Verified Thiemo Mättig (WMDE): Looks good to me, approved diff --git a/WikibaseQualityConstraintsHooks.php b/WikibaseQualityConstraintsHooks.php index 948e281..8bce16d 100644 --- a/WikibaseQualityConstraintsHooks.php +++ b/WikibaseQualityConstraintsHooks.php @@ -19,18 +19,13 @@ */ final class WikibaseQualityConstraintsHooks { - public static function onExtensionRegistration() { - // Define database table names - define( 'CONSTRAINT_TABLE', 'wbqc_constraints' ); - } - /** * @param DatabaseUpdater $updater * * @return bool */ public static function onCreateSchema( DatabaseUpdater $updater ) { - $updater->addExtensionTable( CONSTRAINT_TABLE, __DIR__ . '/sql/create_wbqc_constraints.sql' ); + $updater->addExtensionTable( 'wbqc_constraints', __DIR__ . '/sql/create_wbqc_constraints.sql' ); return true; } diff --git a/extension.json b/extension.json index d9ddb69..e4bba12 100644 --- a/extension.json +++ b/extension.json @@ -7,7 +7,6 @@ "version": "1.0.0", "license-name": "GPL-2.0+", "type": "wikibase", - "callback": "WikibaseQuality\\ConstraintReport\\WikibaseQualityConstraintsHooks::onExtensionRegistration", "MessagesDirs": { "WikibaseQualityConstraints": [ "i18n" diff --git a/includes/ConstraintRepository.php b/includes/ConstraintRepository.php index f06bcc6..4aac97a 100644 --- a/includes/ConstraintRepository.php +++ b/includes/ConstraintRepository.php @@ -24,7 +24,7 @@ $db = wfGetDB( DB_REPLICA ); $results = $db->select( - CONSTRAINT_TABLE, + 'wbqc_constraints', '*', [ 'pid' => $propertyId->getNumericId() ] ); @@ -62,7 +62,7 @@ ); $db = wfGetDB( DB_MASTER ); - return $db->insert( CONSTRAINT_TABLE, $accumulator ); + return $db->insert( 'wbqc_constraints', $accumulator ); } /** @@ -89,7 +89,7 @@ public function deleteWhereConstraintIdIsUuid() { $db = wfGetDB( DB_MASTER ); $db->delete( - CONSTRAINT_TABLE, + 'wbqc_constraints', // WHERE constraint_guid LIKE ---- 'constraint_guid ' . $db->buildLike( $this->uuidPattern( $db->anyChar() ) ) ); @@ -104,7 +104,7 @@ public function deleteForPropertyWhereConstraintIdIsStatementId( PropertyId $propertyId ) { $db = wfGetDB( DB_MASTER ); $db->delete( - CONSTRAINT_TABLE, + 'wbqc_constraints', [ 'pid' => $propertyId->getNumericId(), // AND constraint_guid LIKE %$---- @@ -125,12 +125,12 @@ } $db = wfGetDB( DB_MASTER ); if ( $db->getType() === 'sqlite' ) { - $db->delete( CONSTRAINT_TABLE, '*' ); + $db->delete( 'wbqc_constraints', '*' ); } else { do { $db->commit( __METHOD__, 'flush' ); wfGetLBFactory()->waitForReplication(); - $table = $db->tableName( CONSTRAINT_TABLE ); + $table = $db->tableName( 'wbqc_constraints' ); $db->query( sprintf( 'DELETE FROM %s LIMIT %d', $table, $batchSize ) ); } while ( $db->affectedRows() > 0 ); } diff --git a/tests/phpunit/ConstraintRepositoryTest.php
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseQualityConstraints[master]: Remove CONSTRAINT_TABLE constant
Lucas Werkmeister (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/392457 ) Change subject: Remove CONSTRAINT_TABLE constant .. Remove CONSTRAINT_TABLE constant There was never any mechanism to vary the value of the constant, and it makes it harder to find code locations that access the database table directly, so let’s just inline the value in all those locations and then get rid of the constant. (This also makes the generic initialization callback unnecessary, so that’s removed as well.) Change-Id: I2628eb46def19800f6f2f8b0931239de7d226566 --- M WikibaseQualityConstraintsHooks.php M extension.json M includes/ConstraintRepository.php M tests/phpunit/ConstraintRepositoryTest.php M tests/phpunit/ConstraintTest.php M tests/phpunit/DelegatingConstraintCheckerTest.php M tests/phpunit/Job/UpdateConstraintsTableJobTest.php M tests/phpunit/Specials/SpecialConstraintReportTest.php 8 files changed, 28 insertions(+), 34 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints refs/changes/57/392457/1 diff --git a/WikibaseQualityConstraintsHooks.php b/WikibaseQualityConstraintsHooks.php index 948e281..8bce16d 100644 --- a/WikibaseQualityConstraintsHooks.php +++ b/WikibaseQualityConstraintsHooks.php @@ -19,18 +19,13 @@ */ final class WikibaseQualityConstraintsHooks { - public static function onExtensionRegistration() { - // Define database table names - define( 'CONSTRAINT_TABLE', 'wbqc_constraints' ); - } - /** * @param DatabaseUpdater $updater * * @return bool */ public static function onCreateSchema( DatabaseUpdater $updater ) { - $updater->addExtensionTable( CONSTRAINT_TABLE, __DIR__ . '/sql/create_wbqc_constraints.sql' ); + $updater->addExtensionTable( 'wbqc_constraints', __DIR__ . '/sql/create_wbqc_constraints.sql' ); return true; } diff --git a/extension.json b/extension.json index d9ddb69..e4bba12 100644 --- a/extension.json +++ b/extension.json @@ -7,7 +7,6 @@ "version": "1.0.0", "license-name": "GPL-2.0+", "type": "wikibase", - "callback": "WikibaseQuality\\ConstraintReport\\WikibaseQualityConstraintsHooks::onExtensionRegistration", "MessagesDirs": { "WikibaseQualityConstraints": [ "i18n" diff --git a/includes/ConstraintRepository.php b/includes/ConstraintRepository.php index f06bcc6..4aac97a 100644 --- a/includes/ConstraintRepository.php +++ b/includes/ConstraintRepository.php @@ -24,7 +24,7 @@ $db = wfGetDB( DB_REPLICA ); $results = $db->select( - CONSTRAINT_TABLE, + 'wbqc_constraints', '*', [ 'pid' => $propertyId->getNumericId() ] ); @@ -62,7 +62,7 @@ ); $db = wfGetDB( DB_MASTER ); - return $db->insert( CONSTRAINT_TABLE, $accumulator ); + return $db->insert( 'wbqc_constraints', $accumulator ); } /** @@ -89,7 +89,7 @@ public function deleteWhereConstraintIdIsUuid() { $db = wfGetDB( DB_MASTER ); $db->delete( - CONSTRAINT_TABLE, + 'wbqc_constraints', // WHERE constraint_guid LIKE ---- 'constraint_guid ' . $db->buildLike( $this->uuidPattern( $db->anyChar() ) ) ); @@ -104,7 +104,7 @@ public function deleteForPropertyWhereConstraintIdIsStatementId( PropertyId $propertyId ) { $db = wfGetDB( DB_MASTER ); $db->delete( - CONSTRAINT_TABLE, + 'wbqc_constraints', [ 'pid' => $propertyId->getNumericId(), // AND constraint_guid LIKE %$---- @@ -125,12 +125,12 @@ } $db = wfGetDB( DB_MASTER ); if ( $db->getType() === 'sqlite' ) { - $db->delete( CONSTRAINT_TABLE, '*' ); + $db->delete( 'wbqc_constraints', '*' ); } else { do { $db->commit( __METHOD__, 'flush' ); wfGetLBFactory()->waitForReplication(); - $table = $db->tableName( CONSTRAINT_TABLE ); + $table = $db->tableName( 'wbqc_constraints' ); $db->query( sprintf( 'DELETE FROM %s LIMIT %d', $table, $batchSize ) ); } while ( $db->affectedRows() > 0 ); } diff --git