public function testNewSpec() { $usageQ5X = new EntityUsage(new ItemId('Q5'), 'X'); $title = Title::makeTitle(NS_MAIN, 'Foo'); $title->resetArticleID(17); $touched = '20150101000000'; $usages = array($usageQ5X); $spec = AddUsagesForPageJob::newSpec($title, $usages, $touched); $expected = array('pageId' => $title->getArticleID(), 'usages' => array($usageQ5X->asArray()), 'touched' => '20150101000000'); $this->assertEquals('wikibase-addUsagesForPage', $spec->getType()); $this->assertEquals($title->getFullText(), $spec->getTitle()->getFullText()); $this->assertEquals($expected, $spec->getParams()); }
/** * Triggered when a new rendering of a page is committed to the ParserCache. * Implemented to update usage tracking information via UsageUpdater. * * @param ParserOutput $parserOutput * @param Title $title */ public function doParserCacheSaveComplete(ParserOutput $parserOutput, Title $title) { $usageAcc = new ParserOutputUsageAccumulator($parserOutput); // Note: ParserOutput::getTimestamp() is unreliable and "sometimes" contains an old timestamp. // Note: getTouched() returns false if $title doesn't exist. $touched = $title->getTouched(); if (!$touched || count($usageAcc->getUsages()) === 0) { // no usages or no title, bail out return; } // Add or touch any usages present in the new rendering. // This allows us to track usages in each user language separately, for multilingual sites. // NOTE: Since parser cache updates may be triggered by page views (in a new language), // schedule the usage updates in the job queue, to avoid writing to the database // during a GET request. //TODO: Before posting a job, check slave database. If no changes are needed, skip update. $addUsagesForPageJob = AddUsagesForPageJob::newSpec($title, $usageAcc->getUsages(), $touched); $enqueueJob = EnqueueJob::newFromLocalJobs($addUsagesForPageJob); $this->jobScheduler->lazyPush($enqueueJob); }