Ejemplo n.º 1
0
 /**
  * Delete all semantic data stored for the given subject. Used for
  * update purposes.
  *
  * @param $subject SMWDIWikiPage the data of which is deleted
  */
 protected function deleteSemanticData(SMWDIWikiPage $subject)
 {
     if ($subject->getSubobjectName() !== '') {
         return;
     }
     // not needed, and would mess up data
     $db = wfGetDB(DB_MASTER);
     $id = $this->getSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), '', false);
     if ($id == 0) {
         // not (directly) used anywhere yet, may be a redirect but we do not care here
         wfRunHooks('smwDeleteSemanticData', array($subject));
         return;
     }
     foreach (self::getPropertyTables() as $proptable) {
         if ($proptable->name == 'smw_conc2') {
             continue;
         }
         // skip concepts, since they have chache data in their table which should be kept while the cache is intact
         if ($proptable->idsubject) {
             $db->delete($proptable->name, array('s_id' => $id), __METHOD__);
         } elseif ($proptable->name != 'smw_redi2') {
             /// NOTE: redirects are handled by updateRedirects(), not here!
             $db->delete($proptable->name, array('s_title' => $subject->getDBkey(), 's_namespace' => $subject->getNamespace()), __METHOD__);
         }
     }
     // also find subobjects used by this ID ...
     $res = $db->select('smw_ids', '*', 'smw_title = ' . $db->addQuotes($subject->getDBkey()) . ' AND ' . 'smw_namespace = ' . $db->addQuotes($subject->getNamespace()) . ' AND ' . 'smw_iw = ' . $db->addQuotes($subject->getInterwiki()) . ' AND ' . 'smw_subobject != ' . $db->addQuotes(''), __METHOD__);
     $subobjects = array();
     // ... and delete them as well
     foreach ($res as $row) {
         $subobjects[] = $row->smw_id;
         $this->m_idCache->setId($row->smw_title, $row->smw_namespace, $row->smw_iw, $row->smw_subobject, 0);
         // deleted below
         foreach (self::getPropertyTables() as $proptable) {
             if ($proptable->idsubject) {
                 $db->delete($proptable->name, array('s_id' => $row->smw_id), __METHOD__);
             }
         }
     }
     $db->freeResult($res);
     // free all affected subobjects in one call:
     if (count($subobjects) > 0) {
         $db->delete('smw_ids', array('smw_id' => $subobjects), __METHOD__);
     }
     wfRunHooks('smwDeleteSemanticData', array($subject));
 }
