Esempio n. 1
0
 /**
  * Execute the action.
  * @param array command line parameters specific for this command
  */
 public function run($args)
 {
     set_time_limit('900');
     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.');
     }
     $startTime = microtime(true);
     $template = "{message}\n";
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->setExtraRenderBytes(0);
     $messageStreamer->add(Zurmo::t('Commands', 'Starting schema update process.'));
     $messageLogger = new MessageLogger($messageStreamer);
     InstallUtil::runAutoBuildFromUpdateSchemaCommand($messageLogger);
     $messageStreamer->add(Zurmo::t('Commands', 'Autobuild complete, rebuilding read permissions.'));
     if (SHOW_QUERY_DATA) {
         $messageStreamer->add(PageView::getTotalAndDuplicateQueryCountContent());
     }
     ReadPermissionsOptimizationUtil::rebuild();
     $messageStreamer->add(Zurmo::t('Commands', 'Rebuild read permissions complete.'));
     $endTime = microtime(true);
     $messageStreamer->add(Zurmo::t('Commands', 'Schema update complete.'));
     $messageStreamer->add(Zurmo::t('Commands', 'Total run time: {formattedTime} seconds.', array('{formattedTime}' => number_format($endTime - $startTime, 3))));
     if (SHOW_QUERY_DATA) {
         $messageStreamer->add(PageView::getTotalAndDuplicateQueryCountContent());
     }
 }
 /**
  * Execute the action
  * @param array $args - command line parameters specific for this command
  * @return int|void
  */
 public function run($args)
 {
     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('JobType must be provided and must be existing jobType!');
     } else {
         $jobType = $args[1];
     }
     $template = "{message}\n";
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->setExtraRenderBytes(0);
     $messageStreamer->add('');
     if ($jobType == 'All') {
         $messageStreamer->add("Reset all jobs.");
         $jobsInProcess = JobInProcess::getAll();
         if (is_array($jobsInProcess) && count($jobsInProcess) > 0) {
             foreach ($jobsInProcess as $jobInProcess) {
                 $jobInProcess->delete();
                 $messageStreamer->add("The job {$jobInProcess->type} has been reset.");
             }
         } else {
             $messageStreamer->add("There are no jobs in process to be reset.");
         }
     } else {
         $jobClassName = $jobType . 'Job';
         if (!@class_exists($jobClassName)) {
             $messageStreamer->add("Error! The {$jobClassName} does not exist.");
         } else {
             try {
                 $jobInProcess = JobInProcess::getByType($jobType);
                 $jobInProcess->delete();
                 $messageStreamer->add("The job {$jobClassName} has been reset.");
             } catch (NotFoundException $e) {
                 $messageStreamer->add("The job {$jobClassName} was not found to be stuck and therefore was not reset.");
             }
         }
     }
 }
Esempio n. 3
0
 /**
  * @see JobManagerCommand.  This method is called from the JobManagerCommand which is a commandline
  * tool to run jobs.  Based on the 'type' specified this method will call to run the monitor or a
  * regular non-monitor job.
  * @param string $type
  * @param timeLimit $timeLimit
  */
 public static function runFromJobManagerCommand($type, $timeLimit, $messageLoggerClassName)
 {
     assert('is_string($type)');
     assert('is_int($timeLimit)');
     assert('is_string($messageLoggerClassName) && (
                 is_subclass_of($messageLoggerClassName, "MessageLogger") ||
                 $messageLoggerClassName == "MessageLogger")');
     set_time_limit($timeLimit);
     $template = "{message}\n";
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->setExtraRenderBytes(0);
     $messageStreamer->add(Zurmo::t('JobsManagerModule', 'Script will run at most for {seconds} seconds.', array('{seconds}' => $timeLimit)));
     echo "\n";
     $messageStreamer->add(Zurmo::t('JobsManagerModule', '{dateTimeString} Starting job type: {type}', array('{type}' => $type, '{dateTimeString}' => static::getLocalizedDateTimeTimeZoneString())));
     $messageLogger = new $messageLoggerClassName($messageStreamer);
     if ($type == 'Monitor') {
         static::runMonitorJob($messageLogger);
     } else {
         static::runNonMonitorJob($type, $messageLogger);
     }
     $messageStreamer->add(Zurmo::t('JobsManagerModule', '{dateTimeString} Ending job type: {type}', array('{type}' => $type, '{dateTimeString}' => static::getLocalizedDateTimeTimeZoneString())));
 }
