public static function update() { $salt = Common::generateUniqId(); $config = Config::getInstance(); $superuser = $config->superuser; if (!isset($superuser['salt'])) { try { if (is_writable(Config::getLocalConfigPath())) { $superuser['salt'] = $salt; $config->superuser = $superuser; $config->forceSave(); } else { throw new \Exception('mandatory update failed'); } } catch (\Exception $e) { throw new \Piwik\UpdaterErrorException("Please edit your config/config.ini.php file and add below <code>[superuser]</code> the following line: <br /><code>salt = {$salt}</code>"); } } $plugins = $config->Plugins; if (!in_array('MultiSites', $plugins)) { try { if (is_writable(Config::getLocalConfigPath())) { $plugins[] = 'MultiSites'; $config->Plugins = $plugins; $config->forceSave(); } else { throw new \Exception('optional update failed'); } } catch (\Exception $e) { throw new \Exception("You can now enable the new MultiSites plugin in the Plugins screen in the Piwik admin!"); } } Updater::updateDatabase(__FILE__, self::getSql()); }
public function doUpdate(Updater $updater) { $config = Config::getInstance(); $dbInfos = $config->database; if (!isset($dbInfos['schema'])) { try { if (is_writable(Config::getLocalConfigPath())) { $config->database = $dbInfos; $config->forceSave(); } else { throw new \Exception('mandatory update failed'); } } catch (\Exception $e) { } } $updater->executeMigrationQueries(__FILE__, $this->getMigrationQueries($updater)); }
public static function update() { $config = Config::getInstance(); $dbInfos = $config->database; if (!isset($dbInfos['schema'])) { try { if (is_writable(Config::getLocalConfigPath())) { $config->database = $dbInfos; $config->forceSave(); } else { throw new \Exception('mandatory update failed'); } } catch (\Exception $e) { } } Updater::updateDatabase(__FILE__, self::getSql()); }
static function update() { $config = Config::getInstance(); $dbInfos = $config->database; if (!isset($dbInfos['schema'])) { try { if (is_writable(Config::getLocalConfigPath())) { $dbInfos['schema'] = 'Myisam'; $config->database = $dbInfos; $config->forceSave(); } else { throw new \Exception('mandatory update failed'); } } catch (\Exception $e) { throw new \Piwik\UpdaterErrorException("Please edit your config/config.ini.php file and add below <code>[database]</code> the following line: <br /><code>schema = Myisam</code>"); } } Updater::updateDatabase(__FILE__, self::getSql()); }
/** * Records one host, or an array of hosts in the config file, * if user is Super User * * @static * @param $host string|array * @return bool */ public static function saveTrustedHostnameInConfig($host) { if (Piwik::hasUserSuperUserAccess() && file_exists(Config::getLocalConfigPath())) { $general = Config::getInstance()->General; if (!is_array($host)) { $host = array($host); } $host = array_filter($host); if (empty($host)) { return false; } $general['trusted_hosts'] = $host; Config::getInstance()->General = $general; Config::getInstance()->forceSave(); return true; } return false; }
protected static function saveHostsnameInConfig($host, $domain, $key) { if (Piwik::hasUserSuperUserAccess() && file_exists(Config::getLocalConfigPath())) { $config = Config::getInstance()->{$domain}; if (!is_array($host)) { $host = array($host); } $host = array_filter($host); if (empty($host)) { return false; } $config[$key] = $host; Config::getInstance()->{$domain} = $config; Config::getInstance()->forceSave(); return true; } return false; }
/** * Enable test environment * * @param string $pathLocal * @param string $pathGlobal * @param string $pathCommon */ public function setTestEnvironment($pathLocal = null, $pathGlobal = null, $pathCommon = null, $allowSaving = false) { if (!$allowSaving) { $this->isTest = true; } $this->clear(); $this->pathLocal = $pathLocal ?: Config::getLocalConfigPath(); $this->pathGlobal = $pathGlobal ?: Config::getGlobalConfigPath(); $this->pathCommon = $pathCommon ?: Config::getCommonConfigPath(); $this->init(); // this proxy will not record any data in the production database. // this provides security for Piwik installs and tests were setup. if (isset($this->configGlobal['database_tests']) || isset($this->configLocal['database_tests'])) { $this->__get('database_tests'); $this->configCache['database'] = $this->configCache['database_tests']; } // Ensure local mods do not affect tests if (empty($pathGlobal)) { $this->configCache['log'] = $this->configGlobal['log']; $this->configCache['Debug'] = $this->configGlobal['Debug']; $this->configCache['mail'] = $this->configGlobal['mail']; $this->configCache['General'] = $this->configGlobal['General']; $this->configCache['Segments'] = $this->configGlobal['Segments']; $this->configCache['Tracker'] = $this->configGlobal['Tracker']; $this->configCache['Deletelogs'] = $this->configGlobal['Deletelogs']; $this->configCache['Deletereports'] = $this->configGlobal['Deletereports']; $this->configCache['Development'] = $this->configGlobal['Development']; } // for unit tests, we set that no plugin is installed. This will force // the test initialization to create the plugins tables, execute ALTER queries, etc. $this->configCache['PluginsInstalled'] = array('PluginsInstalled' => array()); }
/** * The previous step is valid if it is either * - any step before (OK to go back) * - the current step (case when validating a form) * If step is invalid, then exit. * * @param string $currentStep Current step */ protected function checkPreviousStepIsValid($currentStep) { $error = false; if (empty($this->session->currentStepDone)) { $error = true; } else { if ($currentStep == 'finished' && $this->session->currentStepDone == 'finished') { // ok to refresh this page or use language selector } else { if (file_exists(Config::getLocalConfigPath())) { $error = true; } $steps = array_keys($this->steps); // the currentStep $currentStepId = array_search($currentStep, $steps); // the step before $previousStepId = array_search($this->session->currentStepDone, $steps); // not OK if currentStepId > previous+1 if ($currentStepId > $previousStepId + 1) { $error = true; } } } if ($error) { \Piwik\Plugins\Login\Controller::clearSession(); $message = Piwik::translate('Installation_ErrorInvalidState', array('<br /><strong>', '</strong>', '<a href=\'' . Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName()) . '\'>', '</a>')); Piwik::exitWithErrorMessage($message); } }
/** * Enable test environment * * @param string $pathLocal * @param string $pathGlobal * @param string $pathCommon */ public function setTestEnvironment($pathLocal = null, $pathGlobal = null, $pathCommon = null, $allowSaving = false) { if (!$allowSaving) { $this->doNotWriteConfigInTests = true; } $this->pathLocal = $pathLocal ?: Config::getLocalConfigPath(); $this->pathGlobal = $pathGlobal ?: Config::getGlobalConfigPath(); $this->pathCommon = $pathCommon ?: Config::getCommonConfigPath(); $this->reload(); $databaseTestsSettings = $this->database_tests; if (!empty($databaseTestsSettings)) { $this->database = $databaseTestsSettings; } // Ensure local mods do not affect tests if (empty($pathGlobal)) { $this->Debug = $this->settings->getFrom($this->pathGlobal, 'Debug'); $this->mail = $this->settings->getFrom($this->pathGlobal, 'mail'); $this->General = $this->settings->getFrom($this->pathGlobal, 'General'); $this->Segments = $this->settings->getFrom($this->pathGlobal, 'Segments'); $this->Tracker = $this->settings->getFrom($this->pathGlobal, 'Tracker'); $this->Deletelogs = $this->settings->getFrom($this->pathGlobal, 'Deletelogs'); $this->Deletereports = $this->settings->getFrom($this->pathGlobal, 'Deletereports'); $this->Development = $this->settings->getFrom($this->pathGlobal, 'Development'); } // for unit tests, we set that no plugin is installed. This will force // the test initialization to create the plugins tables, execute ALTER queries, etc. $this->PluginsInstalled = array('PluginsInstalled' => array()); }