Ejemplo 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.");
             }
         }
     }
 }
 /**
  * @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 $type
  * @param $timeLimit
  * @param $messageLoggerClassName
  * @param $isJobInProgress
  * @param bool $useMessageStreamer
  * @param string $template
  * @param string $lineBreak
  */
 public static function runFromJobManagerCommandOrBrowser($type, $timeLimit, $messageLoggerClassName, &$isJobInProgress, $useMessageStreamer = true, $template = "{message}\n", $lineBreak = "\n")
 {
     assert('is_string($type)');
     assert('is_int($timeLimit)');
     assert('is_string($messageLoggerClassName) && (
                 is_subclass_of($messageLoggerClassName, "MessageLogger") ||
                 $messageLoggerClassName == "MessageLogger")');
     assert('is_bool($isJobInProgress)');
     assert('is_string($template)');
     assert('is_string($lineBreak)');
     set_time_limit($timeLimit);
     $jobManagerFileLogger = Yii::createComponent(array('class' => 'application.modules.jobsManager.components.JobManagerFileLogger', 'maxFileSize' => '5120', 'logFile' => $type . '.log', 'logPath' => Yii::app()->getRuntimePath() . DIRECTORY_SEPARATOR . 'jobLogs'));
     $jobManagerFileMessageStreamer = new JobManagerFileLogRouteMessageStreamer("{message}\n", $jobManagerFileLogger);
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->setExtraRenderBytes(0);
     if ($useMessageStreamer) {
         $messageLogger = new $messageLoggerClassName(array($messageStreamer, $jobManagerFileMessageStreamer));
     } else {
         $messageLogger = new $messageLoggerClassName(array($jobManagerFileMessageStreamer));
     }
     $streamers = array($messageStreamer, $jobManagerFileMessageStreamer);
     if (Yii::app()->isApplicationInMaintenanceMode()) {
         foreach ($streamers as $streamer) {
             $streamer->add(Zurmo::t('JobsManagerModule', '{dateTimeString} Application is in maintenanceMode and {type}Job can not be started.', array('{type}' => $type, '{dateTimeString}' => static::getLocalizedDateTimeTimeZoneString())));
         }
     } else {
         foreach ($streamers as $streamer) {
             $streamer->add(Zurmo::t('JobsManagerModule', 'Script will run at most for {seconds} seconds.', array('{seconds}' => $timeLimit)));
             $streamer->add(Zurmo::t('JobsManagerModule', 'Sending output to runtime/jobLogs/{type}.log', array('{type}' => $type)));
             $streamer->add(Zurmo::t('JobsManagerModule', '{dateTimeString} Starting job type: {type}', array('{type}' => $type, '{dateTimeString}' => static::getLocalizedDateTimeTimeZoneString())));
         }
         $messageLogger->addInfoMessage(Zurmo::t('JobsManagerModule', 'Script will run at most for {seconds} seconds.', array('{seconds}' => $timeLimit)));
         $messageLogger->addInfoMessage(Zurmo::t('JobsManagerModule', 'Starting job type: {type}', array('{type}' => $type)));
         $messageLogger->addDebugMessage('Showing Debug Messages');
         if ($type == 'Monitor') {
             static::runMonitorJob($messageLogger, $isJobInProgress);
         } else {
             static::runNonMonitorJob($type, $messageLogger, $isJobInProgress);
         }
         foreach ($streamers as $streamer) {
             $streamer->add(Zurmo::t('JobsManagerModule', '{dateTimeString} Ending job type: {type}', array('{type}' => $type, '{dateTimeString}' => static::getLocalizedDateTimeTimeZoneString())));
         }
     }
 }
Ejemplo n.º 4
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())));
 }
