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(); }
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); }