Beispiel #1
0
 /**
  * Normalize the information for an SMW object (page etc.) and return
  * the predefined ID if any. All parameters are call-by-reference and
  * will be changed to perform any kind of built-in normalization that
  * SMW requires. This mainly applies to predefined properties that
  * should always use their property key as a title, have fixed
  * sortkeys, etc. Some very special properties also have fixed IDs that
  * do not require any DB lookups. In such cases, the method returns
  * this ID; otherwise it returns 0.
  *
  * @note This function could be extended to account for further kinds
  * of normalization and predefined ID. However, both getSMWPropertyID
  * and makeSMWPropertyID must then also be adjusted to do the same.
  *
  * @since 1.8
  * @param string $title DB key
  * @param integer $namespace namespace
  * @param string $iw interwiki prefix
  * @param string $subobjectName
  * @param string $sortkey
  * @return integer predefined id or 0 if none
  */
 protected function getPredefinedData(&$title, &$namespace, &$iw, &$subobjectName, &$sortkey)
 {
     if ($namespace == SMW_NS_PROPERTY && ($iw === '' || $iw == SMW_SQL3_SMWINTDEFIW) && $title != '') {
         // Check if this is a predefined property:
         if ($title[0] != '_') {
             // This normalization also applies to
             // subobjects of predefined properties.
             $newTitle = SMWDIProperty::findPropertyID(str_replace('_', ' ', $title));
             if ($newTitle) {
                 $title = $newTitle;
                 $sortkey = SMWDIProperty::findPropertyLabel($title);
                 if ($sortkey === '') {
                     $iw = SMW_SQL3_SMWINTDEFIW;
                 }
             }
         }
         // Check if this is a property with a fixed SMW ID:
         if ($subobjectName === '' && array_key_exists($title, self::$special_ids)) {
             return self::$special_ids[$title];
         }
     }
     return 0;
 }
 /**
  * @see SMWStore::refreshData
  *
  * @todo This method will be overhauled in SMW 1.9 to become cleaner
  * and more robust.
  *
  * @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)) {
             // wikia change start - jobqueue migration
             $task = new \Wikia\Tasks\Tasks\JobWrapperTask();
             $task->call('SMWUpdateJob', $title);
             $updatejobs[] = $task;
             // wikia change end
             $emptyrange = false;
         }
     }
     // update by internal SMW id --> make sure we get all objects in SMW
     $dbr = wfGetDB(DB_SLAVE, 'smw');
     $res = $dbr->select(SMWSql3SmwIds::tableName, 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;
         }
         // 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(' ', '_', SMWDIProperty::findPropertyLabel($row->smw_title));
         } else {
             $titleKey = '';
         }
         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) && $titleKey != '') {
             // 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, $titleKey);
             if ($title !== null && !$title->exists()) {
                 // wikia change start - jobqueue migration
                 $task = new \Wikia\Tasks\Tasks\JobWrapperTask();
                 $task->call('SMWUpdateJob', $title);
                 $updatejobs[] = $task;
                 // wikia change end
             }
         } elseif ($row->smw_iw == SMW_SQL3_SMWIW_OUTDATED) {
             // remove outdated internal object references
             $dbw = wfGetDB(DB_MASTER, 'smw');
             foreach (SMWSQLStore3::getPropertyTables() as $proptable) {
                 if ($proptable->usesIdSubject()) {
                     $dbw->delete($proptable->getName(), array('s_id' => $row->smw_id), __METHOD__);
                 }
             }
             $dbw->delete(SMWSql3SmwIds::tableName, array('smw_id' => $row->smw_id), __METHOD__);
         } elseif ($titleKey != '') {
             // "normal" interwiki pages or outdated internal objects -- delete
             $diWikiPage = new SMWDIWikiPage($titleKey, $row->smw_namespace, $row->smw_iw);
             $emptySemanticData = new SMWSemanticData($diWikiPage);
             $this->store->doDataUpdate($emptySemanticData);
         }
     }
     $dbr->freeResult($res);
     wfRunHooks('smwRefreshDataJobs', array(&$updatejobs));
     if ($usejobs) {
         // wikia change start - jobqueue migration
         \Wikia\Tasks\Tasks\BaseTask::batch($updatejobs);
         // wikia change end
     } else {
         foreach ($updatejobs as $job) {
             // wikia change start - jobqueue migration
             /** @var \Wikia\Tasks\Tasks\JobWrapperTask $job */
             try {
                 $job->init();
             } catch (Exception $e) {
                 continue;
             }
             $job->wrap('SMWUpdateJob');
             // wikia change end
         }
     }
     $nextpos = $index + $count;
     // smw+ wikia change, handler to local database
     $dbl = wfGetDB(DB_SLAVE);
     if ($emptyrange) {
         // nothing found, check if there will be more pages later on
         $next1 = $dbl->selectField('page', 'page_id', "page_id >= {$nextpos}", __METHOD__, array('ORDER BY' => "page_id ASC"));
         $next2 = $dbr->selectField(SMWSql3SmwIds::tableName, 'smw_id', "smw_id >= {$nextpos}", __METHOD__, array('ORDER BY' => "smw_id ASC"));
         $nextpos = $next2 != 0 && $next2 < $next1 ? $next2 : $next1;
     }
     $max1 = $dbl->selectField('page', 'MAX(page_id)', '', __METHOD__);
     $max2 = $dbr->selectField(SMWSql3SmwIds::tableName, 'MAX(smw_id)', '', __METHOD__);
     $index = $nextpos ? $nextpos : -1;
     return $index > 0 ? $index / max($max1, $max2) : 1;
 }