Ejemplo n.º 5
0
 public static function suite()
 {
     global $argv;
     PhpUnitServiceUtil::checkVersion();
     $usage = PHP_EOL . "  Usage: phpunit [phpunit options] TestSuite.php <All|Framework|Misc|moduleName|TestClassName> [custom options]" . PHP_EOL . PHP_EOL . "    All                     Run all tests." . PHP_EOL . "    Framework               Run the tests in app/protected/extensions/framework/tests/unit." . PHP_EOL . "    Misc                    Run the tests in app/protected/tests/unit." . PHP_EOL . "    moduleName              Run the tests in app/protected/modules/moduleName/tests/unit." . PHP_EOL . "    TestClassName           Run the tests in TestClassName.php, wherever that happens to be." . PHP_EOL . PHP_EOL . "  Custom Options:" . PHP_EOL . PHP_EOL . "    --only-walkthroughs     For the specified test, only includes tests under a walkthroughs directory." . PHP_EOL . "    --exclude-walkthroughs  For the specified test, exclude tests under a walkthroughs directory." . PHP_EOL . "    --only-benchmarks       For the specified test, only includes tests under a benchmarks directory." . PHP_EOL . "    --exclude-benchmarks    For the specified test, exclude tests under a benchmarks directory." . PHP_EOL . "    --reuse-schema          Reload a previously auto build database. (Will auto build if there is no" . PHP_EOL . "                            previous one. The auto built schema is dumped to the system temp dir in" . PHP_EOL . "                            autobuild.sql.)" . PHP_EOL . PHP_EOL . "  Examples:" . PHP_EOL . PHP_EOL . "    phpunit --verbose TestSuite.php accounts (Run the tests in the Accounts module.)" . PHP_EOL . "    phpunit TestSuite.php RedBeanModelTest   (Run the tests in RedBeanModelTest.php.)" . PHP_EOL . PHP_EOL . "    To run specific tests use the phpunit --filter <regex> option." . PHP_EOL . "    phpunit has its own options. Check phpunit --help." . PHP_EOL . PHP_EOL;
     // Not Coding Standard
     $onlyWalkthroughs = self::customOptionSet('--only-walkthroughs', $argv);
     $excludeWalkthroughs = self::customOptionSet('--exclude-walkthroughs', $argv);
     $onlyBenchmarks = self::customOptionSet('--only-benchmarks', $argv);
     $excludeBenchmarks = self::customOptionSet('--exclude-benchmarks', $argv);
     $reuse = self::customOptionSet('--reuse-schema', $argv);
     if ($argv[count($argv) - 2] != 'TestSuite.php') {
         echo $usage;
         exit(static::ERROR_INVOCATION_WITHOUT_TESTSUITE);
     }
     if ($onlyWalkthroughs && $onlyBenchmarks) {
         echo $usage;
         echo "It doesn't have sense to select both \"--only-walkthroughs\" and \"--only-benchmarks\" options. " . PHP_EOL . PHP_EOL;
         exit(static::ERROR_WALKTHROUGH_AND_BENCHMARK_SELECTED);
     }
     $whatToTest = $argv[count($argv) - 1];
     $includeUnitTests = !$onlyWalkthroughs && !$onlyBenchmarks;
     $includeWalkthroughs = !$excludeWalkthroughs && !$onlyBenchmarks;
     $includeBenchmarks = !$excludeBenchmarks && !$onlyWalkthroughs;
     $suite = new PHPUnit_Framework_TestSuite();
     $suite->setName("{$whatToTest} Tests");
     self::buildAndAddSuiteFromDirectory($suite, 'Framework', COMMON_ROOT . '/protected/core/tests/unit', $whatToTest, true, false, $includeBenchmarks);
     $moduleDirectoryName = COMMON_ROOT . '/protected/modules';
     if (is_dir($moduleDirectoryName)) {
         $moduleNames = scandir($moduleDirectoryName);
         foreach ($moduleNames as $moduleName) {
             if ($moduleName != '.' && $moduleName != '..') {
                 $moduleUnitTestDirectoryName = "{$moduleDirectoryName}/{$moduleName}/tests/unit";
                 self::buildAndAddSuiteFromDirectory($suite, $moduleName, $moduleUnitTestDirectoryName, $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
             }
         }
     }
     self::buildAndAddSuiteFromDirectory($suite, 'Misc', COMMON_ROOT . '/protected/tests/unit', $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
     self::buildAndAddSuiteFromDirectory($suite, 'Commands', COMMON_ROOT . '/protected/commands/tests/unit', $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
     ////////////////////////////////////////////////////////////////////////////////
     // Temporary - See Readme.txt in the notSupposedToBeHere directory.
     self::buildAndAddSuiteFromDirectory($suite, 'BadDependencies', COMMON_ROOT . '/protected/tests/unit/notSupposedToBeHere', $whatToTest, $includeUnitTests, $includeWalkthroughs, $includeBenchmarks);
     ////////////////////////////////////////////////////////////////////////////////
     if ($suite->count() == 0) {
         echo $usage;
         echo "  No tests found for '{$whatToTest}'." . PHP_EOL . PHP_EOL;
         exit(static::ERROR_TEST_NOT_FOUND);
     }
     echo "Testing with database: '" . Yii::app()->db->connectionString . '\', ' . 'username: \'' . Yii::app()->db->username . "'." . PHP_EOL;
     static::setupDatabaseConnection();
     // get rid of any caches from last execution, this ensure we rebuild any required tables
     // without this some of many_many tables have issues as we use cache to determine
     // if we need to rebuild those.
     ForgetAllCacheUtil::forgetAllCaches();
     $template = "{message}\n";
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->setExtraRenderBytes(0);
     $messageLogger = new MessageLogger($messageStreamer);
     $messageLogger->logDateTimeStamp = false;
     if (!$reuse) {
         if (!is_writable(sys_get_temp_dir())) {
             echo PHP_EOL . PHP_EOL . "Temp directory must be writable to store reusable schema" . PHP_EOL;
             // Not Coding Standard
             echo "Temp directory: " . sys_get_temp_dir() . PHP_EOL . PHP_EOL;
             // Not Coding Standard
             exit(static::ERROR_TEMP_DIR_NOT_WRITABLE);
         }
         echo "Auto building database schema..." . PHP_EOL;
         ZurmoRedBean::$writer->wipeAll();
         InstallUtil::autoBuildDatabase($messageLogger, true);
         $messageLogger->printMessages();
         // recreate all tables, we know there aren't existing because we just did a wipeAll();
         static::rebuildReadPermissionsTables(true, true, $messageStreamer);
         assert('RedBeanDatabase::isSetup()');
         Yii::app()->user->userModel = InstallUtil::createSuperUser('super', 'super');
         echo "Saving auto built schema..." . PHP_EOL;
         $schemaFile = sys_get_temp_dir() . '/autobuilt.sql';
         $success = preg_match("/;dbname=([^;]+)/", Yii::app()->db->connectionString, $matches);
         // Not Coding Standard
         assert('$success == 1');
         $databaseName = $matches[1];
         preg_match("/mysql:host=([^;]+)/", Yii::app()->db->connectionString, $matches);
         // Not Coding Standard
         $host = $matches[1];
         $systemOutput = system('mysqldump -u' . Yii::app()->db->username . ' -p' . Yii::app()->db->password . ' -h ' . $host . ' ' . $databaseName . " > {$schemaFile}");
         if ($systemOutput != null) {
             echo 'Dumping schema using system command. Output: ' . $systemOutput . PHP_EOL . PHP_EOL;
         }
     } else {
         echo PHP_EOL;
         static::buildDependentTestModels($messageLogger);
         $messageLogger->printMessages();
     }
     echo PHP_EOL;
     static::closeDatabaseConnection();
     return $suite;
 }
Ejemplo n.º 6
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.'));
 }
Ejemplo n.º 7
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.'));
     }
 }
