/** * @since 2.3 * * @param DIWikiPage $subject, $subobjectName * @param string $subobjectName */ public function tryToMakeIdForSubject(DIWikiPage $subject, $subobjectName = '') { if ($subject->getNamespace() !== NS_CATEGORY && $subject->getNamespace() !== SMW_NS_PROPERTY) { return 0; } $id = $this->store->getObjectIds()->makeSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subobjectName, false); wfDebugLog('smw', __METHOD__ . " add new {$id} ID for " . $subject->getHash() . " \n"); return $id; }
/** * Returns wanted properties * * @note This function is very resource intensive and needs to be cached on * medium/large wikis. * * @since 1.9 * * @return DIProperty[] */ protected function doQuery() { Profiler::In(__METHOD__); $options = $this->store->getSQLOptions($this->requestOptions, 'title'); $options['ORDER BY'] = 'count DESC'; // TODO: this is not how JOINS should be specified in the select function $res = $this->dbConnection->select($this->dbConnection->tableName($this->propertyTable->getName()) . ' INNER JOIN ' . $this->dbConnection->tableName($this->store->getObjectIds()->getIdTable()) . ' ON p_id=smw_id LEFT JOIN ' . $this->dbConnection->tableName('page') . ' ON (page_namespace=' . $this->dbConnection->addQuotes(SMW_NS_PROPERTY) . ' AND page_title=smw_title)', 'smw_title, COUNT(*) as count', 'smw_id > 50 AND page_id IS NULL GROUP BY smw_title', __METHOD__, $options); Profiler::Out(__METHOD__); return $res; }
private function selectPropertiesFromTable($propertyTable) { $options = $this->store->getSQLOptions($this->requestOptions, 'title'); $idTable = $this->store->getObjectIds()->getIdTable(); $options['ORDER BY'] = 'count DESC'; $options['GROUP BY'] = 'smw_title'; $conditions = array('smw_id > 50', '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; }
/** * Create an array of rows to insert into property tables in order to * store the given SMWSemanticData. The given $sid (subject page id) is * used directly and must belong to the subject of the data container. * Sortkeys are ignored since they are not stored in a property table * but in the ID table. * * The returned array uses property table names as keys and arrays of * table rows as values. Each table row is an array mapping column * names to values. * * @note Property tables that do not use ids as subjects are ignored. * This just excludes redirects that are handled differently anyway; * it would not make a difference to include them here. * * @since 1.8 * * @param integer $sid * @param SemanticData $semanticData * * @return array */ private function mapToInsertValueFormat($sid, SemanticData $semanticData) { $updates = array(); $subject = $semanticData->getSubject(); $propertyTables = $this->store->getPropertyTables(); foreach ($semanticData->getProperties() as $property) { $tableId = $this->store->findPropertyTableID($property); // not stored in a property table, e.g., sortkeys if ($tableId === null) { continue; } // "Notice: Undefined index" if (!isset($propertyTables[$tableId])) { throw new RuntimeException("Unable to find a property table for " . $property->getKey()); } $propertyTable = $propertyTables[$tableId]; // not using subject ids, e.g., redirects if (!$propertyTable->usesIdSubject()) { continue; } $insertValues = array('s_id' => $sid); if (!$propertyTable->isFixedPropertyTable()) { $insertValues['p_id'] = $this->store->getObjectIds()->makeSMWPropertyID($property); } foreach ($semanticData->getPropertyValues($property) as $dataItem) { if ($dataItem instanceof DIError) { // ignore error values continue; } if (!array_key_exists($propertyTable->getName(), $updates)) { $updates[$propertyTable->getName()] = array(); } $dataItemValues = $this->store->getDataItemHandlerForDIType($dataItem->getDIType())->getInsertValues($dataItem); // Ensure that the sortkey is a string if (isset($dataItemValues['o_sortkey'])) { $dataItemValues['o_sortkey'] = (string) $dataItemValues['o_sortkey']; } // Make sure to build a unique set without duplicates which could happen // if an annotation is made to a property that has a redirect pointing // to the same p_id $insertValues = array_merge($insertValues, $dataItemValues); $insertValuesHash = md5(implode('#', $insertValues)); $updates[$propertyTable->getName()][$insertValuesHash] = $insertValues; } } // Special handling of Concepts if ($subject->getNamespace() === SMW_NS_CONCEPT && $subject->getSubobjectName() == '') { $this->fetchConceptTableInserts($sid, $updates); } return $updates; }
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; }
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 doRealUpdate() { $this->store->setUpdateJobsEnabledState($this->enabledWithUpdateJobs); $semanticData = $this->checkForRequiredRedirectUpdate($this->semanticData); $subject = $semanticData->getSubject(); if ($this->processSemantics) { $this->store->updateData($semanticData); } elseif ($this->store->getObjectIds()->hasIDFor($subject)) { // Only clear the data where it is know that "hasIDFor" is true otherwise // an empty entity is created and later being removed by the // "PropertyTableOutdatedReferenceDisposer" since it is an entity that is // empty == has no reference $this->store->clearData($subject); } return true; }
/** * @since 1.9 * * @return array */ protected function doQuery() { Profiler::In(__METHOD__); // the query needs to do the filtering of internal properties, else LIMIT is wrong $options = array('ORDER BY' => 'smw_sortkey'); if ($this->requestOptions !== null) { if ($this->requestOptions->limit > 0) { $options['LIMIT'] = $this->requestOptions->limit; $options['OFFSET'] = max($this->requestOptions->offset, 0); } } $conditions = array('smw_namespace' => SMW_NS_PROPERTY, 'smw_iw' => ''); $conditions['usage_count'] = 0; $res = $this->dbConnection->select(array($this->store->getObjectIds()->getIdTable(), $this->store->getStatisticsTable()), array('smw_title', 'usage_count'), $conditions, __METHOD__, $options, array($this->store->getObjectIds()->getIdTable() => array('INNER JOIN', array('smw_id=p_id')))); Profiler::Out(__METHOD__); return $res; }
private function modifyEntityList($fieldChangeOp, &$affiliateEntityList, &$combinedChangedEntityList) { $key = ''; if ($fieldChangeOp->has('key')) { $key = $fieldChangeOp->get('key'); } elseif ($fieldChangeOp->has('p_id')) { $dataItem = $this->store->getObjectIds()->getDataItemById($fieldChangeOp->get('p_id')); $key = $dataItem !== null ? $dataItem->getDBKey() : null; } // Exclusion before inclusion if (isset($this->propertyExemptionlist[$key])) { $this->unsetEntityList($fieldChangeOp, $combinedChangedEntityList); return; } if (isset($this->affiliatePropertyDetectionlist[$key]) && $fieldChangeOp->has('s_id')) { $affiliateEntityList[$fieldChangeOp->get('s_id')] = true; } }
/** * Finds a partial list (given limit and offset) of registered subjects that * that represent a dependency on something like a subject in a query list, * a property, or a printrequest. * * `s_id` contains the subject id that links to the query that fulfills one * of the conditions cited above. * * Prefetched Ids are turned into a hash list that can later be split into * chunks to work either in online or batch mode without creating a huge memory * foothold. * * @note Select a list is crucial for performance as any selectRow would / * single Id select would strain the system on large list connected to a * query * * @since 2.3 * * @param array $idlist * @param RequestOptions $requestOptions * * @return array */ public function findEmbeddedQueryTargetLinksHashListFor(array $idlist, RequestOptions $requestOptions) { if ($idlist === array() || !$this->isEnabled()) { return array(); } $options = array('LIMIT' => $requestOptions->getLimit(), 'OFFSET' => $requestOptions->getOffset(), 'GROUP BY' => 's_id', 'ORDER BY' => 's_id', 'DISTINCT' => true); $conditions = array('o_id' => $idlist); foreach ($requestOptions->getExtraConditions() as $extraCondition) { $conditions += $extraCondition; } $rows = $this->connection->select(SQLStore::QUERY_LINKS_TABLE, array('s_id'), $conditions, __METHOD__, $options); $targetLinksIdList = array(); foreach ($rows as $row) { $targetLinksIdList[] = $row->s_id; } if ($targetLinksIdList === array()) { return array(); } return $this->store->getObjectIds()->getDataItemPoolHashListFor($targetLinksIdList); }
/** * @since 2.3 */ public function getObjectIds() { return $this->baseStore->getObjectIds(); }
/** * @since 2.2 * * @return number */ public function getImproperValueForCount() { return $this->propertyStatisticsStore->getUsageCount($this->store->getObjectIds()->getSMWPropertyID(new DIProperty('_ERRP'))); }
/** * @since 2.4 * * @param DIWikiPage $subject, $subobjectName * @param string $subobjectName */ public function createId(DIWikiPage $subject, $subobjectName = '') { $id = $this->store->getObjectIds()->makeSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subobjectName, false); wfDebugLog('smw', __METHOD__ . " add new {$id} ID for " . $subject->getHash() . " {$subobjectName}"); return $id; }
public function getIdForSubject(DIWikiPage $subject, $subobjectName = '') { return $this->store->getObjectIds()->getSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subobjectName, false); }