public function testPredefinedProperty() { $instance = new HashBuilder(); $property = new DIProperty('_MDAT'); $dataItem = $property->getDiWikiPage(); $this->assertEquals($dataItem, $instance->newDiWikiPageFromHash($instance->getHashIdForDiWikiPage($dataItem))); $this->assertEquals($dataItem, $instance->newDiWikiPageFromHash($instance->createHashIdFromSegments($property->getKey(), SMW_NS_PROPERTY))); }
/** * @note SMWSql3SmwIds::getSMWPageID has some issues with the cache as it returned * 0 even though an object was matchable, using this method is safer then trying * to encipher getSMWPageID related methods. * * It uses the PoolCache which means Lru is in place to avoid memory leakage. * * @since 2.4 * * @param DIWikiPage $subject * * @param integer */ public function getIDFor(DIWikiPage $subject) { // Try to match a predefined property if ($subject->getNamespace() === SMW_NS_PROPERTY && $subject->getInterWiki() === '') { $property = DIProperty::newFromUserLabel($subject->getDBKey()); $key = $property->getKey(); // Has a fixed ID? if (isset(self::$special_ids[$key])) { return self::$special_ids[$key]; } // Switch title for fixed properties without a fixed ID (e.g. _MIME is the smw_title) if (!$property->isUserDefined()) { $subject = new DIWikiPage($key, SMW_NS_PROPERTY); } } $hash = HashBuilder::getHashIdForDiWikiPage($subject); if (($id = $this->intermediaryIdCache->fetch($hash)) !== false) { return $id; } $id = 0; $row = $this->store->getConnection('mw.db')->selectRow(self::TABLE_NAME, array('smw_id'), array('smw_title' => $subject->getDBKey(), 'smw_namespace' => $subject->getNamespace(), 'smw_iw' => $subject->getInterWiki(), 'smw_subobject' => $subject->getSubobjectName()), __METHOD__); if ($row !== false) { $id = $row->smw_id; } // Legacy $this->setCache($subject->getDBKey(), $subject->getNamespace(), $subject->getInterWiki(), $subject->getSubobjectName(), $id, $subject->getSortKey()); return $id; }