/** * Update variables in WikiFactory * @param array $cities List of wikis to update flags * containg wikis IDs and values: True - is WDAC, False - is not WDAC * Struncture of param * $city = array( $cityId => $isDirectedAtCh ) */ public function updateWDACFlags($cities) { wfProfileIn(__METHOD__); foreach ($cities as $cityId => $isDirectedAtCh) { if ($isDirectedAtCh == WDACReviewSpecialController::FLAG_APPROVE) { WikiFactory::setVarById($this->byStaffVarId, $cityId, true, self::UPDATE_REASON); WikiFactory::removeVarById($this->byFounderVarId, $cityId, self::UPDATE_REASON); } elseif ($isDirectedAtCh == WDACReviewSpecialController::FLAG_DISAPPROVE) { WikiFactory::setVarById($this->byStaffVarId, $cityId, false, self::UPDATE_REASON); WikiFactory::removeVarById($this->byFounderVarId, $cityId, self::UPDATE_REASON); } } wfProfileOut(__METHOD__); }
public function execute() { $wikiFactory = new WikiFactory(); $varId = $wikiFactory->getVarIdByName(self::VAR_TO_SET); if ($varId === false) { throw new ErrorException('No such variable: ' . self::VAR_TO_SET); } $newTopWikiIds = $this->getTopWamWikiIds(self::TOP_NUMBER_OF_WIKIS); $oldTopWikiIds = array_keys($wikiFactory->getListOfWikisWithVar($varId, 'bool', '=', true)); foreach ($newTopWikiIds as $wikiId) { if (array_search($wikiId, $oldTopWikiIds) === false) { $wikiFactory->setVarById($varId, $wikiId, true, __METHOD__); echo '+' . $wikiId . PHP_EOL; } } foreach ($oldTopWikiIds as $wikiId) { if (array_search($wikiId, $newTopWikiIds) === false) { $wikiFactory->removeVarById($varId, $wikiId, __METHOD__); echo '-' . $wikiId . PHP_EOL; } } }
/** * addCustomSettings * * @author tor@wikia-inc.com * @param string $match * @param array $settings * @param string $type */ public function addCustomSettings($match, $settings, $type = 'unknown') { global $wgUser; wfProfileIn(__METHOD__); if ((!empty($match) || $type == 'universal') && isset($settings[$match]) && is_array($settings[$match])) { wfDebugLog("createwiki", __METHOD__ . ": Found '{$match}' in {$type} settings array \n", true); /** * switching user for correct logging */ $oldUser = $wgUser; $wgUser = User::newFromName('CreateWiki script'); foreach ($settings[$match] as $key => $value) { $success = WikiFactory::setVarById($key, $this->mNewWiki->city_id, $value); if ($success) { wfDebugLog("createwiki", __METHOD__ . ": Successfully added setting for {$this->mNewWiki->city_id}: {$key} = {$value}\n", true); } else { wfDebugLog("createwiki", __METHOD__ . ": Failed to add setting for {$this->mNewWiki->city_id}: {$key} = {$value}\n", true); } } $wgUser = $oldUser; wfDebugLog("createwiki", __METHOD__ . ": Finished adding {$type} settings\n", true); } else { wfDebugLog("createwiki", __METHOD__ . ": '{$match}' not found in {$type} settings array. Skipping this step.\n", true); } wfProfileOut(__METHOD__); return 1; }
<?php /** * Import WF variables into CSV. The CSV must take the following format: * wiki_id,variable_id,variable_value * NOTE: variable value _must_ be serialized. * @package MediaWiki * @addtopackage maintenance */ require_once "../../../../maintenance/commandLine.inc"; $rowCounter = 0; if (($handle = fopen($argv[0], 'r')) !== false) { while (($row = fgetcsv($handle)) !== false) { try { $wikiId = $row[0]; $variableId = $row[1]; $variableValue = $row[2]; if (($valArray = unserialize($variableValue)) !== false) { WikiFactory::setVarById($variableId, $wikiId, $valArray); } if ($rowCounter++ % 1000 == 0) { echo "{$rowCounter}\n"; } } catch (Exception $e) { echo "Problem with {$wikiId}: {$e}\n"; } } fclose($handle); } else { echo "{$argv[0]} could not be opened"; }