Esempio n. 4
0
 /**
  * Method to run import from command line. Use @ImportCommand.
  * @param array $args
  */
 public static function runFromImportCommand($args)
 {
     assert('is_array($args)');
     $template = "{message}\n";
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->setExtraRenderBytes(0);
     if (isset($args[3])) {
         set_time_limit($args[3]);
         $messageStreamer->add(Zurmo::t('JobsManagerModule', 'Script will run at most for {seconds} seconds.', array('{seconds}' => $args[3])));
     } else {
         set_time_limit('1200');
         $messageStreamer->add(Zurmo::t('JobsManagerModule', 'Script will run at most for {seconds} seconds.', array('{seconds}' => '1200')));
     }
     if (isset($args[0])) {
         $importName = $args[0];
         $messageStreamer->add(Zurmo::t('ImportModule', 'Starting import for process: {processName}', array('{processName}' => $importName)));
     } else {
         $importName = null;
         $messageStreamer->add(Zurmo::t('ImportModule', 'Starting import. Looking for processes.'));
     }
     $messageLogger = new ImportMessageLogger($messageStreamer);
     if (isset($args[2])) {
         $messageLogger->setMessageOutputInterval((int) $args[2]);
     }
     $importName = null;
     if (isset($args[1])) {
         $importName = $args[1];
     }
     Yii::app()->custom->runImportsForImportCommand($messageLogger, $importName);
     $messageStreamer->add(Zurmo::t('ImportModule', 'Ending import.'));
 }
Esempio n. 5
0
 /**
  * Restore database from backup file.
  * Database must be empty before restore starts.
  * @param string $filePath
  * @param MessageStreamer $messageStreamer
  * @param $databaseType
  * @param $databaseHost
  * @param $databaseName
  * @param $databasePort
  * @param $databaseUsername
  * @param $databasePassword
  */
 protected function restoreDatabase($filePath, $messageStreamer, $databaseType, $databaseHost, $databaseName, $databasePort, $databaseUsername, $databasePassword)
 {
     $messageStreamer->add(Zurmo::t('Commands', 'Starting database restore process.'));
     $result = DatabaseCompatibilityUtil::restoreDatabase($databaseType, $databaseHost, $databaseUsername, $databasePassword, $databasePort, $databaseName, $filePath);
     if ($result) {
         $messageStreamer->add(Zurmo::t('Commands', 'Database restored.'));
     } else {
         $messageStreamer->add(Zurmo::t('Commands', 'There was an error during restore.'));
         $messageStreamer->add(Zurmo::t('Commands', 'Please restore database manually.'));
     }
 }
