Andreasburmeister has submitted this change and it was merged.

Change subject: change job so it should finally work
......................................................................


change job so it should finally work

only use scalars in params
use full namespace

Change-Id: I2cefe3504cafa65265c75c7bf30cde98fb6e494b
---
M WikibaseQualityConstraints.php
M composer.json
M includes/Constraint.php
M includes/ConstraintRepository.php
M includes/EvaluateConstraintReportJob.php
M includes/EvaluateConstraintReportJobService.php
M maintenance/UpdateTable.php
M specials/SpecialConstraintReport.php
M tests/phpunit/EvaluateConstraintReportJobServiceTest.php
9 files changed, 140 insertions(+), 135 deletions(-)

Approvals:
  Andreasburmeister: Verified; Looks good to me, approved



diff --git a/WikibaseQualityConstraints.php b/WikibaseQualityConstraints.php
index 8fff9a5..600fff3 100755
--- a/WikibaseQualityConstraints.php
+++ b/WikibaseQualityConstraints.php
@@ -40,6 +40,6 @@
        define( 'CONSTRAINT_TABLE', 'wbqc_constraints' );
 
        // Jobs
-       $GLOBALS['wgJobClasses']['evaluateConstraintReportJob'] = 
'EvaluateConstraintReportJob';
+       $GLOBALS['wgJobClasses']['evaluateConstraintReportJob'] = 
'WikidataQuality\ConstraintReport\EvaluateConstraintReportJob';
        $GLOBALS['wgDebugLogGroups']['wbq_evaluation'] = 
'/var/log/mediawiki/wbq_evaluation.log';
 } );
\ No newline at end of file
diff --git a/composer.json b/composer.json
old mode 100755
new mode 100644
diff --git a/includes/Constraint.php b/includes/Constraint.php
old mode 100755
new mode 100644
diff --git a/includes/ConstraintRepository.php 
b/includes/ConstraintRepository.php
old mode 100755
new mode 100644
diff --git a/includes/EvaluateConstraintReportJob.php 
b/includes/EvaluateConstraintReportJob.php
index 8480707..6931bd2 100755
--- a/includes/EvaluateConstraintReportJob.php
+++ b/includes/EvaluateConstraintReportJob.php
@@ -4,73 +4,68 @@
 
 use Job;
 use Title;
