/**
  * Updates entity usage information for the given page, and automatically adjusts
  * any subscriptions based on that usage.
  *
  * @param int $pageId The ID of the page the entities are used on.
  * @param EntityUsage[] $usages A list of EntityUsage objects.
  * See docs/usagetracking.wiki for details.
  * @param string $touched timestamp. Timestamp of the update that contained the given usages.
  *
  * @see UsageTracker::trackUsedEntities
  *
  * @throws InvalidArgumentException
  */
 public function addUsagesForPage($pageId, array $usages, $touched)
 {
     if (!is_int($pageId)) {
         throw new InvalidArgumentException('$pageId must be an int!');
     }
     if (!is_string($touched) || $touched === '') {
         throw new InvalidArgumentException('$touched must be a timestamp string!');
     }
     $this->usageTracker->trackUsedEntities($pageId, $usages, $touched);
     $currentlyUsedEntities = $this->getEntityIds($usages);
     // Subscribe to anything that was added
     if (!empty($currentlyUsedEntities)) {
         $this->subscriptionManager->subscribe($this->clientId, $currentlyUsedEntities);
     }
 }
 public function testPruneStaleUsages()
 {
     $t1 = '20150111000000';
     $t2 = '20150222000000';
     $q3 = new ItemId('Q3');
     $q4 = new ItemId('Q4');
     $q5 = new ItemId('Q5');
     $usagesT1 = array(new EntityUsage($q3, EntityUsage::SITELINK_USAGE), new EntityUsage($q3, EntityUsage::LABEL_USAGE), new EntityUsage($q4, EntityUsage::LABEL_USAGE));
     $usagesT2 = array(new EntityUsage($q3, EntityUsage::SITELINK_USAGE), new EntityUsage($q4, EntityUsage::LABEL_USAGE), new EntityUsage($q5, EntityUsage::ALL_USAGE));
     // init database: $usagesT2 get timestamp $t2,
     // array_diff( $usagesT1, $usagesT2 ) get timestamp $t1.
     $this->tracker->trackUsedEntities(23, $usagesT1, $t1);
     $this->tracker->trackUsedEntities(23, $usagesT2, $t2);
     // pruning should remove entries with a timestamp < $t2
     $this->tracker->pruneStaleUsages(23, $t2);
     $actualUsages = $this->getUsages(23, $t2);
     $this->assertSameUsages($usagesT2, $actualUsages);
 }