Ejemplo n.º 8
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();
     }
 }
Ejemplo n.º 9
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.'));
     }
 }
Ejemplo n.º 10
0
 public function actionSendDemoEmailNotifications()
 {
     if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel)) {
         throw new NotSupportedException();
     }
     $template = "{message}<br/>";
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->setExtraRenderBytes(0);
     $messageLogger = new MessageLogger($messageStreamer);
     if (Yii::app()->user->userModel->primaryEmail->emailAddress == null) {
         $messageLogger->addErrorMessage('Cannot send test emails because the current user does not have an email address');
         Yii::app()->end(0, false);
     }
     $messageLogger->addInfoMessage('Using type:' . Yii::app()->emailHelper->outboundType);
     $messageLogger->addInfoMessage('Using host:' . Yii::app()->emailHelper->outboundHost);
     $messageLogger->addInfoMessage('Using port:' . Yii::app()->emailHelper->outboundPort);
     $messageLogger->addInfoMessage('Using username:'******'Using password: Yes');
     } else {
         $messageLogger->addInfoMessage('Using password: No');
     }
     $modules = Module::getModuleObjects();
     foreach ($modules as $module) {
         $notificationClassNames = $module::getAllClassNamesByPathFolder('data');
         foreach ($notificationClassNames as $notificationClassName) {
             if (!strpos($notificationClassName, 'DemoEmailNotifications') === false) {
                 $demoNotification = new $notificationClassName();
                 $demoNotification->run(Yii::app()->user->userModel, $messageLogger);
             }
         }
     }
     Yii::app()->emailHelper->sendQueued();
 }
