コード例 #1
0
ファイル: DefaultController.php プロジェクト: youprofit/Zurmo
 public function actionSettings()
 {
     $form = new InstallSettingsForm();
     $memcacheServiceHelper = new MemcacheServiceHelper();
     if (!$memcacheServiceHelper->runCheckAndGetIfSuccessful()) {
         $form->setMemcacheIsNotAvailable();
     }
     $form->hostInfo = InstallUtil::getDefaultHostInfo();
     $form->scriptUrl = InstallUtil::getDefaultScriptUrl($this->getRoute());
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'install-form') {
         $this->actionValidateSettings($form);
     } else {
         if (isset($_POST['InstallSettingsForm'])) {
             $form->setAttributes($_POST['InstallSettingsForm']);
             //in case if additionalSystemCheck it will render its own screen
             $this->additionalSystemCheck($form);
             Yii::app()->end(0, false);
         }
     }
     $settingsView = new InstallSettingsView($this->getId(), $this->getModule()->getId(), $form);
     $view = new InstallPageView($settingsView);
     echo $view->render();
 }
コード例 #2
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.'));
     }
 }
コード例 #3
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);
 }