/** * 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; }
/** * Runs the whole rename process, schedules background jobs/tasks if needed. * * @return bool True if the process succeded */ public function run() { // Make sure the process will not be stopped in the middle set_time_limit(3600); //1h ignore_user_abort(true); ini_set("max_execution_time", 3600); //1h wfProfileIn(__METHOD__); if (!$this->setup()) { wfProfileOut(__METHOD__); return false; } // Execute the worker $status = false; try { $status = $this->doRun(); } catch (Exception $e) { $this->addLog($e->getMessage() . ' in ' . $e->getFile() . ' at line ' . $e->getLine()); $this->addError(wfMessage('userrenametool-error-cannot-rename-unexpected')->inContentLanguage()->text()); } // Analyze status if (!$status) { $problems = array_merge($this->mErrors, $this->mWarnings); $this->addMainLog("fail", RenameUserLogFormatter::fail($this->mRequestorName, $this->mOldUsername, $this->mNewUsername, $this->mReason)); } wfProfileOut(__METHOD__); return $status; }
/** * Runs the whole rename process, schedules background jobs/tasks if needed. * * @return bool True if the process succeded */ public function run() { // Make sure the process will not be stopped in the middle set_time_limit(3600); //1h ignore_user_abort(true); ini_set("max_execution_time", 3600); //1h wfProfileIn(__METHOD__); if (!$this->setup()) { wfProfileOut(__METHOD__); return false; } //create a new task for the Task Manager to store the logs for the global process $this->mGlobalTask = new UserRenameGlobalTask(); $this->mGlobalTask->createTask(array('requestor_id' => $this->mRequestorId, 'requestor_name' => $this->mRequestorName, 'rename_user_id' => $this->mUserId, 'rename_old_name' => $this->mOldUsername, 'rename_new_name' => $this->mNewUsername, 'reason' => $this->mReason, 'tasks' => array()), TASK_STARTED); $this->addLogDestination(self::LOG_BATCH_TASK, $this->mGlobalTask); $this->addLog("---USERNAMES LOG BEGIN---\n" . $this->getInternalLog() . "---USERNAMES LOG END---"); $tasks = array($this->mGlobalTask->getID()); // Put the starting line to log $this->addMainLog("start", RenameUserLogFormatter::start($this->mRequestorName, $this->mOldUsername, $this->mNewUsername, $this->mReason, $tasks)); // Execute the worker $status = false; try { $status = $this->doRun(); } catch (Exception $e) { $this->addError($e->getMessage() . ' in ' . $e->getFile() . ' at line ' . $e->getLine()); } $this->mGlobalTask->closeTask($status); // Analyze status if (!$status) { $problems = array_merge($this->mErrors, $this->mWarnings); $this->addMainLog("fail", RenameUserLogFormatter::fail($this->mRequestorName, $this->mOldUsername, $this->mNewUsername, $this->mReason, $tasks)); } return $status; }