Andreasburmeister has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/209197

Change subject: allow different logging methods for the eval job
......................................................................

allow different logging methods for the eval job

also fixed issue with formatting of values on special page

Change-Id: I498110c84b557f7c4edc7349156d13e29e00b36a
---
M includes/CheckForConstraintViolationsJob.php
M specials/SpecialConstraintReport.php
M tests/phpunit/CheckForConstraintViolationsJobTest.php
M tests/phpunit/Specials/SpecialConstraintReportTest.php
4 files changed, 34 insertions(+), 50 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataQualityConstraints
 refs/changes/97/209197/1

diff --git a/includes/CheckForConstraintViolationsJob.php 
b/includes/CheckForConstraintViolationsJob.php
index 19fbf1f..2464101 100644
--- a/includes/CheckForConstraintViolationsJob.php
+++ b/includes/CheckForConstraintViolationsJob.php
@@ -14,6 +14,26 @@
 
 class CheckForConstraintViolationsJob extends Job {
 
+       private $defaultLoggingMethod;
+
+       private $loggingMethod;
+
+       public function setLoggingMethod( $class, $loggingMethod ) {
+               $this->loggingMethod = array( $class, $loggingMethod );
+       }
+
+       public function resetLoggingMethod( ) {
+               $this->loggingMethod = $this->defaultLoggingMethod;
+       }
+
+       private function defaultLoggingMethod( $logEntry ) {
+               wfDebugLog( 'wdqa_evaluation', $logEntry );
+       }
+
+       private function writeLog( $logEntry ) {
+               call_user_func( $this->loggingMethod, $logEntry );
+       }
+
        public static function newInsertNow( Entity $entity, $checkTimestamp, 
$results ) {
                // The Job class wants a Title object for some reason. Supply a 
dummy.
                $dummyTitle = Title::newFromText( 
"CheckForConstraintViolationsJob", NS_SPECIAL );
@@ -44,6 +64,9 @@
 
        public function __construct( Title $title, $params ) {
                parent::__construct( 'checkForConstraintViolations', $title, 
$params );
+
+               $this->defaultLoggingMethod = array( $this, 
'defaultLoggingMethod' );
+               $this->loggingMethod = $this->defaultLoggingMethod;
        }
 
        public function run() {
@@ -67,7 +90,7 @@
                        'result_summary' => $this->buildResultSummary( $results 
)
                );
 
-               wfDebugLog( 'wdqa_evaluation', json_encode( $accumulator ) );
+               $this->writeLog( json_encode( $accumulator ) );
        }
 
        private function buildResultSummary( $results ) {
diff --git a/specials/SpecialConstraintReport.php 
b/specials/SpecialConstraintReport.php
index 1c81115..2e59c50 100755
--- a/specials/SpecialConstraintReport.php
+++ b/specials/SpecialConstraintReport.php
@@ -146,7 +146,7 @@
 
                        // Claim column
                        $property = 
$this->entityIdHtmlLinkFormatter->formatEntityId( $result->getPropertyId() );
-                       if ( $result->getMainSnakType() !== 'value' ) {
+                       if ( $result->getMainSnakType() === 'value' ) {
                                $value = $this->formatValue( 
$result->getDataValue() );
                        } else {
                                $value = $result->getMainSnakType();
@@ -299,14 +299,11 @@
        }
 
        protected function doEvaluation( $entity, $results ) {
-               //TODO: Push (deferred) job(s) in queue
                $checkTimeStamp = wfTimestamp( TS_MW );
                $jobs = array ();
                $jobs[ ] = CheckForConstraintViolationsJob::newInsertNow( 
$entity, $checkTimeStamp, $results );
                $jobs[ ] = CheckForConstraintViolationsJob::newInsertDeferred( 
$entity, $checkTimeStamp, 10 );
 
-               $jobs[ 0 ]->run();
-               $jobs[ 1 ]->run();
                JobQueueGroup::singleton()->push( $jobs );
        }
 
diff --git a/tests/phpunit/CheckForConstraintViolationsJobTest.php 
b/tests/phpunit/CheckForConstraintViolationsJobTest.php
index 3d659bd..b261b0e 100644
--- a/tests/phpunit/CheckForConstraintViolationsJobTest.php
+++ b/tests/phpunit/CheckForConstraintViolationsJobTest.php
@@ -30,8 +30,7 @@
        private $checkTimestamp;
        private $constraintName;
        private $results;
-       private $testLogFileName;
-       private $oldLogFileName;
+       private $logEntry;
 
        protected function setUp() {
                parent::setUp();
@@ -54,25 +53,10 @@
                $results[] = new CheckResult( $statement, 
$this->constraintName, array (), 'some other status' );
                $results[] = new CheckResult( $statement, 
$this->constraintName, array (), 'yet another one' );
                $this->results = $results;
-
-               $this->testLogFileName = 
'/var/log/mediawiki/test_wdqa_evaluation.log';
-               if( file_exists( $this->testLogFileName ) ) {
-                       unlink( $this->testLogFileName );
-               }
-
-               $this->oldLogFileName = 
$GLOBALS['wgDebugLogGroups']['wdqa_evaluation'];
-               $GLOBALS['wgDebugLogGroups']['wdqa_evaluation'] = 
$this->testLogFileName;
        }
 
        protected function tearDown() {
-               $GLOBALS['wgDebugLogGroups']['wdqa_evaluation'] = 
$this->oldLogFileName;
-               unset( $this->oldLogFileName );
-
-               if( file_exists( $this->testLogFileName ) ) {
-                       unlink( $this->testLogFileName );
-               }
-               unset( $this->testLogFileName );
-
+               unset( $this->logEntry );
                unset( $this->results );
                unset( $this->constraintName );
                unset( $this->checkTimestamp );
@@ -81,18 +65,17 @@
                parent::tearDown();
        }
 
+       public function anotherLoggingMethod( $logEntry ) {
+               $this->logEntry = json_decode( substr( $logEntry, mb_strpos( 
$logEntry, '{' ) ), true );
+       }
+
        public function testNewInsertNowAndRun() {
                $job = CheckForConstraintViolationsJob::newInsertNow( 
$this->entity, $this->checkTimestamp, $this->results );
+               $job->setLoggingMethod( $this, 'anotherLoggingMethod' );
                $job->run();
+               $job->resetLoggingMethod();
 
-               $this->assertFileExists( $this->testLogFileName );
-
-               $logFile = fopen( $this->testLogFileName, 'r' );
-               $firstLine = fgets( $logFile );
-               $logEntry = json_decode( substr( $firstLine, mb_strpos( 
$firstLine, '{' ) ), true );
-               fclose( $logFile );
-
-               $this->assertEquals( 1, count( file( $this->testLogFileName ) ) 
);
+               $logEntry = $this->logEntry;
 
                $this->assertEquals( 5, count( $logEntry ) );
                $this->assertEquals( 'SpecialConstraintReport', 
$logEntry['special_page_id'] );
diff --git a/tests/phpunit/Specials/SpecialConstraintReportTest.php 
b/tests/phpunit/Specials/SpecialConstraintReportTest.php
index b112773..953f352 100755
--- a/tests/phpunit/Specials/SpecialConstraintReportTest.php
+++ b/tests/phpunit/Specials/SpecialConstraintReportTest.php
@@ -55,31 +55,12 @@
         */
        private static $hasSetup;
 
-       private $testLogFileName;
-       private $oldLogFileName;
-
        protected function setUp() {
                parent::setUp();
                $this->tablesUsed[ ] = CONSTRAINT_TABLE;
-
-               $this->testLogFileName = 
'/var/log/mediawiki/test_wdqa_evaluation.log';
-               if( file_exists( $this->testLogFileName ) ) {
-                       unlink( $this->testLogFileName );
-               }
-
-               $this->oldLogFileName = 
$GLOBALS['wgDebugLogGroups']['wdqa_evaluation'];
-               $GLOBALS['wgDebugLogGroups']['wdqa_evaluation'] = 
$this->testLogFileName;
        }
 
        protected function tearDown() {
-               $GLOBALS['wgDebugLogGroups']['wdqa_evaluation'] = 
$this->oldLogFileName;
-               unset( $this->oldLogFileName );
-
-               if( file_exists( $this->testLogFileName ) ) {
-                       unlink( $this->testLogFileName );
-               }
-               unset( $this->testLogFileName );
-
                parent::tearDown();
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I498110c84b557f7c4edc7349156d13e29e00b36a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataQualityConstraints
Gerrit-Branch: v1
Gerrit-Owner: Andreasburmeister <andreas.burmeis...@student.hpi.de>

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

Reply via email to