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)));
 }
Пример #2
0
 /**
  * Find the numeric ID used for the page of the given normalized title,
  * namespace, interwiki, and subobjectName. Predefined IDs are not
  * taken into account (however, they would still be found correctly by
  * an avoidable database read if they are stored correctly in the
  * database; this should always be the case). In all other aspects, the
  * method works just like makeSMWPageID(). Especially, if no ID exists,
  * a new ID is created and returned.
  *
  * @since 1.8
  * @param string $title DB key
  * @param integer $namespace namespace
  * @param string $iw interwiki prefix
  * @param string $subobjectName name of subobject
  * @param boolean $canonical should redirects be resolved?
  * @param string $sortkey call-by-ref will be set to sortkey
  * @param boolean $fetchHashes should the property hashes be obtained and cached?
  * @return integer SMW id or 0 if there is none
  */
 protected function makeDatabaseId($title, $namespace, $iw, $subobjectName, $canonical, $sortkey, $fetchHashes)
 {
     $oldsort = '';
     $id = $this->getDatabaseIdAndSort($title, $namespace, $iw, $subobjectName, $oldsort, $canonical, $fetchHashes);
     $db = $this->store->getConnection('mw.db');
     $db->beginAtomicTransaction(__METHOD__);
     if ($id == 0) {
         $sortkey = $sortkey ? $sortkey : str_replace('_', ' ', $title);
         $sequenceValue = $db->nextSequenceValue($this->getIdTable() . '_smw_id_seq');
         // Bug 42659
         $db->insert(self::tableName, array('smw_id' => $sequenceValue, 'smw_title' => $title, 'smw_namespace' => $namespace, 'smw_iw' => $iw, 'smw_subobject' => $subobjectName, 'smw_sortkey' => $sortkey), __METHOD__);
         $id = (int) $db->insertId();
         // Properties also need to be in the property statistics table
         if ($namespace === SMW_NS_PROPERTY) {
             $statsStore = new PropertyStatisticsTable($db, SMWSQLStore3::PROPERTY_STATISTICS_TABLE);
             $statsStore->insertUsageCount($id, 0);
         }
         $this->setCache($title, $namespace, $iw, $subobjectName, $id, $sortkey);
         if ($fetchHashes) {
             $this->setPropertyTableHashesCache($id, null);
         }
     } elseif ($sortkey !== '' && $sortkey != $oldsort) {
         $db->update(self::tableName, array('smw_sortkey' => $sortkey), array('smw_id' => $id), __METHOD__);
         $this->setCache($title, $namespace, $iw, $subobjectName, $id, $sortkey);
     }
     $db->commitAtomicTransaction(__METHOD__);
     return $id;
 }