Esempio n. 6
0
 /**
  * Run second and last part of upgrade process, which include:
  * - Update schema
  * - Clean assets and runtime foders
  * - Process final tasks
  * - Remove upgrade files
  * - Clear cache
  * @param MessageStreamer $messageStreamer
  */
 public static function runPart2(MessageStreamer $messageStreamer)
 {
     try {
         $messageStreamer->add(Zurmo::t('Core', 'Clearing cache.'));
         self::clearCache();
         $upgradeExtractPath = self::getUpgradeState('zurmoUpgradeFolderPath');
         $messageLogger = new MessageLogger($messageStreamer);
         self::isApplicationInUpgradeMode();
         $messageStreamer->add(Zurmo::t('Core', 'Loading UpgraderComponent.'));
         self::loadUpgraderComponent($upgradeExtractPath, $messageLogger);
         $messageStreamer->add(Zurmo::t('Core', 'Clearing cache.'));
         self::clearCache();
         $messageStreamer->add(Zurmo::t('Core', 'Running tasks before updating schema.'));
         self::processBeforeUpdateSchema();
         $messageStreamer->add(Zurmo::t('Core', 'Clearing cache.'));
         self::clearCache();
         $messageStreamer->add(Zurmo::t('Core', 'Updating schema.'));
         self::processUpdateSchema($messageLogger);
         $messageStreamer->add(Zurmo::t('Core', 'Clearing cache.'));
         self::clearCache();
         $messageStreamer->add(Zurmo::t('Core', 'Running tasks after schema is updated.'));
         self::processAfterUpdateSchema();
         $messageStreamer->add(Zurmo::t('Core', 'Clearing cache.'));
         self::clearCache();
         $messageStreamer->add(Zurmo::t('Core', 'Clearing assets and runtime folders.'));
         self::clearAssetsAndRunTimeItems();
         $messageStreamer->add(Zurmo::t('Core', 'Clearing cache.'));
         self::clearCache();
         $messageStreamer->add(Zurmo::t('Core', 'Processing final touches.'));
         self::processFinalTouches();
         $messageStreamer->add(Zurmo::t('Core', 'Clearing cache.'));
         self::clearCache();
         $messageStreamer->add(Zurmo::t('Core', 'Removing upgrade files.'));
         self::removeUpgradeFiles($upgradeExtractPath);
         self::unsetUpgradeState();
         $messageStreamer->add(Zurmo::t('Core', 'Clearing cache.'));
         self::clearCache();
         $messageStreamer->add(Zurmo::t('Core', 'Upgrade process completed.'));
     } catch (CException $e) {
         $messageStreamer->add(Zurmo::t('Core', 'Error during upgrade!'));
         $messageStreamer->add($e->getMessage());
         $messageStreamer->add(Zurmo::t('Core', 'Please fix error(s) and try again, or restore your database/files.'));
         Yii::app()->end();
     }
 }
Esempio n. 7
0
 /**
  * Method to run installation from command line. Use @InstallCommand.
  * @param array $args
  */
 public static function runFromInstallCommand($args, $validateForm = false)
 {
     assert('is_array($args)');
     $form = new InstallSettingsForm();
     $template = "{message}\n";
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->setExtraRenderBytes(0);
     $messageStreamer->add(Zurmo::t('InstallModule', 'Connecting to Database.'));
     $form->databaseHostname = $args[0];
     $form->databaseName = $args[1];
     $form->databaseUsername = $args[2];
     $form->databasePassword = $args[3];
     $form->databasePort = $args[4];
     $form->superUserPassword = $args[5];
     $form->removeExistingData = 1;
     if (!empty($args[6])) {
         $form->hostInfo = $args[6];
         Yii::app()->getRequest()->setHostInfo($form->hostInfo);
     }
     if (!empty($args[7])) {
         $form->scriptUrl = $args[7];
     }
     $formHasErrors = false;
     if ($validateForm) {
         $form->validate();
         if ($form->hasErrors()) {
             $errors = $form->getErrors();
             foreach ($errors as $fieldErrors) {
                 foreach ($fieldErrors as $fieldError) {
                     $messageStreamer->add($fieldError);
                 }
             }
             $formHasErrors = true;
         }
     }
     if (!$formHasErrors) {
         static::runInstallation($form, $messageStreamer);
         if (isset($args[8])) {
             $messageStreamer->add(Zurmo::t('InstallModule', 'Starting to load demo data.'));
             $messageLogger = new MessageLogger($messageStreamer);
             $messageLogger->logDateTimeStamp = false;
             $startTime = microtime(true);
             if (isset($args[9])) {
                 DemoDataUtil::load($messageLogger, intval($args[9]));
             } else {
                 DemoDataUtil::load($messageLogger, 6);
             }
             $endTime = microtime(true);
             $messageStreamer->add(Zurmo::t('InstallModule', 'Total demodata build time: {formattedTime} seconds.', array('{formattedTime}' => number_format($endTime - $startTime, 3))));
             if (SHOW_QUERY_DATA) {
                 $messageStreamer->add(FooterView::getTotalAndDuplicateQueryCountContent());
                 $messageStreamer->add(PageView::makeNonHtmlDuplicateCountAndQueryContent());
             }
             $messageStreamer->add(Zurmo::t('InstallModule', 'Finished loading demo data.'));
         }
         if (empty($args[6]) || empty($args[7])) {
             // Send notification to super admin that need to setup hostInfo and scriptUrl params in perInstance.php
             $message = new NotificationMessage();
             $message->textContent = Zurmo::t('InstallModule', 'The system has detected that the hostInfo and/or scriptUrl are ' . 'not set up. Please open the perInstance.php config file and ' . 'set up these parameters.');
             $rules = new HostInfoAndScriptUrlNotSetupNotificationRules();
             NotificationsUtil::submit($message, $rules);
         }
         $messageStreamer->add(Zurmo::t('InstallModule', 'Locking Installation.'));
         static::writeInstallComplete(INSTANCE_ROOT);
         $messageStreamer->add(Zurmo::t('InstallModule', 'Installation Complete.'));
     }
 }
 /**
  * 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();
     }
 }
 /**
  * Upgrade step two:
  */
 public function actionStepTwo()
 {
     // Upgrade process can take much time, because upgrade schema script.
     // Set timeout for upgrade to 12 hours.
     set_time_limit(12 * 60 * 60);
     Yii::app()->gameHelper->muteScoringModelsOnSave();
     $nextView = new UpgradeStepTwoCompleteView($this->getId(), $this->getModule()->getId());
     $view = new InstallPageView($nextView);
     echo $view->render();
     $template = ZurmoHtml::script("\$('#logging-table').prepend('{message}<br/>');");
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->setExtraRenderBytes(4096);
     $messageStreamer->add(Zurmo::t('InstallModule', 'Starting upgrade process.'));
     UpgradeUtil::runPart2($messageStreamer);
     ForgetAllCacheUtil::forgetAllCaches();
     echo ZurmoHtml::script('$("#progress-table").hide(); $("#upgrade-step-two").show();');
     Yii::app()->gameHelper->unmuteScoringModelsOnSave();
 }
