/**
  * @since 2.2
  *
  * @return ConceptCache
  */
 public function newMasterConceptCache()
 {
     $conceptQueryResolver = new ConceptQueryResolver($this->newMasterQueryEngine());
     $conceptQueryResolver->setConceptFeatures($GLOBALS['smwgQConceptFeatures']);
     $conceptCache = new ConceptCache($this->store, $conceptQueryResolver);
     $conceptCache->setUpperLimit($GLOBALS['smwgQMaxLimit']);
     return $conceptCache;
 }
 public function testPrepareQuerySegmentForNull()
 {
     $querySegmentListBuilder = $this->getMockBuilder('\\SMW\\SQLStore\\QueryEngine\\QuerySegmentListBuilder')->disableOriginalConstructor()->getMock();
     $querySegmentListProcessor = $this->getMockBuilder('\\SMW\\SQLStore\\QueryEngine\\QuerySegmentListProcessor')->disableOriginalConstructor()->getMock();
     $queryEngine = $this->getMockBuilder('\\SMW\\SQLStore\\QueryEngine\\QueryEngine')->disableOriginalConstructor()->getMock();
     $queryEngine->expects($this->any())->method('getQuerySegmentListBuilder')->will($this->returnValue($querySegmentListBuilder));
     $queryEngine->expects($this->any())->method('getQuerySegmentListProcessor')->will($this->returnValue($querySegmentListProcessor));
     $instance = new ConceptQueryResolver($queryEngine);
     $this->assertNull($instance->prepareQuerySegmentFor('[[Foo]]'));
 }
 /**
  * @param Title $concept
  *
  * @return string[] array with error messages
  */
 public function refresh(Title $concept)
 {
     global $wgDBtype;
     $db = $this->store->getConnection();
     $cid = $this->store->smwIds->getSMWPageID($concept->getDBkey(), SMW_NS_CONCEPT, '', '');
     $cid_c = $this->getIdOfConcept($concept);
     if ($cid !== $cid_c) {
         return array("Skipping redirect concept.");
     }
     $conceptQueryText = $this->getConceptCacheText($concept);
     if ($conceptQueryText === false) {
         $this->deleteConceptById($cid);
         return array("No concept description found.");
     }
     // Pre-process query:
     $querySegment = $this->conceptQueryResolver->prepareQuerySegmentFor($conceptQueryText);
     if ($querySegment === null || $querySegment->joinfield === '' || $querySegment->joinTable === '') {
         return array();
     }
     // TODO: catch db exception
     $db->delete(SMWSQLStore3::CONCEPT_CACHE_TABLE, array('o_id' => $cid), __METHOD__);
     $concCacheTableName = $db->tablename(SMWSQLStore3::CONCEPT_CACHE_TABLE);
     if ($wgDBtype == 'postgres') {
         // PostgresQL: no INSERT IGNORE, check for duplicates explicitly
         $where = $querySegment->where . ($querySegment->where ? ' AND ' : '') . "NOT EXISTS (SELECT NULL FROM {$concCacheTableName}" . " WHERE {$concCacheTableName}.s_id = {$querySegment->alias}.s_id " . " AND  {$concCacheTableName}.o_id = {$querySegment->alias}.o_id )";
     } else {
         // MySQL just uses INSERT IGNORE, no extra conditions
         $where = $querySegment->where;
     }
     // TODO: catch db exception
     $db->query("INSERT " . ($wgDBtype == 'postgres' ? '' : 'IGNORE ') . "INTO {$concCacheTableName}" . " SELECT DISTINCT {$querySegment->joinfield} AS s_id, {$cid} AS o_id FROM " . $db->tableName($querySegment->joinTable) . " AS {$querySegment->alias}" . $querySegment->from . ($where ? ' WHERE ' : '') . $where . " LIMIT " . $this->upperLimit, __METHOD__);
     $db->update('smw_fpt_conc', array('cache_date' => strtotime("now"), 'cache_count' => $db->affectedRows()), array('s_id' => $cid), __METHOD__);
     return array();
 }
Ejemplo n.º 4
0
 /**
  * @param Title $concept
  *
  * @return string[] array with error messages
  */
 public function refresh(Title $concept)
 {
     global $wgDBtype;
     $db = $this->store->getConnection();
     $cid = $this->store->smwIds->getSMWPageID($concept->getDBkey(), SMW_NS_CONCEPT, '', '');
     $cid_c = $this->getIdOfConcept($concept);
     if ($cid !== $cid_c) {
         return array("Skipping redirect concept.");
     }
     $conceptQueryText = $this->getConceptCacheText($concept);
     if ($conceptQueryText === false) {
         $this->deleteConceptById($cid);
         return array("No concept description found.");
     }
     // Pre-process query:
     $querySegment = $this->conceptQueryResolver->prepareQuerySegmentFor($conceptQueryText);
     if ($querySegment === null || $querySegment->joinfield === '' || $querySegment->joinTable === '') {
         return array();
     }
     // TODO: catch db exception
     $db->delete(SMWSQLStore3::CONCEPT_CACHE_TABLE, array('o_id' => $cid), __METHOD__);
     $concCacheTableName = $db->tablename(SMWSQLStore3::CONCEPT_CACHE_TABLE);
     // MySQL just uses INSERT IGNORE, no extra conditions
     $where = $querySegment->where;
     if ($wgDBtype == 'postgres') {
         // PostgresQL: no INSERT IGNORE, check for duplicates explicitly
         // This code doesn't work and has created all sorts of issues therefore use LEFT JOIN instead
         // http://people.planetpostgresql.org/dfetter/index.php?/archives/48-Adding-Only-New-Rows-INSERT-IGNORE,-Done-Right.html
         //	$where = $querySegment->where . ( $querySegment->where ? ' AND ' : '' ) .
         //		"NOT EXISTS (SELECT NULL FROM $concCacheTableName" .
         //		" WHERE {$concCacheTableName}.s_id = {$querySegment->alias}.s_id " .
         //		" AND  {$concCacheTableName}.o_id = {$querySegment->alias}.o_id )";
         $querySegment->from = str_replace('INNER JOIN', 'LEFT JOIN', $querySegment->from);
     }
     $db->query("INSERT " . ($wgDBtype == 'postgres' ? '' : 'IGNORE ') . "INTO {$concCacheTableName}" . " SELECT DISTINCT {$querySegment->joinfield} AS s_id, {$cid} AS o_id FROM " . $db->tableName($querySegment->joinTable) . " AS {$querySegment->alias}" . $querySegment->from . ($where ? ' WHERE ' : '') . $where . " LIMIT " . $this->upperLimit, __METHOD__);
     $db->update('smw_fpt_conc', array('cache_date' => strtotime("now"), 'cache_count' => $db->affectedRows()), array('s_id' => $cid), __METHOD__);
     return array();
 }