/**
  * Update all property tables and any dependent data (hashes,
  * statistics, etc.) by inserting/deleting the given values. The ID of
  * the page that is updated, and the hashes of the properties must be
  * given explicitly (the hashes could not be computed from the insert
  * and delete data alone anyway).
  *
  * It is assumed and required that the tables mentioned in
  * $tablesInsertRows and $tablesDeleteRows are the same, and that all
  * $rows in these datasets refer to the same subject ID.
  *
  * @since 1.8
  *
  * @param integer $sid
  * @param array $tablesInsertRows array mapping table names to arrays of rows
  * @param array $tablesDeleteRows array mapping table names to arrays of rows
  * @param array $newHashes
  */
 protected function writePropertyTableUpdates($sid, array $tablesInsertRows, array $tablesDeleteRows, array $newHashes)
 {
     $propertyUseIncrements = array();
     $propertyTables = $this->store->getPropertyTables();
     foreach ($tablesInsertRows as $tableName => $insertRows) {
         // Note: by construction, the inserts and deletes have the same table keys.
         // Note: by construction, the inserts and deletes are currently disjoint;
         // yet we delete first to make the method more robust/versatile.
         $this->writePropertyTableRowUpdates($propertyUseIncrements, $propertyTables[$tableName], $tablesDeleteRows[$tableName], false);
         $this->writePropertyTableRowUpdates($propertyUseIncrements, $propertyTables[$tableName], $insertRows, true);
     }
     if (!empty($tablesInsertRows) || !empty($tablesDeleteRows)) {
         $this->store->smwIds->setPropertyTableHashes($sid, $newHashes);
     }
     $statsTable = new PropertyStatisticsTable($this->store->getConnection(), SMWSQLStore3::PROPERTY_STATISTICS_TABLE);
     $statsTable->addToUsageCounts($propertyUseIncrements);
 }
 public function testAddToUsageCounts()
 {
     $statsTable = new PropertyStatisticsTable($this->getStore()->getConnection('mw.db'), \SMWSQLStore3::PROPERTY_STATISTICS_TABLE);
     $this->assertTrue($statsTable->deleteAll() !== false);
     $counts = array(1 => 42, 2 => 0, 9001 => 9001, 9002 => $this->isWinOS() ? pow(2, 30) : pow(2, 31), 9003 => 1);
     foreach ($counts as $propId => $count) {
         $this->assertTrue($statsTable->insertUsageCount($propId, $count) !== false);
     }
     $additions = array(2 => 42, 9001 => -9000, 9003 => 0);
     $this->assertTrue($statsTable->addToUsageCounts($additions) !== false);
     foreach ($additions as $propId => $addition) {
         $counts[$propId] += $addition;
     }
     $this->assertEquals($counts, $statsTable->getUsageCounts(array_keys($counts)));
 }
 /**
  * Update all property tables and any dependent data (hashes,
  * statistics, etc.) by inserting/deleting the given values. The ID of
  * the page that is updated, and the hashes of the properties must be
  * given explicitly (the hashes could not be computed from the insert
  * and delete data alone anyway).
  *
  * It is assumed and required that the tables mentioned in
  * $tablesInsertRows and $tablesDeleteRows are the same, and that all
  * $rows in these datasets refer to the same subject ID.
  *
  * @since 1.8
  *
  * @param integer $sid
  * @param array $tablesInsertRows array mapping table names to arrays of rows
  * @param array $tablesDeleteRows array mapping table names to arrays of rows
  * @param array $newHashes
  */
 protected function writePropertyTableUpdates($sid, array $tablesInsertRows, array $tablesDeleteRows, array $newHashes)
 {
     $propertyUseIncrements = array();
     $propertyTables = $this->store->getPropertyTables();
     foreach ($tablesInsertRows as $tableName => $insertRows) {
         // Note: by construction, the inserts and deletes have the same table keys.
         // Note: by construction, the inserts and deletes are currently disjoint;
         // yet we delete first to make the method more robust/versatile.
         $this->writePropertyTableRowUpdates($propertyUseIncrements, $propertyTables[$tableName], $tablesDeleteRows[$tableName], false);
         $this->writePropertyTableRowUpdates($propertyUseIncrements, $propertyTables[$tableName], $insertRows, true);
     }
     // If only rows are marked for deletion then modify hashs to ensure that
     // any inbalance can be corrected by the next insert operation for which
     // the newHashes are computed (seen in connection with redirects)
     if ($tablesInsertRows === array() && $tablesDeleteRows !== array()) {
         foreach ($newHashes as $key => $hash) {
             $newHashes[$key] = $hash . '.d';
         }
     }
     if ($tablesInsertRows !== array() || $tablesDeleteRows !== array()) {
         $this->store->smwIds->setPropertyTableHashes($sid, $newHashes);
     }
     $statsTable = new PropertyStatisticsTable($this->store->getConnection(), SMWSQLStore3::PROPERTY_STATISTICS_TABLE);
     $statsTable->addToUsageCounts($propertyUseIncrements);
 }