Esempio n. 10
0
 /**
  * Execute the action.
  * @param array command line parameters specific for this command
  */
 public function run($args)
 {
     set_time_limit('900');
     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 (User::getRootUserCount() > 0) {
         echo 'There is already a root user. A new one cannot be specified.';
         Yii::app()->end();
     }
     Yii::app()->user->userModel->setIsRootUser();
     Yii::app()->user->userModel->hideFromSelecting = true;
     Yii::app()->user->userModel->hideFromLeaderboard = true;
     $saved = Yii::app()->user->userModel->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     $template = "{message}\n";
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->setExtraRenderBytes(0);
     $messageStreamer->add('');
     $messageStreamer->add(Zurmo::t('Commands', 'User with username {username} elevated to root.', array('{username}' => Yii::app()->user->userModel->username)));
 }
Esempio n. 11
0
 /**
  * Added forgetAllCaches in case you are debugging and want to run this action again with a saved db.
  */
 public function actionInstallDemoData()
 {
     RedBeanDatabase::setup(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password);
     InstallUtil::freezeDatabase();
     ForgetAllCacheUtil::forgetAllCaches();
     Yii::app()->user->userModel = User::getByUsername('super');
     $nextView = new InstallCompleteView($this->getId(), $this->getModule()->getId());
     $view = new InstallPageView($nextView);
     echo $view->render();
     $template = ZurmoHtml::script("\$('#logging-table').prepend('{message}<br/>');");
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->add(Zurmo::t('InstallModule', 'Starting to load demo data.'));
     $messageLogger = new MessageLogger($messageStreamer);
     DemoDataUtil::load($messageLogger, 6);
     $messageStreamer->add(Zurmo::t('InstallModule', 'Finished loading demo data.'));
     $messageStreamer->add(Zurmo::t('InstallModule', 'Locking Installation.'));
     InstallUtil::writeInstallComplete(INSTANCE_ROOT);
     ForgetAllCacheUtil::forgetAllCaches();
     echo ZurmoHtml::script('$("#progress-table").hide(); $("#complete-table").show();');
 }