/** * @since 2.5 * * @param integer|stdClass $id */ public function executeWith($id) { if (is_int($id)) { return $this->propertyTableIdReferenceDisposer->cleanUpTableEntriesById($id); } $this->propertyTableIdReferenceDisposer->cleanUpTableEntriesByRow($id); }
/** * @param integer $id * @param UpdateJob[] &$updateJobs * @param bool $emptyRange */ private function createUpdateJobsForSmwIdRange($id, &$updateJobs, &$emptyRange) { // update by internal SMW id --> make sure we get all objects in SMW $db = $this->store->getConnection('mw.db'); $res = $db->select(\SMWSql3SmwIds::TABLE_NAME, array('smw_id', 'smw_title', 'smw_namespace', 'smw_iw', 'smw_subobject', 'smw_sortkey', 'smw_proptable_hash'), array("smw_id >= {$id} ", " smw_id < " . $db->addQuotes($id + $this->iterationLimit)), __METHOD__); foreach ($res as $row) { $emptyRange = false; // note this even if no jobs were created if ($this->namespaces && !in_array($row->smw_namespace, $this->namespaces)) { continue; } // Find page to refresh, even for special properties: if ($row->smw_title != '' && $row->smw_title[0] != '_') { $titleKey = $row->smw_title; } elseif ($row->smw_namespace == SMW_NS_PROPERTY && $row->smw_iw == '' && $row->smw_subobject == '') { $titleKey = str_replace(' ', '_', DIProperty::findPropertyLabel($row->smw_title)); } else { $titleKey = ''; } if ($row->smw_subobject !== '' && $row->smw_iw !== SMW_SQL3_SMWDELETEIW) { // leave subobjects alone; they ought to be changed with their pages $this->dispatchedEntities[] = array('s' => $row->smw_title . '#' . $row->smw_namespace . '#' . $row->smw_subobject); } elseif ($this->isPlainObjectValue($row)) { $this->propertyTableIdReferenceDisposer->removeOutdatedEntityReferencesById($row->smw_id); } elseif ($row->smw_iw === '' && $titleKey != '') { // objects representing pages $title = Title::makeTitleSafe($row->smw_namespace, $titleKey); if ($title !== null) { $this->dispatchedEntities[] = array('s' => $title->getPrefixedDBKey()); $updateJobs[] = $this->newUpdateJob($title); } } elseif ($row->smw_iw == SMW_SQL3_SMWREDIIW && $titleKey != '') { // TODO: special treatment of redirects needed, since the store will // not act on redirects that did not change according to its records $title = Title::makeTitleSafe($row->smw_namespace, $titleKey); if ($title !== null && !$title->exists()) { $this->dispatchedEntities[] = array('s' => $title->getPrefixedDBKey()); $updateJobs[] = $this->newUpdateJob($title); } } elseif ($row->smw_iw == SMW_SQL3_SMWIW_OUTDATED || $row->smw_iw == SMW_SQL3_SMWDELETEIW) { // remove outdated internal object references $this->propertyTableIdReferenceDisposer->cleanUpTableEntriesById($row->smw_id); } elseif ($titleKey != '') { // "normal" interwiki pages or outdated internal objects -- delete $diWikiPage = new DIWikiPage($titleKey, $row->smw_namespace, $row->smw_iw); $emptySemanticData = new SemanticData($diWikiPage); $this->store->updateData($emptySemanticData); $this->dispatchedEntities[] = array('s' => $diWikiPage); } if ($row->smw_namespace == SMW_NS_PROPERTY && $row->smw_iw == '' && $row->smw_subobject == '') { $this->markPossibleDuplicateProperties($row); } } $db->freeResult($res); }
public function testCleanUpTableEntriesFor() { $tableDefinition = $connection = $this->getMockBuilder('\\SMW\\SQLStore\\TableDefinition')->disableOriginalConstructor()->getMock(); $tableDefinition->expects($this->once())->method('usesIdSubject')->will($this->returnValue(true)); $connection = $this->getMockBuilder('\\SMW\\MediaWiki\\Database')->disableOriginalConstructor()->getMock(); $connection->expects($this->any())->method('selectRow')->will($this->returnValue(false)); $connection->expects($this->at(3))->method('delete')->with($this->equalTo(\SMW\SQLStore\SQLStore::ID_TABLE)); $this->store->expects($this->any())->method('getConnection')->will($this->returnValue($connection)); $this->store->expects($this->any())->method('getPropertyTables')->will($this->returnValue(array($tableDefinition))); $instance = new PropertyTableIdReferenceDisposer($this->store); $instance->cleanUpTableEntriesById(42); }