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); }