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(); }
/** * Writes configuration to debug.php and phpInstance.php. */ public static function writeConfiguration($instanceRoot, $databaseType, $databaseHost, $databaseName, $username, $password, $port, $memcacheHost = null, $memcachePort = null, $minifyScripts = true, $language, $perInstanceFilename = 'perInstance.php', $debugFilename = 'debug.php', $hostInfo, $scriptUrl, $submitCrashToSentry = true) { assert('is_dir($instanceRoot)'); assert('in_array($databaseType, static::getSupportedDatabaseTypes())'); assert('is_string($databaseHost) && $databaseHost != ""'); assert('is_string($databaseName) && $databaseName != ""'); assert('is_string($username) && $username != ""'); assert('is_string($password)'); assert('is_string($port) || is_int($port)'); assert('is_string($memcacheHost) || $memcacheHost == null'); assert('(is_int ($memcachePort) && $memcachePort >= 1024) || $memcachePort == null'); assert('is_string($language) && $language != ""'); assert('is_string($hostInfo) || $hostInfo == ""'); assert('is_string($scriptUrl) || $scriptUrl == ""'); $perInstanceConfigFileDist = "{$instanceRoot}/protected/config/perInstanceDIST.php"; $debugConfigFileDist = "{$instanceRoot}/protected/config/debugDIST.php"; $perInstanceConfigFile = "{$instanceRoot}/protected/config/{$perInstanceFilename}"; $debugConfigFile = "{$instanceRoot}/protected/config/{$debugFilename}"; copy($perInstanceConfigFileDist, $perInstanceConfigFile); copy($debugConfigFileDist, $debugConfigFile); chmod($perInstanceConfigFile, 0777); chmod($debugConfigFile, 0777); // NOTE: These keep the tidy formatting of the files they are modifying - the whitespace matters! $contents = file_get_contents($debugConfigFile); $contents = preg_replace('/\\$debugOn\\s*=\\s*true;/', '$debugOn = false;', $contents); if (!$submitCrashToSentry) { $contents = preg_replace('/\\$submitCrashToSentry\\s*=\\s*true;/', '$submitCrashToSentry = false;', $contents); } $setIncludePathServiceHelper = new SetIncludePathServiceHelper(); if ($minifyScripts && $setIncludePathServiceHelper->runCheckAndGetIfSuccessful()) { $contents = preg_replace('/\\$minifyScripts\\s*=\\s*false;/', '$minifyScripts = true;', $contents); } // Check if user setup memcache host and port if ($memcacheHost && $memcachePort) { // Check if memcache extension is installed $memcacheServiceHelper = new MemcacheServiceHelper(); if ($memcacheServiceHelper->runCheckAndGetIfSuccessful()) { $contents = preg_replace('/\\$memcacheLevelCaching\\s*=\\s*false;/', '$memcacheLevelCaching = true;', $contents); } } $installSettingsForm = new InstallSettingsForm(); $installSettingsForm->databaseHostname = $databaseHost; $installSettingsForm->databaseUsername = $username; $installSettingsForm->databasePassword = $password; $installSettingsForm->databasePort = $port; $maxSpRecursionDepthServiceHelper = new DatabaseMaxSpRecursionDepthServiceHelper($installSettingsForm); if ($maxSpRecursionDepthServiceHelper->runCheckAndGetIfSuccessful()) { $contents = preg_replace('/\\$securityOptimized\\s*=\\s*false;/', '$securityOptimized = true;', $contents); } else { $contents = preg_replace('/\\$securityOptimized\\s*=\\s*true;/', '$securityOptimized = false;', $contents); } file_put_contents($debugConfigFile, $contents); $contents = file_get_contents($perInstanceConfigFile); $contents = preg_replace('/\\$language\\s*=\\s*\'[a-z]+\';/', "\$language = '{$language}';", $contents); $contents = preg_replace('/\\$connectionString\\s*=\\s*\'[a-z]+:host=[^;]+;port=[^;]+;dbname=[^;]+;/', "\$connectionString = '{$databaseType}:host={$databaseHost};port={$port};dbname={$databaseName}';", $contents); $contents = preg_replace('/\\$username\\s*=\\s*\'[^\']+\';/', "\$username = '******';", $contents); $contents = preg_replace('/\\$password\\s*=\\s*\'[^\']+\';/', "\$password = '******';", $contents); $contents = preg_replace('/\\$memcacheServers\\s*=\\s*array\\(.*?array\\(\\s+\'host\'\\s*=>\\s*\'[^\']+\',\\s*\'port\'\\s*=>\\s*\\d{4,},/s', "\$memcacheServers = array( // An empty array means memcache is not used.\n array(\n 'host' => '{$memcacheHost}',\n 'port' => {$memcachePort}, ", $contents); $contents = preg_replace('/\\/\\/\\$instanceConfig\\[\'components\'\\]\\[\'request\'\\]\\[\'hostInfo\'\\]\\s*=\\s*\'.*?\';/', "\$instanceConfig['components']['request']['hostInfo'] = '{$hostInfo}';", $contents); $contents = preg_replace('/\\/\\/\\$instanceConfig\\[\'components\'\\]\\[\'request\'\\]\\[\'scriptUrl\'\\]\\s*=\\s*\'.*?\';/', "\$instanceConfig['components']['request']['scriptUrl'] = '{$scriptUrl}';", $contents); $contents = preg_replace('/\\s+\\/\\/ REMOVE THE REMAINDER OF THIS FILE FOR PRODUCTION.*?>/s', "\n?>", $contents); file_put_contents($perInstanceConfigFile, $contents); }
/** * Load memcache extension if memcache extension is * loaded and if memcache server is avalable * @param $event */ public function handleApplicationCache($event) { if (MEMCACHE_ON) { //Yii::import('application.core.components.ZurmoMemCache'); $memcacheServiceHelper = new MemcacheServiceHelper(); if ($memcacheServiceHelper->runCheckAndGetIfSuccessful()) { $cacheComponent = Yii::createComponent(array('class' => 'CMemCache', 'keyPrefix' => ZURMO_TOKEN, 'servers' => Yii::app()->params['memcacheServers'])); Yii::app()->setComponent('cache', $cacheComponent); } // todo: Find better way to append this prefix for tests. // We can't put this code only in BeginRequestTestBehavior, because for API tests we are using BeginRequestBehavior if (defined('IS_TEST')) { ZurmoCache::setAdditionalStringForCachePrefix('Test'); } } }