Ejemplo n.º 2
0
 /**
  * Method to get all subobjects for a given subject.
  *
  * @since 1.8
  * @param SMWDIWikiPage $subject
  * @param DatabaseBase $dbr only used for reading
  * @return array of smw_id => SMWDIWikiPage
  */
 protected function getSubobjects(SMWDIWikiPage $subject, DatabaseBase $dbr)
 {
     $res = $dbr->select(SMWSql3SmwIds::tableName, 'smw_id,smw_subobject', 'smw_title = ' . $dbr->addQuotes($subject->getDBkey()) . ' AND ' . 'smw_namespace = ' . $dbr->addQuotes($subject->getNamespace()) . ' AND ' . 'smw_iw = ' . $dbr->addQuotes($subject->getInterwiki()) . ' AND ' . 'smw_subobject != ' . $dbr->addQuotes(''), __METHOD__);
     $diHandler = $this->store->getDataItemHandlerForDIType(SMWDataItem::TYPE_WIKIPAGE);
     $subobjects = array();
     foreach ($res as $row) {
         $subobjects[$row->smw_id] = $diHandler->dataItemFromDBKeys(array($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), '', $row->smw_subobject));
     }
     $dbr->freeResult($res);
     return $subobjects;
 }
 /**
  * @see SMWStore::getProperties
  *
  * @param SMWDIWikiPage $subject
  * @param SMWRequestOptions $requestoptions
  */
 public function getProperties(SMWDIWikiPage $subject, $requestoptions = null)
 {
     wfProfileIn("SMWSQLStore3::getProperties (SMW)");
     $sid = $this->store->smwIds->getSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName());
     if ($sid == 0) {
         // no id, no page, no properties
         wfProfileOut("SMWSQLStore3::getProperties (SMW)");
         return array();
     }
     $db = wfGetDB(DB_SLAVE);
     $result = array();
     if ($requestoptions !== null) {
         // potentially need to get more results, since options apply to union
         $suboptions = clone $requestoptions;
         $suboptions->limit = $requestoptions->limit + $requestoptions->offset;
         $suboptions->offset = 0;
     } else {
         $suboptions = null;
     }
     foreach (SMWSQLStore3::getPropertyTables() as $proptable) {
         $from = $db->tableName($proptable->name);
         if ($proptable->idsubject) {
             $where = 's_id=' . $db->addQuotes($sid);
         } elseif ($subject->getInterwiki() === '') {
             $where = 's_title=' . $db->addQuotes($subject->getDBkey()) . ' AND s_namespace=' . $db->addQuotes($subject->getNamespace());
         } else {
             // subjects with non-emtpy interwiki cannot have properties
             continue;
         }
         if ($proptable->fixedproperty == false) {
             // select all properties
             $from .= " INNER JOIN " . $db->tableName('smw_ids') . " ON smw_id=p_id";
             $res = $db->select($from, 'DISTINCT smw_title,smw_sortkey', $where . $this->store->getSQLConditions($suboptions, 'smw_sortkey', 'smw_sortkey'), 'SMW::getProperties', $this->store->getSQLOptions($suboptions, 'smw_sortkey'));
             foreach ($res as $row) {
                 $result[] = new SMWDIProperty($row->smw_title);
             }
         } else {
             // just check if subject occurs in table
             $res = $db->select($from, '*', $where, 'SMW::getProperties', array('LIMIT' => 1));
             if ($db->numRows($res) > 0) {
                 $result[] = new SMWDIProperty($proptable->fixedproperty);
             }
         }
         $db->freeResult($res);
     }
     $result = $this->store->applyRequestOptions($result, $requestoptions);
     // apply options to overall result
     wfProfileOut("SMWSQLStore3::getProperties (SMW)");
     return $result;
 }
 /**
  * Delete all semantic data stored for the given subject. Used for
  * update purposes. Handles Subobjects recursively
  *
  * @param $subject SMWDIWikiPage the data of which is deleted
  */
 public function deleteSemanticData(SMWDIWikiPage $subject)
 {
     $db = wfGetDB(DB_MASTER);
     $id = $this->store->smwIds->getSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName(), false, true);
     if ($id == 0) {
         // not (directly) used anywhere yet, may be a redirect but we do not care here
         wfRunHooks('smwDeleteSemanticData', array($subject));
         return;
     }
     //get oldData for diffing and updating property counts
     $oldData = $this->store->getSemanticData($subject);
     $this->doDiffandUpdateCount($oldData);
     $oldHashes = $this->store->smwIds->getPropertyTableHashes($id);
     foreach (SMWSQLStore3::getPropertyTables() as $tableId => $tableDeclaration) {
         $tableName = $tableDeclaration->name;
         if (array_key_exists($tableName, $oldHashes)) {
             $this->deleteTableSemanticData($id, $tableDeclaration);
         }
     }
     if ($subject->getSubobjectName() !== '') {
         wfRunHooks('smwDeleteSemanticData', array($subject));
         return;
         // Subobjects don't have subsubobjects
     }
     // also find subobjects used by this ID ...
     $oldSubobjects = $this->getSubobjects($subject);
     // ... and delete their data as well recursively
     foreach ($oldSubobjects as $subobject) {
         $this->deleteSemanticData($subobject);
     }
     //TODO: delete all unused subobjects
     wfRunHooks('smwDeleteSemanticData', array($subject));
 }