-use Wikibase\DataModel\Entity\EntityId;
 
 class EvaluateConstraintReportJob extends Job {
 
        private $service;
 
        /**
-        * @param EvaluateConstraintReportJobService $service
-        * @param EntityId $entityId
-        * @param $checkTimestamp
-        * @param $results
+        * @param string $entityId
+        * @param int $checkTimestamp
+        * @param string $results
         *
         * @return EvaluateConstraintReportJob
         * @throws \MWException
         */
-       public static function newInsertNow( EvaluateConstraintReportJobService 
$service, EntityId $entity, $checkTimestamp, $results ) {
+       public static function newInsertNow( $entityId, $checkTimestamp, 
$results ) {
                // The Job class wants a Title object for some reason. Supply a 
dummy.
                $dummyTitle = Title::newFromText( 
"EvaluateConstraintReportJob", NS_SPECIAL );
 
                $params = array ();
 
-               $params['entityId'] = $entity;
+               $params['entityId'] = $entityId;
                $params['results'] = $results;
                $params['checkTimestamp'] = $checkTimestamp;
-               $params['referenceTimestamp'] = null;
+               $params['referenceTimestamp'] = 'null';
 
-               return new EvaluateConstraintReportJob( $service, $dummyTitle, 
$params );
+               return new EvaluateConstraintReportJob( $dummyTitle, $params );
        }
 
        /**
-        * @param EvaluateConstraintReportJobService $service
-        * @param EntityId $entityId
-        * @param null $referenceTimestamp
+        * @param string $entityId
+        * @param int $referenceTimestamp
         * @param int $releaseTimestamp
         *
         * @return EvaluateConstraintReportJob
         * @throws \MWException
         */
-       public static function newInsertDeferred( 
EvaluateConstraintReportJobService $service, EntityId $entity, 
$referenceTimestamp = null, $releaseTimestamp = 0 ) {
+       public static function newInsertDeferred( $entityId, 
$referenceTimestamp = 'null', $releaseTimestamp = 0 ) {
                // The Job class wants a Title object for some reason. Supply a 
dummy.
                $dummyTitle = Title::newFromText( 
"EvaluateConstraintReportJob", NS_SPECIAL );
 
                $params = array ();
 
-               $params['entityId'] = $entity;
-               $params['results'] = null;
+               $params['entityId'] = $entityId;
                $params['referenceTimestamp'] = $referenceTimestamp;
                $params['releaseTimestamp'] = wfTimestamp( TS_MW ) + 
$releaseTimestamp;
 
-               return new EvaluateConstraintReportJob( $service, $dummyTitle, 
$params );
+               return new EvaluateConstraintReportJob( $dummyTitle, $params );
        }
 
        /**
-        * @param EvaluateConstraintReportJobService $service
         * @param Title $title
         * @param array|bool $params
         */
-       public function __construct( EvaluateConstraintReportJobService 
$service, Title $title, $params ) {
-               parent::__construct( 'checkForConstraintViolations', $title, 
$params );
-               $this->service = $service;
+       public function __construct( Title $title, $params ) {
+               parent::__construct( 'evaluateConstraintReportJob', $title, 
$params );
+               $this->service = new EvaluateConstraintReportJobService();
        }
 
        public function run() {
                $checkTimestamp = array_key_exists( 'checkTimestamp', 
$this->params ) ? $this->params[ 'checkTimestamp' ] : wfTimestamp( TS_MW );
 
-               $results = $this->service->getResults( $this->params );
-               $messageToLog = $this->service->buildMessageForLog( $results, 
$checkTimestamp, $this->params );
+               $resultSummary = $this->service->getResults( $this->params );
+               $messageToLog = $this->service->buildMessageForLog( 
$resultSummary, $checkTimestamp, $this->params );
                $this->service->writeToLog( $messageToLog );
 
        }
diff --git a/includes/EvaluateConstraintReportJobService.php 
b/includes/EvaluateConstraintReportJobService.php
old mode 100755
new mode 100644
index d1ac9b3..2ebc71f
--- a/includes/EvaluateConstraintReportJobService.php
+++ b/includes/EvaluateConstraintReportJobService.php
@@ -2,32 +2,31 @@
 
 namespace WikibaseQuality\ConstraintReport;
 
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Entity\PropertyId;
 use Wikibase\Repo\WikibaseRepo;
 use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult;
-use 
WikibaseQuality\ConstraintReport\ConstraintCheck\DelegatingConstraintChecker;
-use WikibaseQuality\ConstraintReport\ConstraintCheck\CheckerMapBuilder;
-use 
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintReportHelper;
 
 
 class EvaluateConstraintReportJobService {
 
        public function writeToLog( $message ) {
-               wfDebugLog( 'wdqa_evaluation', $message );
+               wfDebugLog( 'wbq_evaluation', $message );
        }
 
-       public function buildMessageForLog( $results, $timestamp, $params ) {
+       public function buildMessageForLog( $resultSummary, $timestamp, $params 
) {
                return json_encode(
                        array (
                                'special_page_id' => 'SpecialConstraintReport',
-                               'entity_id' => 
$params['entityId']->getSerialization(),
+                               'entity_id' => $params['entityId'],
                                'insertion_timestamp' => $timestamp,
                                'reference_timestamp' => 
$params['referenceTimestamp'],
-                               'result_summary' => $this->buildResultSummary( 
$results )
+                               'result_summary' => $resultSummary
                        )
                );
        }
 
-       private function buildResultSummary( $results ) {
+       public function buildResultSummary( $results ) {
                $summary = array();
 
                foreach ( $results as $result ) {
@@ -37,7 +36,8 @@
                                $summary[$constraintName] = array(
                                        CheckResult::STATUS_COMPLIANCE => 0,
                                        CheckResult::STATUS_VIOLATION => 0,
-                                       CheckResult::STATUS_EXCEPTION => 0
+                                       CheckResult::STATUS_EXCEPTION => 0,
+                                       CheckResult::STATUS_TODO => 0
                                );
                        }
                        if( array_key_exists( $status, 
$summary[$constraintName] ) ) {
@@ -45,16 +45,16 @@
                        }
                }
 
-               return $summary;
+               return json_encode( $summary );
        }
 
        public function getResults( $params ) {
-               if ( $params[ 'results' ] === null ) {
+               if ( !array_key_exists( 'results', $params ) ) {
                        $lookup = 
WikibaseRepo::getDefaultInstance()->getEntityLookup();
-                       $checkerMap = new CheckerMapBuilder( $lookup, new 
ConstraintReportHelper() );
-                       $constraintChecker = new DelegatingConstraintChecker( 
$lookup, $checkerMap->getCheckerMap() );
-
-                       return $constraintChecker->checkAgainstConstraints( 
$lookup->getEntity( $params[ 'entityId' ] ) );
+                       $constraintChecker = 
ConstraintReportFactory::getDefaultInstance()->getConstraintChecker();
+                       $entityId = $params['entityId'][0] === 'Q' ? new 
ItemId( $params['entityId'] ) : new PropertyId( $params['entityId'] );
+                       $results = $constraintChecker->checkAgainstConstraints( 
$lookup->getEntity( $entityId ) );
+                       return $this->buildResultSummary( $results );
                } else {
                        return $params['results'];
                }
diff --git a/maintenance/UpdateTable.php b/maintenance/UpdateTable.php
old mode 100755
new mode 100644
index 9127917..a016025
--- a/maintenance/UpdateTable.php
+++ b/maintenance/UpdateTable.php
@@ -52,6 +52,6 @@
 }
 
 // @codeCoverageIgnoreStart
-$maintClass = 'WikidataQuality\ConstraintReport\Maintenance\UpdateTable';
+$maintClass = 'WikibaseQuality\ConstraintReport\Maintenance\UpdateTable';
 require_once RUN_MAINTENANCE_IF_MAIN;
 // @codeCoverageIgnoreEnd
\ No newline at end of file
diff --git a/specials/SpecialConstraintReport.php 
b/specials/SpecialConstraintReport.php
index 11fb689..244e393 100755
--- a/specials/SpecialConstraintReport.php
+++ b/specials/SpecialConstraintReport.php
@@ -344,7 +344,9 @@
                $constraintChecker = 
ConstraintReportFactory::getDefaultInstance()->getConstraintChecker();
                $results = $constraintChecker->checkAgainstConstraints( $entity 
);
 
-               $this->doEvaluation( $entity, $results );
+               if ( !defined( 'MW_PHPUNIT_TEST' ) ){
+                       $this->doEvaluation( $entity, $results );
+               }
                return $results;
        }
 
@@ -740,12 +742,12 @@
        }
 
        protected function doEvaluation( $entity, $results ) {
-               $service = new EvaluateConstraintReportJobService();
                $checkTimeStamp = wfTimestamp( TS_MW );
+               $service = new EvaluateConstraintReportJobService();
+               $results = $service->buildResultSummary( $results );
                $jobs = array ();
-               $jobs[] = EvaluateConstraintReportJob::newInsertNow( $service, 
$entity->getId(), $checkTimeStamp, $results );
-               $jobs[] = EvaluateConstraintReportJob::newInsertDeferred( 
$service, $entity->getId(), $checkTimeStamp, 10 );
-               $jobs[0]->run();
+               $jobs[] = EvaluateConstraintReportJob::newInsertNow( 
$entity->getId()->getSerialization(), $checkTimeStamp, $results );
+               $jobs[] = EvaluateConstraintReportJob::newInsertDeferred( 
$entity->getId()->getSerialization(), $checkTimeStamp, 10 );
                JobQueueGroup::singleton()->push( $jobs );
        }
 
diff --git a/tests/phpunit/EvaluateConstraintReportJobServiceTest.php 
b/tests/phpunit/EvaluateConstraintReportJobServiceTest.php
old mode 100755
new mode 100644
index 96fff10..cdc82e0
--- a/tests/phpunit/EvaluateConstraintReportJobServiceTest.php
+++ b/tests/phpunit/EvaluateConstraintReportJobServiceTest.php
@@ -1,91 +1,99 @@
-<?php
-
-namespace WikibaseQuality\ConstraintReport\Tests;
-
-use Wikibase\DataModel\Statement\Statement;
-use Wikibase\DataModel\Claim\Claim;
-use Wikibase\DataModel\Snak\PropertyValueSnak;
-use Wikibase\DataModel\Entity\PropertyId;
-use Wikibase\DataModel\Entity\ItemId;
-use DataValues\StringValue;
-use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult;
-use WikibaseQuality\ConstraintReport\EvaluateConstraintReportJobService;
-
-
-/**
- * @covers WikibaseQuality\ConstraintReport\EvaluateConstraintReportJobService
- *
- * @uses   WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult
- * @uses   
WikibaseQuality\ConstraintReport\ConstraintCheck\DelegatingConstraintChecker
- *
- * @author BP2014N1
- * @license GNU GPL v2+
- */
-class EvaluateConstraintReportJobServiceTest extends \MediaWikiTestCase {
-
-       private $entityId;
-       private $checkTimestamp;
-       private $constraintName;
-       private $results;
-       private $params;
-
-       protected function setUp() {
-               parent::setUp();
-
-               $this->entityId = new ItemId( 'Q23' );
-
-               $this->checkTimestamp = wfTimestamp( TS_MW );
-
-               $statement = new Statement( new Claim( new PropertyValueSnak( 
new PropertyId( 'P1337' ), new StringValue( 'f00b4r' ) ) ) );
-               $this->constraintName = 'Single value';
-
-               $results = array ();
-               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), CheckResult::STATUS_COMPLIANCE );
-               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), CheckResult::STATUS_COMPLIANCE );
-               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), CheckResult::STATUS_COMPLIANCE );
-               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), CheckResult::STATUS_EXCEPTION );
-               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), CheckResult::STATUS_VIOLATION );
-               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), CheckResult::STATUS_VIOLATION );
-               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), 'some other status' );
-               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), 'yet another one' );
-               $this->results = $results;
-
-               $this->params = array( 'entityId' => $this->entityId, 
'referenceTimestamp' => null, 'results' => $results );
-
-       }
-
-       protected function tearDown() {
-
-               unset( $this->results );
-               unset( $this->constraintName );
-               unset( $this->checkTimestamp );
-               unset( $this->entityId );
-               unset( $this->params );
-
-               parent::tearDown();
-       }
-
-       public function testBuildMessageForLog() {
-               $service = new EvaluateConstraintReportJobService();
-               $messageToLog = (array) json_decode( 
$service->buildMessageForLog( $this->results, $this->checkTimestamp, 
$this->params ) );
-
-               $this->assertEquals( 5, count( $messageToLog ) );
-               $this->assertEquals( 'SpecialConstraintReport', 
$messageToLog['special_page_id'] );
-               $this->assertEquals( $this->entityId->getSerialization(), 
$messageToLog['entity_id'] );
-               $this->assertEquals( $this->checkTimestamp, 
$messageToLog['insertion_timestamp'] );
-               $this->assertEquals( null, $messageToLog['reference_timestamp'] 
);
-
-               $resultSummary = (array) $messageToLog['result_summary'];
-               $this->assertEquals( 1, count( $resultSummary ) );
-
-               $resultForConstraint = (array) 
$resultSummary[$this->constraintName];
-               $this->assertEquals( 3, count( $resultForConstraint ) );
-               $this->assertEquals( 3, 
$resultForConstraint[CheckResult::STATUS_COMPLIANCE] );
-       }
-
-       public function testGetResults() {
-               $service = new EvaluateConstraintReportJobService();
-               $this->assertEquals( $this->results, $service->getResults( 
$this->params ) );
-       }
-
-}
+<?php
+
+namespace WikibaseQuality\ConstraintReport\Tests;
+
+use Wikibase\DataModel\Statement\Statement;
+use Wikibase\DataModel\Claim\Claim;
+use Wikibase\DataModel\Snak\PropertyValueSnak;
+use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\DataModel\Entity\ItemId;
+use DataValues\StringValue;
+use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult;
+use WikibaseQuality\ConstraintReport\EvaluateConstraintReportJobService;
+
+
+/**
+ * @covers WikibaseQuality\ConstraintReport\EvaluateConstraintReportJobService
+ *
+ * @uses   WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult
+ * @uses   
WikibaseQuality\ConstraintReport\ConstraintCheck\DelegatingConstraintChecker
+ *
+ * @author BP2014N1
+ * @license GNU GPL v2+
+ */
+class EvaluateConstraintReportJobServiceTest extends \MediaWikiTestCase {
+
+       private $entityId;
+       private $checkTimestamp;
+       private $constraintName;
+       private $results;
+       private $params;
+
+       protected function setUp() {
+               parent::setUp();
+
+               $this->entityId = new ItemId( 'Q23' );
+
+               $this->checkTimestamp = wfTimestamp( TS_MW );
+
+               $statement = new Statement( new Claim( new PropertyValueSnak( 
new PropertyId( 'P1337' ), new StringValue( 'f00b4r' ) ) ) );
+               $this->constraintName = 'Single value';
+
+               $results = array ();
+               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), CheckResult::STATUS_COMPLIANCE );
+               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), CheckResult::STATUS_COMPLIANCE );
+               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), CheckResult::STATUS_COMPLIANCE );
+               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), CheckResult::STATUS_EXCEPTION );
+               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), CheckResult::STATUS_VIOLATION );
+               $results[] = new CheckResult( $statement, 
$this->constraintName, array (), CheckResult::STATUS_VIOLATION );
+               $results[] = new CheckResult( $statement, 
$this->constraintName, array () );
+               $results[] = new CheckResult( $statement, 
$this->constraintName, array () );
+               $this->results = $results;
+
+               $this->params = array( 'entityId' => 
$this->entityId->getSerialization(), 'referenceTimestamp' => null, 'results' => 
$results );
+
+       }
+
+       protected function tearDown() {
+
+               unset( $this->results );
+               unset( $this->constraintName );
+               unset( $this->checkTimestamp );
+               unset( $this->entityId );
+               unset( $this->params );
+
+               parent::tearDown();
+       }
+#
+       public function testBuildResultSummary() {
+               $service = new EvaluateConstraintReportJobService();
+               $this->assertEquals( '{"Single 
value":{"compliance":3,"violation":2,"exception":1,"todo":2}}', 
$service->buildResultSummary( $this->results ) );
+       }
+
+       public function testBuildMessageForLog() {
+               $service = new EvaluateConstraintReportJobService();
+               $messageToLog = (array) json_decode( 
$service->buildMessageForLog( '{"Single 
value":{"compliance":3,"violation":2,"exception":1,"todo":2}}', 
$this->checkTimestamp, $this->params ) );
+
+               $this->assertEquals( 5, count( $messageToLog ) );
+               $this->assertEquals( 'SpecialConstraintReport', 
$messageToLog['special_page_id'] );
+               $this->assertEquals( $this->entityId->getSerialization(), 
$messageToLog['entity_id'] );
+               $this->assertEquals( $this->checkTimestamp, 
$messageToLog['insertion_timestamp'] );
+               $this->assertEquals( null, $messageToLog['reference_timestamp'] 
);
+
+               $resultSummary = (array) json_decode( 
$messageToLog['result_summary'] );
+
+               $this->assertEquals( 1, count( $resultSummary ) );
+               $resultForConstraint = (array) 
$resultSummary[$this->constraintName];
+               $this->assertEquals( 4, count( $resultForConstraint ) );
+               $this->assertEquals( 3, 
$resultForConstraint[CheckResult::STATUS_COMPLIANCE], 'Compliance' );
+               $this->assertEquals( 1, 
$resultForConstraint[CheckResult::STATUS_EXCEPTION], 'Exception' );
+               $this->assertEquals( 2, 
$resultForConstraint[CheckResult::STATUS_VIOLATION], 'Violation' );
+               $this->assertEquals( 2, 
$resultForConstraint[CheckResult::STATUS_TODO], 'Todo' );
+       }
+
+       public function testGetResults() {
+               $service = new EvaluateConstraintReportJobService();
+               $this->assertEquals( $this->results, $service->getResults( 
$this->params ) );
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/211703
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2cefe3504cafa65265c75c7bf30cde98fb6e494b
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/WikidataQualityConstraints
Gerrit-Branch: v1
Gerrit-Owner: Jonaskeutel <jonas.keu...@student.hpi.de>
Gerrit-Reviewer: Andreasburmeister <andreas.burmeis...@student.hpi.de>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to