/** * Execute the action. * @param array command line parameters specific for this command */ public function run($args) { set_time_limit(0); if (!isset($args[0])) { $this->usageError('A username must be specified.'); } try { Yii::app()->user->userModel = User::getByUsername($args[0]); } catch (NotFoundException $e) { $this->usageError('The specified username does not exist.'); } $group = Group::getByName(Group::SUPER_ADMINISTRATORS_GROUP_NAME); if (!$group->users->contains(Yii::app()->user->userModel)) { $this->usageError('The specified user is not a super administrator.'); } if (!isset($args[1])) { $this->usageError('You must specify an action.'); } else { $upgradeStep = $args[1]; } if (isset($args[2])) { $doNotlAlterFiles = $args[2]; } else { $doNotlAlterFiles = 0; } if (isset($args[3])) { $this->interactive = $args[3]; } try { $template = "{message}\n"; $messageStreamer = new MessageStreamer($template); $messageStreamer->setExtraRenderBytes(0); if ($upgradeStep == 'runPart1') { $messageStreamer->add(Zurmo::t('Commands', 'Starting Zurmo upgrade process.')); $this->runPart1($messageStreamer, $doNotlAlterFiles); $messageStreamer->add(Zurmo::t('Commands', 'Zurmo upgrade phase 1 completed.')); $messageStreamer->add(Zurmo::t('Commands', 'Please execute next command: "{command}" to complete upgrade process.', array('{command}' => './zurmoc upgradeZurmo super runPart2'))); } elseif ($upgradeStep == 'runPart2') { if (UpgradeUtil::isUpgradeStateValid()) { $messageStreamer->add(Zurmo::t('Commands', 'Starting Zurmo upgrade process - phase 2.')); $this->runPart2($messageStreamer); $messageStreamer->add(Zurmo::t('Commands', 'Zurmo upgrade completed.')); } else { $message = 'Upgrade state is older then one day, please run phase one of the upgrade process again.'; throw new NotSupportedException($message); } } else { $this->usageError('Invalid step/action. Valid values are "runPart1" and "runPart2".'); } } catch (Exception $e) { $messageStreamer->add(Zurmo::t('Commands', 'An error occur during upgrade: {message}', array('{message}' => $e->getMessage()))); UpgradeUtil::unsetUpgradeState(); } }