public function testContentHashId() { $hash = HashBuilder::createHashIdForContent('Foo'); $this->assertInternalType('string', $hash); $this->assertSame($hash, HashBuilder::createHashIdForContent(array('Foo'))); $this->assertContains('Bar', HashBuilder::createHashIdForContent(array('Foo'), 'Bar')); }
private function createSubobjectId(ArrayFormatter $parameters) { $isAnonymous = in_array($parameters->getFirst(), array(null, '', '-')); $this->useFirstElementForPropertyLabel = $this->useFirstElementForPropertyLabel && !$isAnonymous; if ($this->useFirstElementForPropertyLabel || $isAnonymous) { return HashBuilder::createHashIdForContent($parameters->toArray(), '_'); } return $parameters->getFirst(); }
/** * The subobject is attached to a root subject therefore using the root as * identifier to allow it to be invalidated at once with all other subobjects * that relate to a subject */ private function getHashFrom(DIWikiPage $subject, $suffix = '') { return md5(HashBuilder::createHashIdFromSegments($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki()) . $suffix); }
/** * Returns result hash value * * @since 1.9 * * @return string */ public function getHash() { return HashBuilder::createHashIdForContent($this->serializeToArray()); }
/** * @note Before 2.5, toArray was used to generate the content, as of 2.5 * only parameters that influence the result of an query is included. * * @since 2.1 * * @return string */ public function getHash() { // FIXME 3.0 Leave the hash unchanged to avoid unnecessary BC issues in // case the cache is not used. if ($GLOBALS['smwgQueryResultCacheType'] === false || $GLOBALS['smwgQueryResultCacheType'] === CACHE_NONE || $GLOBALS['smwgQueryResultCacheType'] === 'hash') { return HashBuilder::createFromArray($this->toArray()); } // For an optimal (less fragmentation) use of the cache, only use // elements that directly influence the result list $serialized = array(); $serialized['conditions'] = $this->getQueryString(); $serialized['parameters'] = array('limit' => $this->limit, 'offset' => $this->offset, 'sortkeys' => $this->sortkeys, 'querymode' => $this->querymode); if ($this->querySource !== null && $this->querySource !== '') { $serialized['parameters']['source'] = $this->querySource; } // printouts are avoided as part of the hash as they not influence the // match process and are only resolved after the query result has been // retrieved return HashBuilder::createFromArray($serialized); }
/** * Remove any cache entry for the given data. The key consists of the * parameters $title, $namespace, $interwiki, and $subobject. The * cached data is $id and $sortkey. * * @since 1.8 * @param string $title * @param integer $namespace * @param string $interwiki * @param string $subobject */ public function deleteCache($title, $namespace, $interwiki, $subobject) { if ($namespace == SMW_NS_PROPERTY && $interwiki === '' && $subobject === '') { $id = isset($this->prop_ids[$title]) ? $this->prop_ids[$title] : 0; unset($this->prop_ids[$title]); unset($this->prop_sortkeys[$title]); } else { $hashKey = HashBuilder::createHashIdFromSegments($title, $namespace, $interwiki, $subobject); $id = isset($this->regular_ids[$hashKey]) ? $this->regular_ids[$hashKey] : 0; unset($this->regular_ids[$hashKey]); unset($this->regular_sortkeys[$hashKey]); } $this->dataItemByIdFinder->deleteFromCache($id); }
private function addPagesToUpdater(array $hashList) { foreach ($hashList as $hash) { $this->pageUpdater->addPage(HashBuilder::newTitleFromHash($hash)); } }
/** * @since 2.1 * * @param string $title * @param integer $namespace */ public function deleteRedirectEntry($title, $namespace) { $this->delete($title, $namespace); $hash = HashBuilder::createHashIdFromSegments($title, $namespace); $this->inMemoryPoolCache->getPoolCacheFor('sql.store.redirect.infostore')->delete($hash); }
private function getParameters(ParserParameterProcessor $parserParameterProcessor) { $id = $parserParameterProcessor->getFirst(); $isAnonymous = in_array($id, array(null, '', '-')); $this->isEnabledFirstElementAsPropertyLabel = $this->isEnabledFirstElementAsPropertyLabel && !$isAnonymous; $parameters = $this->doPrepareParameters($parserParameterProcessor); // Reclaim the ID to be hash based on the content if ($this->isEnabledFirstElementAsPropertyLabel || $isAnonymous) { $id = HashBuilder::createHashIdForContent($parameters, '_'); } return array($parameters, $id); }
private function canMatchById($id) { $row = $this->connection->selectRow(\SMWSQLStore3::ID_TABLE, array('smw_title', 'smw_namespace', 'smw_iw', 'smw_subobject'), array('smw_id' => $id), __METHOD__); if ($row === false) { return false; } $hash = HashBuilder::createHashIdFromSegments($row->smw_title, $row->smw_namespace, $row->smw_iw, $row->smw_subobject); $this->saveToCache($id, $hash); return true; }
public function testCreateFromSemanticData() { $semanticData = new SemanticData(DIWikiPage::newFromText(__METHOD__)); $this->assertInternalType('string', HashBuilder::createFromSemanticData($semanticData)); }
/** * @since 2.1 * * @param string $title * @param integer $namespace */ public function deleteRedirectEntry($title, $namespace) { $this->delete($title, $namespace); $hash = HashBuilder::createHashIdFromSegments($title, $namespace); $this->cache->delete($hash); }
/** * @since 2.1 * * @param integer $id * * @return DIWikiPage|null */ public function getDataItemForId($id) { $poolCache = $this->inMemoryPoolCache->getPoolCacheFor('sql.store.dataitem.finder'); if (!$poolCache->contains($id)) { $row = $this->connection->selectRow(\SMWSQLStore3::ID_TABLE, array('smw_title', 'smw_namespace', 'smw_iw', 'smw_subobject'), array('smw_id' => $id), __METHOD__); if ($row === false) { return null; } $hash = HashBuilder::createHashIdFromSegments($row->smw_title, $row->smw_namespace, $row->smw_iw, $row->smw_subobject); $this->saveToCache($id, $hash); } return HashBuilder::newDiWikiPageFromHash($poolCache->fetch($id)); }
/** * @since 2.1 * * @param integer $id * * @return DIWikiPage|null */ public function getDataItemForId($id) { if (!$this->cache->contains($id)) { $row = $this->connection->selectRow($this->tableName, array('smw_title', 'smw_namespace', 'smw_iw', 'smw_subobject'), array('smw_id' => $id), __METHOD__); if ($row === false) { return null; } $hash = HashBuilder::createHashIdFromSegments($row->smw_title, $row->smw_namespace, $row->smw_iw, $row->smw_subobject); $this->saveToCache($id, $hash); } return HashBuilder::newDiWikiPageFromHash($this->cache->fetch($id)); }