Ejemplo n.º 11
0
 /**
  * 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();
     }
 }
Ejemplo n.º 12
0
 /**
  * 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();
 }
Ejemplo n.º 13
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)));
 }
Ejemplo n.º 14
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();');
 }
Ejemplo n.º 15
0
 protected function runInstallation($memcacheOn = true)
 {
     $instanceRoot = INSTANCE_ROOT;
     $form = new InstallSettingsForm();
     $form->databaseType = 'mysql';
     $form->databaseHostname = $this->temporaryDatabaseHostname;
     $form->databaseName = $this->temporaryDatabaseName;
     $form->databaseUsername = $this->temporaryDatabaseUsername;
     $form->databasePassword = $this->temporaryDatabasePassword;
     $form->databasePort = $this->temporaryDatabasePort;
     $form->superUserPassword = $this->superUserPassword;
     if (!$memcacheOn) {
         $form->setMemcacheIsNotAvailable();
     }
     $messageStreamer = new MessageStreamer();
     $messageStreamer->setExtraRenderBytes(0);
     $messageStreamer->setEmptyTemplate();
     $perInstanceConfigFile = "{$instanceRoot}/protected/config/perInstanceTest.php";
     $debugConfigFile = "{$instanceRoot}/protected/config/debugTest.php";
     if (is_file($perInstanceConfigFile)) {
         $originalPerInstanceConfiguration = file_get_contents($perInstanceConfigFile);
         unlink($perInstanceConfigFile);
     }
     if (is_file($debugConfigFile)) {
         $originalDebugConfiguration = file_get_contents($debugConfigFile);
         unlink($debugConfigFile);
     }
     $this->assertTrue(!is_file($perInstanceConfigFile));
     $this->assertTrue(!is_file($debugConfigFile));
     InstallUtil::runInstallation($form, $messageStreamer);
     $notifications = Notification::getAll();
     $this->assertCount(1, $notifications);
     $this->assertEquals('If this website is in production mode, please remove the app/test.php file.', $notifications[0]->notificationMessage->textContent);
     $perInstanceConfiguration = file_get_contents($perInstanceConfigFile);
     $debugConfiguration = file_get_contents($debugConfigFile);
     //Check if super user is created.
     $user = User::getByUsername('super');
     $this->assertEquals('super', $user->username);
     //Check if config files is updated.
     $this->assertRegExp('/\\$connectionString = \'mysql:host=' . $this->temporaryDatabaseHostname . ';port=' . $this->temporaryDatabasePort . ';dbname=' . $this->temporaryDatabaseName . '\';/', $perInstanceConfiguration);
     $this->assertRegExp('/\\$username         = \'' . $this->temporaryDatabaseUsername . '\';/', $perInstanceConfiguration);
     $this->assertRegExp('/\\$password         = \'' . $this->temporaryDatabasePassword . '\';/', $perInstanceConfiguration);
     if ($memcacheOn) {
         $this->assertRegExp('/\\$memcacheLevelCaching\\s*=\\s*true;/', $debugConfiguration);
     } else {
         $this->assertRegExp('/\\$memcacheLevelCaching\\s*=\\s*false;/', $debugConfiguration);
     }
     //Restore original config files.
     unlink($debugConfigFile);
     unlink($perInstanceConfigFile);
     file_put_contents($perInstanceConfigFile, $originalPerInstanceConfiguration);
     file_put_contents($debugConfigFile, $originalDebugConfiguration);
 }