/** * @see SMWStore::refreshData * * @param integer $index * @param integer $count * @param mixed $namespaces Array or false * @param boolean $usejobs * * @return decimal between 0 and 1 to indicate the overall progress of the refreshing */ public function refreshData(&$index, $count, $namespaces = false, $usejobs = true) { $updatejobs = array(); $emptyrange = true; // was nothing done in this run? // Update by MediaWiki page id --> make sure we get all pages. $tids = array(); // Array of ids for ($i = $index; $i < $index + $count; $i++) { $tids[] = $i; } $titles = Title::newFromIDs($tids); foreach ($titles as $title) { if ($namespaces == false || in_array($title->getNamespace(), $namespaces)) { $updatejobs[] = new SMWUpdateJob($title); $emptyrange = false; } } // update by internal SMW id --> make sure we get all objects in SMW $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('smw_ids', array('smw_id', 'smw_title', 'smw_namespace', 'smw_iw', 'smw_subobject'), array("smw_id >= {$index} ", " smw_id < " . $dbr->addQuotes($index + $count)), __METHOD__); foreach ($res as $row) { $emptyrange = false; // note this even if no jobs were created if ($namespaces && !in_array($row->smw_namespace, $namespaces)) { continue; } if ($row->smw_subobject !== '') { // leave subobjects alone; they ought to be changed with their pages } elseif ($row->smw_iw === '' || $row->smw_iw == SMW_SQL3_SMWREDIIW) { // objects representing pages // TODO: special treament 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, $row->smw_title); if ($title !== null && !$title->exists()) { $updatejobs[] = new SMWUpdateJob($title); } } elseif ($row->smw_iw == SMW_SQL3_SMWIW_OUTDATED) { // remove outdated internal object references foreach (SMWSQLStore3::getPropertyTables() as $proptable) { if ($proptable->idsubject) { $dbr->delete($proptable->name, array('s_id' => $row->smw_id), __METHOD__); } } $dbr->delete('smw_ids', array('smw_id' => $row->smw_id), __METHOD__); } else { // "normal" interwiki pages or outdated internal objects $diWikiPage = new SMWDIWikiPage($row->smw_title, $row->smw_namespace, $row->smw_iw); $this->store->getWriter()->deleteSemanticData($diWikiPage); } } $dbr->freeResult($res); wfRunHooks('smwRefreshDataJobs', array(&$updatejobs)); if ($usejobs) { Job::batchInsert($updatejobs); } else { foreach ($updatejobs as $job) { $job->run(); } } $nextpos = $index + $count; if ($emptyrange) { // nothing found, check if there will be more pages later on $next1 = $dbr->selectField('page', 'page_id', "page_id >= {$nextpos}", __METHOD__, array('ORDER BY' => "page_id ASC")); $next2 = $dbr->selectField('smw_ids', 'smw_id', "smw_id >= {$nextpos}", __METHOD__, array('ORDER BY' => "smw_id ASC")); $nextpos = $next2 != 0 && $next2 < $next1 ? $next2 : $next1; } $max1 = $dbr->selectField('page', 'MAX(page_id)', '', __METHOD__); $max2 = $dbr->selectField('smw_ids', 'MAX(smw_id)', '', __METHOD__); $index = $nextpos ? $nextpos : -1; return $index > 0 ? $index / max($max1, $max2) : 1; }