/**
  * Triggered when a page gets re-rendered to update secondary link tables.
  * Implemented to update usage tracking information via UsageUpdater.
  *
  * @param LinksUpdate $linksUpdate
  */
 public function doLinksUpdateComplete(LinksUpdate $linksUpdate)
 {
     $title = $linksUpdate->getTitle();
     $parserOutput = $linksUpdate->getParserOutput();
     $usageAcc = new ParserOutputUsageAccumulator($parserOutput);
     // For now, use the current timestamp as the touch date.
     // $parserOutput->getTimestamp() sounds good, but is documented as "timestamp of the revision",
     // which is not what we want. $title->getTouched() sounds good, but it may not have been
     // updated reflecting the current run of LinksUpdate yet. Since on LinksUpdateComplete we
     // actually want to purge all old tracking entries and only care about keeping the ones
     // now present in $parserOutput, using the current timestamp should be fine.
     // NOTE: adjust DataUpdateHookHandlerTest::newUsageUpdater when fixing this.
     $touched = wfTimestampNow();
     // Add or touch any usages present in the rendering
     $this->usageUpdater->addUsagesForPage($title->getArticleId(), $usageAcc->getUsages(), $touched);
     // Prune any usages older than the new rendering's timestamp.
     // NOTE: only prune after adding the new updates, to avoid unsubscribing and then
     // immediately re-subscribing to the used entities.
     $this->usageUpdater->pruneUsagesForPage($title->getArticleId(), $touched);
 }
 /**
  * @dataProvider addUsagesForPageProvider
  */
 public function testAddUsagesForPage($newUsage, $touched, $subscribe)
 {
     $usageTracker = $this->getMock('Wikibase\\Client\\Usage\\UsageTracker');
     $usageTracker->expects($this->once())->method('trackUsedEntities')->with(23, $newUsage, $touched);
     $usageLookup = $this->getMock('Wikibase\\Client\\Usage\\UsageLookup');
     $usageLookup->expects($this->never())->method('getUsagesForPage');
     $usageLookup->expects($this->never())->method('getUnusedEntities');
     $subscriptionManager = $this->getMock('Wikibase\\Client\\Usage\\SubscriptionManager');
     $subscriptionManager->expects($this->never())->method('unsubscribe');
     if (empty($subscribe)) {
         // PHPUnit 3.7 doesn't like a with() assertion combined with an exactly( 0 ) assertion.
         $subscriptionManager->expects($this->never())->method('subscribe');
     } else {
         $subscriptionManager->expects($this->once())->method('subscribe')->with('testwiki', $this->callback(function ($actualSubscribe) use($subscribe) {
             return UsageUpdaterTest::arraysHaveSameContent($actualSubscribe, $subscribe);
         }));
     }
     $updater = new UsageUpdater('testwiki', $usageTracker, $usageLookup, $subscriptionManager);
     // assertions are done by the mock double
     $updater->addUsagesForPage(23, $newUsage, $touched);
 }
 /**
  * Call UsageUpdater::addUsagesForPage
  *
  * @return bool Success
  */
 public function run()
 {
     $this->usageUpdater->addUsagesForPage($this->pageId, $this->getUsages(), $this->touched);
 }