/** * @see SMWStore::getSemanticData() * @since 1.8 * * @param DIWikiPage $subject * @param string[]|bool $filter */ public function getSemanticData(DIWikiPage $subject, $filter = false) { // *** Find out if this subject exists ***// $sortKey = ''; $sid = $this->store->smwIds->getSMWPageIDandSort($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName(), $sortKey, true, true); // Ensures that a cached item to contain an expected sortKey when // for example the ID was just created and the sortKey from the DB // is empty otherwise the DB wins over the invoked sortKey if (!$sortKey) { $sortKey = $subject->getSortKey(); } $subject->setSortKey($sortKey); if ($sid == 0) { // We consider redirects for getting $sid, // so $sid == 0 also means "no redirects". return new SMWSemanticData($subject); } $propertyTableHashes = $this->store->smwIds->getPropertyTableHashes($sid); foreach ($this->store->getPropertyTables() as $tid => $proptable) { if (!array_key_exists($proptable->getName(), $propertyTableHashes)) { continue; } if ($filter !== false) { $relevant = false; foreach ($filter as $typeId) { $diType = DataTypeRegistry::getInstance()->getDataItemId($typeId); $relevant = $relevant || $proptable->getDiType() == $diType; if ($relevant) { break; } } if (!$relevant) { continue; } } $this->getSemanticDataFromTable($sid, $subject, $proptable); } // Note: the sortkey is always set but belongs to no property table, // hence no entry in $this->store->m_sdstate[$sid] is made. self::$in_getSemanticData++; $this->initSemanticDataCache($sid, $subject); // Avoid adding a sortkey for an already extended stub if (!$this->store->m_semdata[$sid]->hasProperty(new DIProperty('_SKEY'))) { $this->store->m_semdata[$sid]->addPropertyStubValue('_SKEY', array('', $sortKey)); } self::$in_getSemanticData--; return $this->store->m_semdata[$sid]; }
/** * @since 2.1 * * @param integer $sid * @param DIWikiPage $subject * @param integer|string|null $interWiki */ public function updateInterwikiField($sid, DIWikiPage $subject, $interWiki = null) { $this->store->getConnection()->update(self::tableName, array('smw_iw' => $interWiki !== null ? $interWiki : $subject->getInterWiki()), array('smw_id' => $sid), __METHOD__); $this->setCache($subject->getDBKey(), $subject->getNamespace(), $subject->getInterWiki(), $subject->getSubobjectName(), $sid, $subject->getSortKey()); }
/** * @dataProvider sortKeyProvider */ public function testSortKeyRoundtrip($title, $sortkey, $expected) { $instance = new DIWikiPage($title, NS_MAIN); $instance->setSortKey($sortkey); $this->assertEquals($expected, $instance->getSortKey()); }