public static function getInstance() { if (is_null(self::$instance)) { self::$instance = new self(); } return self::$instance; }
public function updateData(SMWSemanticData $data, $store) { //get list of properties which are set by this article //todo: think about only querying for modified properties $properties = $data->getProperties(); foreach ($properties as $name => $property) { //ignore internal properties if (!$property->isUserDefined() || $name == QRC_HQID_LABEL) { unset($properties[$name]); } } //determine differences between the new and the original semantic data global $wgTitle; if ($wgTitle) { $originalData = $store->getSemanticData($wgTitle); foreach ($originalData->getProperties() as $oName => $oProperty) { if (array_key_exists($oName, $properties)) { $oValues = $originalData->getPropertyValues($oProperty); $values = $data->getPropertyValues($properties[$oName]); if (count($oValues) == count($values)) { $oWikiValues = array(); foreach ($oValues as $key => $value) { $oWikiValues[$value->getWikiValue()] = true; } $wikiValues = array(); foreach ($values as $key => $value) { $wikiValues[$value->getWikiValue()] = true; } $unset = true; foreach (array_keys($values) as $value) { if (!array_key_exists($value, $oWikiValues)) { $unset = false; break; } } if ($unset) { unset($properties[$oName]); } } //echo('<pre>'.print_r($oProperty, true).'</pre>'); //echo('<pre>'.print_r(, true).'</pre>'); } else { if ($oProperty->isUserDefined() && $name != QRC_HQID_LABEL) { $properties[$oName] = $oProperty; } } } } //deal with categories and determine which queries to update $categories = array(); global $wgParser; if ($wgParser && $wgParser->getOutput() && $wgTitle) { $categories = $wgParser->getOutput()->getCategories(); $originalCategories = $wgTitle->getParentCategories(); //echo('<pre>'.print_r($originalCategories, true).'</pre>'); foreach (array_keys($originalCategories) as $category) { $category = substr($category, strpos($category, ':') + 1); if (array_key_exists($category, $categories)) { unset($categories[$category]); } else { $categories[$category] = true; } } } //echo('<pre>'.print_r(array_keys($categories), true).'</pre>'); //echo('<pre>'.print_r(array_keys($properties), true).'</pre>'); if (count($properties) > 0 || count($categories) > 0) { //query for all articles that use a query which depends on one of the properties $queryString = SMWQRCQueryManagementHandler::getInstance()->getSearchQueriesAffectedByDataModification(array_keys($properties), array_keys($categories)); SMWQueryProcessor::processFunctionParams(array($queryString), $queryString, $params, $printouts); $query = SMWQueryProcessor::createQuery($queryString, $params); $queryResults = $this->getQueryResult($query, true, false)->getResults(); //get query ids which have to be invalidated $queryIds = array(); foreach ($queryResults as $queryResult) { $semanticData = $store->getSemanticData($queryResult); $invalidatePC = false; $tQueryIds = SMWQRCQueryManagementHandler::getInstance()->getIdsOfQueriesUsingProperty($semanticData, $properties); if (count($tQueryIds) > 0) { $invalidatePC = true; } $queryIds = array_merge($queryIds, $tQueryIds); $tQueryIds = SMWQRCQueryManagementHandler::getInstance()->getIdsOfQueriesUsingCategory($semanticData, $categories); if (count($tQueryIds) > 0) { $invalidatePC = true; } $queryIds = array_merge($queryIds, $tQueryIds); global $invalidateParserCache, $showInvalidatedCacheEntries; if ($invalidatePC && $invalidateParserCache && !$showInvalidatedCacheEntries) { $title = $queryResult->getTitle(); $title->invalidateCache(); } } $qrcStore = SMWQRCStore::getInstance()->getDB(); $qrcStore->invalidateQueryData($queryIds); } return $store->doUpdateData($data); }
* @author: Kai K�hn * * Created on: 3.07.2009 */ if (array_key_exists('SERVER_NAME', $_SERVER) && $_SERVER['SERVER_NAME'] != NULL) { echo "Invalid access! A maintenance script MUST NOT accessed from remote."; return; } $mediaWikiLocation = dirname(__FILE__) . '/../../..'; require_once "{$mediaWikiLocation}/maintenance/commandLine.inc"; $help = array_key_exists('h', $options); $delete = array_key_exists('delete', $options); if ($help) { echo "\nUsage: php setup.php [ -h This help ]\n"; die; } if ($delete) { print "\\Drop SMWHalo.\n\n"; smwfGetSemanticStore()->drop(true); //deal with the query results cache global $smwgHaloIP; require_once "{$smwgHaloIP}/includes/QueryResultsCache/SMW_QRC_Store.php"; SMWQRCStore::getInstance()->getDB()->dropTables(); die; } print "\nSetup SMWHalo.\n\n"; global $smwgHaloIP; require_once "{$smwgHaloIP}/includes/QueryResultsCache/SMW_QRC_Store.php"; SMWQRCStore::getInstance()->getDB()->initDatabaseTables(); smwfGetSemanticStore()->setup(true); //deal with the query results cache
public function doNotTestPriorityComputation() { smwf_om_EditArticle('QRCQueryArticle1', 'PHPUnit', $this->queryArticle1Version2, ''); $request = json_encode(array('debug' => true)); $response = smwf_qc_getQueryIds($request); $response = json_decode($response); $qrcStore = SMWQRCStore::getInstance()->getDB(); $qId = $response->queryIds[0]; $queryData = $qrcStore->getQueryData($qId); $this->assertEquals($queryData['priority'], SMWQRCPriorityCalculator::getInstance()->computeQueryUpdatePriority($queryData['lastUpdate'], $queryData['accessFrequency'], $queryData['invalidationFrequency'])); $rememberedPriority = $queryData['priority']; $article = Article::newFromID(Title::newFromText('QRCQueryArticle1')->getArticleID()); $content = $article->getContent(); global $wgParser; $pOpts = new ParserOptions(); $result = $wgParser->parse($content, Title::newFromText('QRCQueryArticle1'), $pOpts)->getText(); $queryData = $qrcStore->getQueryData($qId); $this->assertEquals($queryData['priority'], SMWQRCPriorityCalculator::getInstance()->computeQueryUpdatePriority($queryData['lastUpdate'], $queryData['accessFrequency'], $queryData['invalidationFrequency'])); $this->assertNotEquals($rememberedPriority, $queryData['priority']); $rememberedPriority = $queryData['priority']; global $wgTitle; $wgTitle = Title::newFromText('QRCDataArticle1'); smwf_om_EditArticle('QRCDataArticle1', 'PHPUnit', '', ''); $queryData = $qrcStore->getQueryData($qId); $this->assertEquals($queryData['priority'], SMWQRCPriorityCalculator::getInstance()->computeQueryUpdatePriority($queryData['lastUpdate'], $queryData['accessFrequency'], $queryData['invalidationFrequency'])); $this->assertNotEquals($rememberedPriority, $queryData['priority']); $request = json_encode(array('debug' => true, 'queryId' => $qId)); $response = smwf_qc_updateQuery($request); $response = json_decode($response); $queryData = $qrcStore->getQueryData($qId); $this->assertEquals($queryData['priority'], SMWQRCPriorityCalculator::getInstance()->computeQueryUpdatePriority($queryData['lastUpdate'], $queryData['accessFrequency'], $queryData['invalidationFrequency'])); $this->assertNotEquals($rememberedPriority, $queryData['priority']); }
function smwfQRCInitializeTables() { global $smwgHaloIP; require_once "{$smwgHaloIP}/includes/QueryResultsCache/SMW_QRC_Store.php"; SMWQRCStore::getInstance()->getDB()->initDatabaseTables(); return true; }