Lucas Werkmeister (WMDE) has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/403641 )
Change subject: Ignore deprecated constraints
......................................................................
Ignore deprecated constraints
If a constraint statement is deprecated, don’t import the constraint
into the database at all. This provides editors with an easy way to
temporarily disable a constraint without removing it from the property.
Bug: T180874
Change-Id: I9a5bc78e5b204d7ff07ab4518c0fc80abf801ba7
---
M src/UpdateConstraintsTableJob.php
M tests/phpunit/Job/UpdateConstraintsTableJobTest.php
2 files changed, 64 insertions(+), 1 deletion(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
refs/changes/41/403641/1
diff --git a/src/UpdateConstraintsTableJob.php
b/src/UpdateConstraintsTableJob.php
index 2bde8ba..9b72cbf 100644
--- a/src/UpdateConstraintsTableJob.php
+++ b/src/UpdateConstraintsTableJob.php
@@ -122,7 +122,9 @@
ConstraintRepository $constraintRepo,
PropertyId $propertyConstraintPropertyId
) {
- $constraintsStatements =
$property->getStatements()->getByPropertyId( $propertyConstraintPropertyId );
+ $constraintsStatements = $property->getStatements()
+ ->getByPropertyId( $propertyConstraintPropertyId )
+ ->getByRank( [ Statement::RANK_PREFERRED,
Statement::RANK_NORMAL ] );
$constraints = [];
foreach ( $constraintsStatements->getIterator() as
$constraintStatement ) {
$constraints[] = $this->extractConstraintFromStatement(
$property->getId(), $constraintStatement );
diff --git a/tests/phpunit/Job/UpdateConstraintsTableJobTest.php
b/tests/phpunit/Job/UpdateConstraintsTableJobTest.php
index eeee85a..a13b551 100644
--- a/tests/phpunit/Job/UpdateConstraintsTableJobTest.php
+++ b/tests/phpunit/Job/UpdateConstraintsTableJobTest.php
@@ -10,12 +10,14 @@
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\Property;
use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\DataModel\Services\Lookup\InMemoryEntityLookup;
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
use Wikibase\DataModel\Snak\PropertySomeValueSnak;
use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\DataModel\Snak\SnakList;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\Statement\StatementList;
+use Wikibase\Repo\Tests\NewStatement;
use WikibaseQuality\ConstraintReport\ConstraintRepository;
use WikibaseQuality\ConstraintReport\Tests\DefaultConfig;
use WikibaseQuality\ConstraintReport\UpdateConstraintsTableJob;
@@ -250,6 +252,65 @@
);
}
+ public function testImportConstraintsForProperty_Deprecated() {
+ $config = $this->getDefaultConfig();
+ $propertyConstraintId = $config->get(
'WBQualityConstraintsPropertyConstraintId' );
+ $usedForValuesOnlyId = $config->get(
'WBQualityConstraintsUsedForValuesOnlyConstraintId' );
+ $usedAsQualifierId = $config->get(
'WBQualityConstraintsUsedAsQualifierConstraintId' );
+ $usedAsReferenceId = $config->get(
'WBQualityConstraintsUsedAsReferenceConstraintId' );
+ $preferredConstraintStatement = NewStatement::forProperty(
$propertyConstraintId )
+ ->withValue( new ItemId( $usedForValuesOnlyId ) )
+ ->withPreferredRank()
+ ->build();
+ $normalConstraintStatement = NewStatement::forProperty(
$propertyConstraintId )
+ ->withValue( new ItemId( $usedAsQualifierId ) )
+ ->withNormalRank()
+ ->build();
+ $deprecatedConstraintStatement = NewStatement::forProperty(
$propertyConstraintId )
+ ->withValue( new ItemId( $usedAsReferenceId ) )
+ ->withDeprecatedRank()
+ ->build();
+ $property = new Property(
+ new PropertyId( 'P3' ),
+ null,
+ 'string',
+ new StatementList( [
+ $preferredConstraintStatement,
+ $normalConstraintStatement,
+ $deprecatedConstraintStatement
+ ] )
+ );
+ $entityLookup = new InMemoryEntityLookup();
+ $entityLookup->addEntity( $property );
+
+ $constraintRepository = $this->getMock(
ConstraintRepository::class );
+ $constraintRepository->expects( $this->once() )
+ ->method( 'insertBatch' )
+ ->with( $this->callback(
+ function( array $constraints ) use (
$usedForValuesOnlyId, $usedAsQualifierId ) {
+ $this->assertCount( 2, $constraints );
+ $this->assertSame(
$usedForValuesOnlyId, $constraints[0]->getConstraintTypeItemId() );
+ $this->assertSame( $usedAsQualifierId,
$constraints[1]->getConstraintTypeItemId() );
+ return true;
+ }
+ ) );
+
+ $job = new UpdateConstraintsTableJob(
+ Title::newFromText( 'constraintsTableUpdate' ),
+ [],
+ 'P3',
+ $config,
+ $constraintRepository,
+ $entityLookup,
+
WikibaseRepo::getDefaultInstance()->getBaseDataModelSerializerFactory()->newSnakSerializer()
+ );
+ $job->importConstraintsForProperty(
+ $property,
+ $constraintRepository,
+ new PropertyId( $propertyConstraintId )
+ );
+ }
+
public function testRun() {
$job = new UpdateConstraintsTableJob(
Title::newFromText( 'constraintsTableUpdate' ),
--
To view, visit https://gerrit.wikimedia.org/r/403641
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9a5bc78e5b204d7ff07ab4518c0fc80abf801ba7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits