private function hasReferenceByTable($proptable, $id) { $row = false; $db = $this->store->getConnection('mw.db'); if ($proptable->usesIdSubject()) { $row = $db->selectRow($proptable->getName(), array('s_id'), array('s_id' => $id), __METHOD__); } if ($row !== false) { return true; } $fields = $proptable->getFields($this->store); // Check whether an object reference exists or not if (isset($fields['o_id'])) { $row = $db->selectRow($proptable->getName(), array('o_id'), array('o_id' => $id), __METHOD__); } // If the property table is not a fixed table (== assigns a whole // table to a specific property with the p_id column being suppressed) // then check for the p_id field if ($row === false && !$proptable->isFixedPropertyTable()) { $row = $db->selectRow($proptable->getName(), array('p_id'), array('p_id' => $id), __METHOD__); } // If the query table contains a reference then we keep the object (could // be a subject, property, or printrequest) where in case the query is // removed the object will also loose its reference if ($row === false) { $row = $db->selectRow(SQLStore::QUERY_LINKS_TABLE, array('o_id'), array('o_id' => $id), __METHOD__); } return $row !== false; }
/** * @param \PublicAccessManager $publicAccessManager * @param array $messages * @return mixed */ public function getJsonData($publicAccessManager, $messages) { $jsonData = parent::getJsonData($publicAccessManager, $messages); $ocsStore = new SQLStore(); $invitations = $ocsStore->invitationsForLink($this->getHash()); if (count($invitations)) { $jsonData["invitation"] = array_shift($invitations)->jsonSerialize(); } return $jsonData; }
private function findReferenceByPropertyTable($proptable, $id) { $row = false; if ($proptable->usesIdSubject()) { $row = $this->connection->selectRow($proptable->getName(), array('s_id'), array('s_id' => $id), __METHOD__); } if ($row !== false) { return $row; } $fields = $proptable->getFields($this->store); // Check whether an object reference exists or not if (isset($fields['o_id'])) { // This next time someone ... I'm going to Alaska $field = strpos($proptable->getName(), 'redi') ? array('s_title', 's_namespace') : array('s_id'); $row = $this->connection->selectRow($proptable->getName(), $field, array('o_id' => $id), __METHOD__); if ($row !== false && strpos($proptable->getName(), 'redi')) { $row->s_id = $this->store->getObjectIds()->findRedirectIdFor($row->s_title, $row->s_namespace); } } // If the property table is not a fixed table (== assigns a whole // table to a specific property with the p_id column being suppressed) // then check for the p_id field if ($row === false && !$proptable->isFixedPropertyTable()) { $row = $this->connection->selectRow($proptable->getName(), array('s_id'), array('p_id' => $id), __METHOD__); } // If the query table contains a reference then we keep the object (could // be a subject, property, or printrequest) where in case the query is // removed the object will also loose its reference if ($row === false) { $row = $this->connection->selectRow(SQLStore::QUERY_LINKS_TABLE, array('s_id'), array('o_id' => $id), __METHOD__); } return $row; }
private function getSortKeyForItem($item) { if ($item instanceof DIWikiPage) { $label = $this->store->getWikiPageSortKey($item); $value = $label; } else { $label = $item instanceof DIBlob ? $item->getString() : ''; $value = $item->getSortKey(); } return array($label, $value); }
private function triggerResetCacheEventBy($id) { $subject = $this->store->getObjectIds()->getDataItemById($id); if (!$subject instanceof DIWikiPage) { return; } $eventHandler = EventHandler::getInstance(); $dispatchContext = $eventHandler->newDispatchContext(); $dispatchContext->set('subject', $subject); $eventHandler->getEventDispatcher()->dispatch('cached.propertyvalues.prefetcher.reset', $dispatchContext); $eventHandler->getEventDispatcher()->dispatch('property.specification.change', $dispatchContext); $eventHandler->getEventDispatcher()->dispatch('factbox.cache.delete', $dispatchContext); }
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 hasReferenceInPropertyTable($proptable, $id) { $row = false; $db = $this->store->getConnection('mw.db'); if ($proptable->usesIdSubject()) { $row = $db->selectRow($proptable->getName(), array('s_id'), array('s_id' => $id), __METHOD__); } if ($row !== false) { return true; } $fields = $proptable->getFields($this->store); // Check whether an object reference exists or not if (isset($fields['o_id'])) { $row = $db->selectRow($proptable->getName(), array('o_id'), array('o_id' => $id), __METHOD__); } // If the property table is not a fixed table (== assigns a whole // table to a specific property with the p_id column being suppressed) // then check for the p_id field if ($row === false && !$proptable->isFixedPropertyTable()) { $row = $db->selectRow($proptable->getName(), array('p_id'), array('p_id' => $id), __METHOD__); } return $row !== false; }
/** * @since 2.5 * * @return Table[] */ public function getTables() { if ($this->tables !== array()) { return $this->tables; } $this->addTable($this->newEntityIdTable()); $this->addTable($this->newConceptCacheTable()); $this->addTable($this->newQueryLinksTable()); $this->addTable($this->newFulltextSearchTable()); $this->addTable($this->newPropertyStatisticsTable()); foreach ($this->store->getPropertyTables() as $propertyTable) { // Only extensions that aren't setup correctly can force an exception // and to avoid a failure during setup, ensure that standard tables // are correctly initialized otherwise SMW can't recover try { $diHandler = $this->store->getDataItemHandlerForDIType($propertyTable->getDiType()); } catch (\Exception $e) { continue; } $this->addTable($this->newPropertyTable($propertyTable, $diHandler)); } return $this->tables; }
private function doCheckPredefinedPropertyBorder($connection) { // Check if we already have this structure $expectedID = SQLStore::FIXED_PROPERTY_ID_UPPERBOUND; $currentID = $connection->selectRow(SQLStore::ID_TABLE, 'smw_id', 'smw_iw=' . $connection->addQuotes(SMW_SQL3_SMWBORDERIW)); if ($currentID !== false && $currentID->smw_id == $expectedID) { return $this->messageReporter->reportMessage(" ... space for internal properties already allocated.\n"); } // Legacy bound $currentID = $currentID === false ? 50 : $currentID->smw_id; $this->messageReporter->reportMessage(" ... allocating space for internal properties ...\n"); $this->store->getObjectIds()->moveSMWPageID($expectedID); $connection->insert(SQLStore::ID_TABLE, array('smw_id' => $expectedID, 'smw_title' => '', 'smw_namespace' => 0, 'smw_iw' => SMW_SQL3_SMWBORDERIW, 'smw_subobject' => '', 'smw_sortkey' => ''), __METHOD__); $this->messageReporter->reportMessage(" ... moving from {$currentID} to {$expectedID} "); // make way for built-in ids for ($i = $currentID; $i < $expectedID; $i++) { $this->store->getObjectIds()->moveSMWPageID($i); $this->messageReporter->reportMessage('.'); } $this->messageReporter->reportMessage("\n ... done.\n"); }
/** * Not in all cases can requestoptions be forwarded to the DB using * getSQLConditions() and getSQLOptions(): some data comes from caches * that do not respect the options yet. This method takes an array of * results (SMWDataItem objects) *of the same type* and applies the * given requestoptions as appropriate. * * @since 1.8 * @param array $data array of SMWDataItem objects * @param SMWRequestOptions|null $requestoptions * * @return SMWDataItem[] */ public function applyRequestOptionsTo(array $data, RequestOptions $requestoptions = null) { if ($data === array() || $requestoptions === null) { return $data; } $result = array(); $sortres = array(); $sampleDataItem = reset($data); $numeric = is_numeric($sampleDataItem->getSortKey()); $i = 0; foreach ($data as $item) { $ok = true; // keep datavalue only if this remains true if ($item instanceof DIWikiPage) { $label = $this->store->getWikiPageSortKey($item); $value = $label; } else { $label = $item instanceof DIBlob ? $item->getString() : ''; $value = $item->getSortKey(); } if ($requestoptions->boundary !== null) { // apply value boundary $strc = $numeric ? 0 : strcmp($value, $requestoptions->boundary); if ($requestoptions->ascending) { if ($requestoptions->include_boundary) { $ok = $numeric ? $value >= $requestoptions->boundary : $strc >= 0; } else { $ok = $numeric ? $value > $requestoptions->boundary : $strc > 0; } } else { if ($requestoptions->include_boundary) { $ok = $numeric ? $value <= $requestoptions->boundary : $strc <= 0; } else { $ok = $numeric ? $value < $requestoptions->boundary : $strc < 0; } } } foreach ($requestoptions->getStringConditions() as $strcond) { // apply string conditions switch ($strcond->condition) { case StringCondition::STRCOND_PRE: $ok = $ok && strpos($label, $strcond->string) === 0; break; case StringCondition::STRCOND_POST: $ok = $ok && strpos(strrev($label), strrev($strcond->string)) === 0; break; case StringCondition::STRCOND_MID: $ok = $ok && strpos($label, $strcond->string) !== false; break; } } if ($ok) { $result[$i] = $item; $sortres[$i] = $value; $i++; } } if ($requestoptions->sort) { $flag = $numeric ? SORT_NUMERIC : SORT_LOCALE_STRING; if ($requestoptions->ascending) { asort($sortres, $flag); } else { arsort($sortres, $flag); } $newres = array(); foreach ($sortres as $key => $value) { $newres[] = $result[$key]; } $result = $newres; } if ($requestoptions->limit > 0) { $result = array_slice($result, $requestoptions->offset, $requestoptions->limit); } else { $result = array_slice($result, $requestoptions->offset); } return $result; }
/** * Method to return the fields for this table * * @since 1.8 * * @param SQLStore $store * * @return array */ public function getFields(SQLStore $store) { $diHandler = $store->getDataItemHandlerForDIType($this->diType); return $diHandler->getTableFields(); }