/** * execute * * entry point for TaskExecutor * * @access public * @author Federico "Lox" Lucignano <*****@*****.**> * * @param mixed $params default null - task data from wikia_tasks table * * @return boolean - status of operation */ public function execute($params = null) { global $wgStatsDB, $wgStatsDBEnabled; //no working stats DB instance on devboxes if (!defined('ENV_DEVBOX') && !empty($wgStatsDBEnabled)) { $this->mParams = unserialize($params->task_arguments); $process = RenameUserProcess::newFromData(array_merge($this->mParams, array('local_task' => $this))); if (defined('ENV_DEVBOX')) { $process->addLogDestination(RenameUserProcess::LOG_BATCH_TASK, $this); } else { $process->setLogDestination(RenameUserProcess::LOG_BATCH_TASK, $this); } $process->addLog('Updating global shared database: stats'); $dbw = wfGetDB(DB_MASTER, array(), $wgStatsDB); $dbw->begin(); $tasks = $this->mParams['tasks']; $hookName = 'UserRename::Stats'; $process->addLog("Broadcasting hook: {$hookName}"); wfRunHooks($hookName, array($dbw, $this->mParams['rename_user_id'], $this->mParams['rename_old_name'], $this->mParams['rename_new_name'], $this, &$tasks)); foreach ($tasks as $task) { $process->addLog("Updating stats: {$task['table']}:{$task['username_column']}"); $process->renameInTable($dbw, $task['table'], $this->mParams['rename_user_id'], $this->mParams['rename_old_name'], $this->mParams['rename_new_name'], $task); } $hookName = 'UserRename::AfterStats'; $process->addLog("Broadcasting hook: {$hookName}"); wfRunHooks($hookName, array($dbw, $this->mParams['rename_user_id'], $this->mParams['rename_old_name'], $this->mParams['rename_new_name'], $this, &$tasks)); $dbw->commit(); $process->addLog('Finished updating shared database: stats'); } return true; }
/** * Marshal & execute the RenameUserProcess functions to rename a user * * @param array $wikiCityIds * @param array $params * requestor_id => ID of the user requesting this rename action * requestor_name => Name of the user requesting this rename action * rename_user_id => ID of the user to rename * rename_old_name => Current username of the user to rename * rename_new_name => New username for the user to rename * reason => Reason for requesting username change * rename_fake_user_id => Repeated rename process special case (TODO: Don't know what this is) * phalanx_block_id => Phalanx login block ID * @return bool */ public function renameUser(array $wikiCityIds, array $params) { global $IP; $renameIP = !empty($params['rename_ip']); $loadBalancerFactory = wfGetLBFactory(); $process = RenameUserProcess::newFromData($params); $process->setLogDestination(\RenameUserProcess::LOG_BATCH_TASK, $this); $process->setRequestorUser(); $noErrors = true; // ComSup wants the StaffLogger to keep track of renames... $this->staffLog('start', $params, \RenameUserLogFormatter::start($params['requestor_name'], $params['rename_old_name'], $params['rename_new_name'], $params['reason'], [$this->getTaskId()])); try { foreach ($wikiCityIds as $cityId) { /** * execute maintenance script */ $cmd = sprintf("SERVER_ID=%s php {$IP}/maintenance/wikia/RenameUser_local.php", $cityId); $opts = ['rename-user-id' => $params['rename_user_id'], 'requestor-id' => $params['requestor_id'], 'reason' => $params['reason']]; if ($renameIP) { $opts['rename-old-name'] = $params['rename_old_name']; $opts['rename-new-name'] = $params['rename_new_name']; } else { $opts['rename-old-name-enc'] = rawurlencode($params['rename_old_name']); $opts['rename-new-name-enc'] = rawurlencode($params['rename_new_name']); $opts['rename-fake-user-id'] = $params['rename_fake_user_id']; $opts['phalanx-block-id'] = $params['phalanx_block_id']; } foreach ($opts as $opt => $val) { $cmd .= sprintf(' --%s %s', $opt, escapeshellarg($val)); } if ($renameIP) { $cmd .= ' --rename-ip-address'; } $exitCode = null; $output = wfShellExec($cmd, $exitCode); $logMessage = sprintf("Rename user %s to %s on city id %s", $params['rename_old_name'], $params['rename_new_name'], $cityId); $logContext = ['command' => $cmd, 'exitStatus' => $exitCode, 'output' => $output]; if ($exitCode > 0) { $this->error($logMessage, $logContext); $noErrors = false; } else { $this->info($logMessage, $logContext); } $this->staffLog('log', $params, \RenameUserLogFormatter::wiki($params['requestor_name'], $params['rename_old_name'], $params['rename_new_name'], $cityId, $params['reason'], $exitCode > 0)); $loadBalancerFactory->forEachLBCallMethod('commitMasterChanges'); $loadBalancerFactory->forEachLBCallMethod('closeAll'); } } catch (Exception $e) { $noErrors = false; $this->error("error while renaming user", ['message' => $e->getMessage(), 'stack' => $e->getTraceAsString()]); } // clean up pre-process setup $process->cleanup(); $this->notifyUser(\User::newFromId($params['requestor_id']), $params['rename_old_name'], $params['rename_new_name']); if (!$renameIP) { //mark user as renamed $renamedUser = \User::newFromName($params['rename_new_name']); $renamedUser->setGlobalFlag('wasRenamed', true); $renamedUser->saveSettings(); if ($params['notify_renamed']) { //send e-mail to the user that rename process has finished $this->notifyUser($renamedUser, $params['rename_old_name'], $params['rename_new_name']); } } if ($noErrors) { $this->staffLog('finish', $params, \RenameUserLogFormatter::finish($params['requestor_name'], $params['rename_old_name'], $params['rename_new_name'], $params['reason'], [$this->getTaskId()])); } else { $this->staffLog('fail', $params, \RenameUserLogFormatter::fail($params['requestor_name'], $params['rename_old_name'], $params['rename_new_name'], $params['reason'], [$this->getTaskId()])); } return $noErrors; }
$processData['rename_fake_user_id'] = (int) $options['rename-fake-user-id']; } if (!empty($options['requestor-id']) && is_numeric($options['requestor-id'])) { $processData['requestor_id'] = (int) $options['requestor-id']; } if (!empty($options['phalanx-block-id']) && is_numeric($options['phalanx-block-id'])) { $processData['phalanx_block_id'] = (int) $options['phalanx-block-id']; } if (!empty($options['reason'])) { $processData['reason'] = $options['reason']; } if (!empty($options['global-task-id']) && is_numeric($options['global-task-id'])) { $processData['global_task_id'] = (int) $options['global-task-id']; } require_once "{$IP}/extensions/wikia/UserRenameTool/SpecialRenameuser.php"; $process = RenameUserProcess::newFromData($processData); $process->setLogDestination(RenameUserProcess::LOG_OUTPUT); if ($taskId) { $runningTask = UserRenameLocalTask::newFromID($taskId); if (defined('ENV_DEVBOX')) { $process->addLogDestination(RenameUserProcess::LOG_BATCH_TASK, $runningTask); } else { $process->setLogDestination(RenameUserProcess::LOG_BATCH_TASK, $runningTask); } } $process->setRequestorUser(); try { if (isset($options['rename-ip-address'])) { $process->updateLocalIP(); } else { $process->updateLocal();
/** * execute * * entry point for TaskExecutor * * @access public * @author Federico "Lox" Lucignano <*****@*****.**> * * @param mixed $params default null - task data from wikia_tasks table * * @return boolean - status of operation */ public function execute($params = null) { global $IP, $wgWikiaLocalSettingsPath, $wgWikiaAdminSettingsPath, $wgMaxShellMemory, $wgMaxShellTime; $wgMaxShellMemory = 0; $wgMaxShellTime = 0; $this->mParams = unserialize($params->task_arguments); $noErrors = true; $process = RenameUserProcess::newFromData(array_merge($this->mParams, array('local_task' => $this))); if (defined('ENV_DEVBOX')) { $process->addLogDestination(RenameUserProcess::LOG_BATCH_TASK, $this); } else { $process->setLogDestination(RenameUserProcess::LOG_BATCH_TASK, $this); } //$process->setRequestorUser(); $process->addLog('User rename local task start.'); $oldUsername = $this->mParams['rename_old_name']; $newUsername = $this->mParams['rename_new_name']; $requestorID = (int) $this->mParams['requestor_id']; $notifyRenamed = $this->mParams['notify_renamed']; foreach ($this->mParams as $key => &$param) { if ($key == 'city_ids') { continue; } if (empty($param)) { $param = "'{$param}'"; } else { $param = escapeshellarg($param); } } if (is_array($this->mParams['city_ids'])) { foreach ($this->mParams['city_ids'] as $cityId) { $process->addLog("Processing wiki with ID {$cityId}."); /** * execute maintenance script */ $aconf = $wgWikiaAdminSettingsPath; if (defined('ENV_DEVBOX') && ENV_DEVBOX) { $aconf = preg_replace("/\\.\\.\\//", "", $aconf); } $cmd = "SERVER_ID={$cityId} php {$IP}/maintenance/wikia/RenameUser_local.php " . "--rename-user-id {$this->mParams['rename_user_id']} --rename-old-name {$this->mParams['rename_old_name']} " . "--rename-new-name {$this->mParams['rename_new_name']} --rename-fake-user-id {$this->mParams['rename_fake_user_id']} " . "--phalanx-block-id {$this->mParams['phalanx_block_id']} " . "--task-id {$this->mTaskID} --requestor-id {$this->mParams['requestor_id']} --reason {$this->mParams['reason']} " . "--global-task-id {$this->mParams['global_task_id']} --conf {$wgWikiaLocalSettingsPath} --aconf {$aconf}"; $this->addLog("Running {$cmd}"); $exitCode = null; $output = wfShellExec($cmd, $exitCode); if ($exitCode == 1) { $noErrors = false; } $this->addLog("--- Command output ---\n{$output}\n--- End of command output ---"); $process->addLog("Finished processing wiki with ID {$cityId}."); } } $process->addLog("Cleaning up pre-process setup."); $process->cleanup(); $process->addLog("Fetching email addresses for notification of completed process."); $requestorUser = User::newFromId($requestorID); //mark user as renamed $renamedUser = User::newFromName($newUsername); $renamedUser->setOption('wasRenamed', true); $renamedUser->saveSettings(); //send e-mail to the user that rename process has finished $notify = array($requestorUser); if ($notifyRenamed) { $notify[] = $renamedUser; } foreach ($notify as $notifyUser) { if ($notifyUser->getEmail() != null) { $notifyUser->sendMail(wfMsgForContent('userrenametool-finished-email-subject', $oldUsername), wfMsgForContent('userrenametool-finished-email-body-text', $oldUsername, $newUsername), null, null, 'UserRenameProcessFinishedNotification', wfMsgForContent('userrenametool-finished-email-body-html', $oldUsername, $newUsername)); $process->addLog("Notification sent."); } else { $process->addLog("Cannot send email, requestor user has no email address."); } } $process->addLog("User rename local task end."); return $noErrors; }