jenkins-bot has submitted this change and it was merged.
Change subject: modify CheckResultTranslator and save results in violationTable
......................................................................
modify CheckResultTranslator and save results in violationTable
also change Checkers (no toArray() anymore)
Change-Id: Ide8e569f72a0021e8e27e3d878f68728d800a36b
---
M constraint-report/includes/ConstraintCheck/Checker/ConnectionChecker.php
M constraint-report/includes/ConstraintCheck/Checker/RangeChecker.php
M constraint-report/includes/ConstraintCheck/Checker/TypeChecker.php
M constraint-report/includes/ConstraintCheck/Checker/ValueCountChecker.php
M
constraint-report/includes/ConstraintCheck/Result/CheckResultToViolationTranslator.php
M constraint-report/specials/SpecialConstraintReport.php
6 files changed, 33 insertions(+), 23 deletions(-)
Approvals:
Andreasburmeister: Checked; Looks good to me, approved
jenkins-bot: Verified
diff --git
a/constraint-report/includes/ConstraintCheck/Checker/ConnectionChecker.php
b/constraint-report/includes/ConstraintCheck/Checker/ConnectionChecker.php
index b90e8b2..e7ac729 100644
--- a/constraint-report/includes/ConstraintCheck/Checker/ConnectionChecker.php
+++ b/constraint-report/includes/ConstraintCheck/Checker/ConnectionChecker.php
@@ -22,7 +22,7 @@
/**
* List of all statements of given entity.
*
- * @var array
+ * @var StatementList
*/
private $statements;
@@ -46,7 +46,7 @@
* @param ConstraintReportHelper $helper
*/
public function __construct( StatementList $statements, EntityLookup
$lookup, ConstraintReportHelper $helper ) {
- $this->statements = $statements->toArray();
+ $this->statements = $statements;
$this->entityLookup = $lookup;
$this->helper = $helper;
}
@@ -187,7 +187,7 @@
$message = 'Target entity does not exist.';
return new CheckResult( $statement, 'Target required
claim', $parameters, 'violation', $message );
}
- $targetEntityStatementsArray =
$targetEntity->getStatements()->toArray();
+ $targetEntityStatementsArray = $targetEntity->getStatements();
/*
* 'Target required claim' can be defined with
@@ -243,7 +243,7 @@
$message = 'Target item does not exist.';
return new CheckResult( $statement, 'Symmetric',
$parameters, 'violation', $message );
}
- $targetItemStatementsArray =
$targetItem->getStatements()->toArray();
+ $targetItemStatementsArray = $targetItem->getStatements();
if ( $this->hasClaim( $targetItemStatementsArray,
$propertyId->getSerialization(), $entityIdSerialization ) ) {
$message = '';
diff --git
a/constraint-report/includes/ConstraintCheck/Checker/RangeChecker.php
b/constraint-report/includes/ConstraintCheck/Checker/RangeChecker.php
index a1aaaa2..56ccc04 100644
--- a/constraint-report/includes/ConstraintCheck/Checker/RangeChecker.php
+++ b/constraint-report/includes/ConstraintCheck/Checker/RangeChecker.php
@@ -21,7 +21,7 @@
/**
* List of all statements of given entity.
*
- * @var array
+ * @var StatementList
*/
private $statements;
@@ -37,7 +37,7 @@
* @param ConstraintReportHelper $helper
*/
public function __construct( StatementList $statements,
ConstraintReportHelper $helper ) {
- $this->statements = $statements->toArray();
+ $this->statements = $statements;
$this->helper = $helper;
}
diff --git a/constraint-report/includes/ConstraintCheck/Checker/TypeChecker.php
b/constraint-report/includes/ConstraintCheck/Checker/TypeChecker.php
index 4fb112c..be60f4b 100644
--- a/constraint-report/includes/ConstraintCheck/Checker/TypeChecker.php
+++ b/constraint-report/includes/ConstraintCheck/Checker/TypeChecker.php
@@ -26,7 +26,15 @@
*/
private $helper;
+ /**
+ * @var EntityLookup
+ */
private $entityLookup;
+
+ /**
+ * @var StatementList
+ */
+ private $statements;
const instanceId = 31;
const subclassId = 279;
@@ -38,7 +46,7 @@
* @param ConstraintReportHelper $helper
*/
public function __construct( StatementList $statements, EntityLookup
$lookup, ConstraintReportHelper $helper ) {
- $this->statements = $statements->toArray();
+ $this->statements = $statements;
$this->entityLookup = $lookup;
$this->helper = $helper;
}
diff --git
a/constraint-report/includes/ConstraintCheck/Checker/ValueCountChecker.php
b/constraint-report/includes/ConstraintCheck/Checker/ValueCountChecker.php
index e71ba2f..c931b5c 100644
--- a/constraint-report/includes/ConstraintCheck/Checker/ValueCountChecker.php
+++ b/constraint-report/includes/ConstraintCheck/Checker/ValueCountChecker.php
@@ -23,7 +23,7 @@
/**
* List of all statements of given entity.
*
- * @var array
+ * @var StatementList
*/
private $statements;
@@ -39,7 +39,7 @@
* @param ConstraintReportHelper $helper
*/
public function __construct( StatementList $statements,
ConstraintReportHelper $helper ) {
- $this->statements = $statements->toArray();
+ $this->statements = $statements;
$this->helper = $helper;
}
diff --git
a/constraint-report/includes/ConstraintCheck/Result/CheckResultToViolationTranslator.php
b/constraint-report/includes/ConstraintCheck/Result/CheckResultToViolationTranslator.php
index 3830490..4bdd4f9 100644
---
a/constraint-report/includes/ConstraintCheck/Result/CheckResultToViolationTranslator.php
+++
b/constraint-report/includes/ConstraintCheck/Result/CheckResultToViolationTranslator.php
@@ -4,14 +4,15 @@
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
-use Wikibase\Lib\ClaimGuidGenerator;
+use Wikibase\DataModel\Entity\Entity;
use WikidataQuality\Result\ResultToViolationTranslator;
use WikidataQuality\Violations\Violation;
class CheckResultToViolationTranslator extends ResultToViolationTranslator{
- public function translateToViolation( $checkResultOrArray ) {
+ public function translateToViolation( Entity $entity,
$checkResultOrArray ) {
+
if( $checkResultOrArray instanceof CheckResult ) {
$checkResultArray = array( $checkResultOrArray );
} else if( is_array( $checkResultOrArray ) ) {
@@ -26,18 +27,19 @@
continue;
}
- // TODO: Use these line when CheckResult has statement
- //$statement = $checkResult->getStatement();
- //$entityId = $statement->getClaim()->getEntityId();
- $entityId = new ItemId( 'Q90' );
- $statement = array();
- $statement[ 'pid' ] = new PropertyId( 'P1' );
- $statement[ 'claimGuid' ] = 'Q42';
+ $statement = $checkResult->getStatement();
+ $entityId = $entity->getId();
//TODO: Use real claimGuid
- $guidGenerator = new ClaimGuidGenerator();
- $constraintClaimGuid = $guidGenerator->newGuid(
$entityId );
$constraintTypeEntityId =
$checkResult->getConstraintName();
+ $constraintClaimGuid = $statement->getGuid() .
$constraintTypeEntityId;
+ $parameters = $checkResult->getParameters();
+ if( is_array( $parameters) ) {
+ foreach( $parameters as $par ) {
+ $constraintClaimGuid .= implode(', ',
$par );
+ }
+ }
+ $constraintClaimGuid = md5( $constraintClaimGuid );
$revisionId = $this->getRevisionIdForEntity( $entityId
);
$status = 'violation';
diff --git a/constraint-report/specials/SpecialConstraintReport.php
b/constraint-report/specials/SpecialConstraintReport.php
index 288ebee..eb89a83 100644
--- a/constraint-report/specials/SpecialConstraintReport.php
+++ b/constraint-report/specials/SpecialConstraintReport.php
@@ -100,7 +100,7 @@
$constraintChecker = new ConstraintChecker( $this->entityLookup
);
$results = $constraintChecker->execute( $entity );
- $this->saveResultsInViolationsTable( $results );
+ $this->saveResultsInViolationsTable( $entity, $results );
return $results;
}
@@ -291,9 +291,9 @@
/**
* @param array $results
*/
- protected function saveResultsInViolationsTable( $results ) {
+ protected function saveResultsInViolationsTable( $entity, $results ) {
$translator = new CheckResultToViolationTranslator();
- $violations = $translator->translateToViolation( $results );
+ $violations = $translator->translateToViolation( $entity,
$results );
$violationStore = new ViolationStore();
$violationStore->insertViolation( $violations );
}
--
To view, visit https://gerrit.wikimedia.org/r/204239
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ide8e569f72a0021e8e27e3d878f68728d800a36b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataQuality
Gerrit-Branch: master
Gerrit-Owner: Jonaskeutel <[email protected]>
Gerrit-Reviewer: Andreasburmeister <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits