/**
  * @since 2.3
  *
  * @param QueryResultDependencyListResolver $queryResultDependencyListResolver
  * @param DependencyLinksTableUpdater $dependencyLinksTableUpdater
  */
 public function __construct(QueryResultDependencyListResolver $queryResultDependencyListResolver, DependencyLinksTableUpdater $dependencyLinksTableUpdater)
 {
     $this->queryResultDependencyListResolver = $queryResultDependencyListResolver;
     $this->dependencyLinksTableUpdater = $dependencyLinksTableUpdater;
     $this->store = $this->dependencyLinksTableUpdater->getStore();
     $this->connection = $this->store->getConnection('mw.db');
 }
 private function tryToMatchDataItemForUnmatchedWikiNamespaceUri($uri)
 {
     $dataItem = null;
     // Sesame: Not a valid (absolute) URI: _node1abjt1k9bx17
     if (filter_var($uri, FILTER_VALIDATE_URL) === false) {
         return $dataItem;
     }
     $respositoryResult = $this->store->getConnection('sparql')->select('?v1 ?v2', "<{$uri}> rdfs:label ?v1 . <{$uri}> swivt:wikiNamespace ?v2", array('LIMIT' => 1));
     $expElements = $respositoryResult->current();
     if ($expElements !== false) {
         // ?v1
         if (isset($expElements[0])) {
             $dbKey = $expElements[0]->getLexicalForm();
         } else {
             $dbKey = 'UNKNOWN';
         }
         // ?v2
         if (isset($expElements[1])) {
             $namespace = strval($expElements[1]->getLexicalForm());
         } else {
             $namespace = NS_MAIN;
         }
         $dataItem = new DIWikiPage($this->getFittingKeyByCapitalLinks($dbKey, $namespace), $namespace);
     }
     return $dataItem;
 }
예제 #3
0
 protected function getPagesFromFilters()
 {
     $pages = array();
     $titleLookup = new TitleLookup($this->store->getConnection('mw.db'));
     foreach ($this->filters as $namespace) {
         $pages = array_merge($pages, $titleLookup->setNamespace($namespace)->selectAll());
     }
     return $pages;
 }
 /**
  * @since 2.2
  *
  * @param Store $store
  * @param Callable|null $reporterCallback
  *
  * @return PropertyStatisticsRebuilder
  */
 public function newPropertyStatisticsRebuilder(Store $store, $reporterCallback = null)
 {
     $messageReporter = MessageReporterFactory::getInstance()->newObservableMessageReporter();
     $messageReporter->registerReporterCallback($reporterCallback);
     $propertyStatisticsTable = new PropertyStatisticsTable($store->getConnection('mw.db'), SQLStore::PROPERTY_STATISTICS_TABLE);
     $propertyStatisticsRebuilder = new PropertyStatisticsRebuilder($store, $propertyStatisticsTable);
     $propertyStatisticsRebuilder->setMessageReporter($messageReporter);
     return $propertyStatisticsRebuilder;
 }
 private function selectPropertiesFromTable($propertyTable)
 {
     $options = $this->store->getSQLOptions($this->requestOptions, 'title');
     $idTable = \SMWSQLStore3::ID_TABLE;
     $options['ORDER BY'] = 'count DESC';
     $options['GROUP BY'] = 'smw_title';
     $conditions = array('smw_id > ' . \SMWSql3SmwIds::FXD_PROP_BORDER_ID, 'page_id IS NULL');
     $db = $this->store->getConnection('mw.db');
     $res = $db->select(array($idTable, 'page', $propertyTable->getName()), array('smw_title', 'COUNT(*) as count'), $conditions, __METHOD__, $options, array($idTable => array('INNER JOIN', 'p_id=smw_id'), 'page' => array('LEFT JOIN', array('page_namespace=' . $db->addQuotes(SMW_NS_PROPERTY), 'page_title=smw_title'))));
     return $res;
 }
예제 #6
0
 protected function createMultipleConcepts()
 {
     $titleLookup = new TitleLookup($this->store->getConnection('mw.db'));
     $titleLookup->setNamespace(SMW_NS_CONCEPT);
     if ($this->endId == 0 && $this->startId == 0) {
         return $titleLookup->selectAll();
     }
     $endId = $titleLookup->getMaxId();
     if ($this->endId > 0) {
         $endId = min($this->endId, $endId);
     }
     return $titleLookup->selectByIdRange($this->startId, $endId);
 }
 private function findNextIdPosition(&$id, $emptyrange)
 {
     $nextpos = $id + $this->iterationLimit;
     $db = $this->store->getConnection('mw.db');
     // nothing found, check if there will be more pages later on
     if ($emptyrange && $nextpos > \SMWSql3SmwIds::FXD_PROP_BORDER_ID) {
         $nextByPageId = (int) $db->selectField('page', 'page_id', "page_id >= {$nextpos}", __METHOD__, array('ORDER BY' => "page_id ASC"));
         $nextBySmwId = (int) $db->selectField(\SMWSql3SmwIds::TABLE_NAME, 'smw_id', "smw_id >= {$nextpos}", __METHOD__, array('ORDER BY' => "smw_id ASC"));
         // Next position is determined by the pool with the maxId
         $nextpos = $nextBySmwId != 0 && $nextBySmwId > $nextByPageId ? $nextBySmwId : $nextByPageId;
     }
     $id = $nextpos ? $nextpos : -1;
 }
 private function selectPropertiesFromTable()
 {
     // the query needs to do the filtering of internal properties, else LIMIT is wrong
     $options = array('ORDER BY' => 'smw_sortkey');
     if ($this->requestOptions->limit > 0) {
         $options['LIMIT'] = $this->requestOptions->limit;
         $options['OFFSET'] = max($this->requestOptions->offset, 0);
     }
     $conditions = array('smw_id > ' . SQLStore::FIXED_PROPERTY_ID_UPPERBOUND, 'smw_namespace' => SMW_NS_PROPERTY, 'smw_iw' => '', 'smw_subobject' => '');
     $conditions['usage_count'] = 0;
     $idTable = $this->store->getObjectIds()->getIdTable();
     $res = $this->store->getConnection('mw.db')->select(array($idTable, $this->propertyStatisticsStore->getStatisticsTable()), array('smw_title', 'usage_count'), $conditions, __METHOD__, $options, array($idTable => array('INNER JOIN', array('smw_id=p_id'))));
     return $res;
 }
예제 #9
0
 private function selectPropertiesFromTable()
 {
     // the query needs to do the filtering of internal properties, else LIMIT is wrong
     $options = array('ORDER BY' => 'smw_sortkey');
     $conditions = array('smw_namespace' => SMW_NS_PROPERTY, 'smw_iw' => '');
     if ($this->requestOptions->limit > 0) {
         $options['LIMIT'] = $this->requestOptions->limit;
         $options['OFFSET'] = max($this->requestOptions->offset, 0);
     }
     if ($this->requestOptions->getStringConditions()) {
         $conditions[] = $this->store->getSQLConditions($this->requestOptions, '', 'smw_title', false);
     }
     $res = $this->store->getConnection('mw.db')->select($this->store->getObjectIds()->getIdTable(), array('smw_id', 'smw_title'), $conditions, __METHOD__, $options);
     return $res;
 }
 private function doQueryPropertyTable()
 {
     // the query needs to do the filtering of internal properties, else LIMIT is wrong
     $options = array('ORDER BY' => 'smw_sortkey');
     $conditions = array('smw_namespace' => SMW_NS_PROPERTY, 'smw_iw' => '');
     if ($this->requestOptions->limit > 0) {
         $options['LIMIT'] = $this->requestOptions->limit;
         $options['OFFSET'] = max($this->requestOptions->offset, 0);
     }
     if ($this->requestOptions->getStringConditions()) {
         $conditions[] = $this->store->getSQLConditions($this->requestOptions, '', 'smw_sortkey', false);
     }
     $db = $this->store->getConnection('mw.db');
     $res = $db->select(array($db->tableName(SQLStore::ID_TABLE), $db->tableName(SQLStore::PROPERTY_STATISTICS_TABLE)), array('smw_title', 'usage_count'), $conditions, __METHOD__, $options, array($db->tableName(SQLStore::ID_TABLE) => array('INNER JOIN', array('smw_id=p_id'))));
     return $res;
 }
 /**
  * Add cache information to concept data and make sure that there is
  * exactly one value for the concept table.
  *
  * @note This code will vanish when concepts have a more standard
  * handling. So not point in optimizing this much now.
  *
  * @since 1.8
  * @param integer $sid
  * @param &array $insertData
  */
 private function fetchConceptTableInserts($sid, &$insertData)
 {
     $connection = $this->store->getConnection('mw.db');
     // Make sure that there is exactly one row to be written:
     if (array_key_exists('smw_fpt_conc', $insertData) && !empty($insertData['smw_fpt_conc'])) {
         $insertValues = end($insertData['smw_fpt_conc']);
     } else {
         $insertValues = array('s_id' => $sid, 'concept_txt' => '', 'concept_docu' => '', 'concept_features' => 0, 'concept_size' => -1, 'concept_depth' => -1);
     }
     // Add existing cache status data to this row:
     $row = $connection->selectRow('smw_fpt_conc', array('cache_date', 'cache_count'), array('s_id' => $sid), __METHOD__);
     if ($row === false) {
         $insertValues['cache_date'] = null;
         $insertValues['cache_count'] = null;
     } else {
         $insertValues['cache_date'] = $row->cache_date;
         $insertValues['cache_count'] = $row->cache_count;
     }
     $insertData['smw_fpt_conc'] = array($insertValues);
 }
 protected function getPropertyTableRowCount($propertyTable, $id)
 {
     $condition = $propertyTable->isFixedPropertyTable() ? array() : array('p_id' => $id);
     $row = $this->store->getConnection('mw.db')->selectRow($propertyTable->getName(), 'Count(*) as count', $condition, __METHOD__);
     return $row->count;
 }
예제 #13
0
 /**
  * @since 2.1
  *
  * @param string $connectionTypeId
  *
  * @return mixed
  */
 public function getConnection($connectionTypeId = 'sparql')
 {
     if ($this->connectionManager === null) {
         $this->setConnectionManager($this->factory->newConnectionManager());
     }
     return parent::getConnection($connectionTypeId);
 }
 public function setStore(Store $store)
 {
     return $store->getConnection('foo');
 }
예제 #15
0
 private function count($type)
 {
     $res = $this->store->getConnection()->select($this->findPropertyTableByType($type)->getName(), 'COUNT(s_id) AS count', array(), __METHOD__);
     $row = $this->store->getConnection()->fetchObject($res);
     return isset($row->count) ? (int) $row->count : 0;
 }
 /**
  * @since 2.4
  *
  * @param Store $store
  */
 public function __construct(Store $store)
 {
     $this->store = $store;
     $this->connection = $this->store->getConnection('mw.db');
 }