diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-10-09 07:17:28 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-10-09 07:17:28 +0400 |
commit | 6d46df58dd4b16a5c8402e34ed018439cbbadee1 (patch) | |
tree | efaeabfe94ab8a601a96c80e1333ae83513f803e /core | |
parent | 9fb5490490913717ccfacec6f597181091be214f (diff) |
Refs #4202 removing functions Piwik_GetOption and SetOption. Now use: Option::get and Option::set and Option::delete
Diffstat (limited to 'core')
-rw-r--r-- | core/ArchiveProcessor/Rules.php | 13 | ||||
-rw-r--r-- | core/FrontController.php | 4 | ||||
-rw-r--r-- | core/Http.php | 4 | ||||
-rw-r--r-- | core/Option.php | 106 | ||||
-rw-r--r-- | core/PluginsManager.php | 2 | ||||
-rw-r--r-- | core/SettingsPiwik.php | 4 | ||||
-rw-r--r-- | core/TaskScheduler.php | 4 | ||||
-rw-r--r-- | core/Tracker.php | 2 | ||||
-rw-r--r-- | core/Tracker/Cache.php | 3 | ||||
-rw-r--r-- | core/UpdateCheck.php | 8 | ||||
-rw-r--r-- | core/Updater.php | 4 | ||||
-rw-r--r-- | core/Updates/2.0-a13.php | 3 | ||||
-rw-r--r-- | core/ViewDataTable.php | 2 | ||||
-rw-r--r-- | core/functions.php | 26 |
14 files changed, 92 insertions, 93 deletions
diff --git a/core/ArchiveProcessor/Rules.php b/core/ArchiveProcessor/Rules.php index 18f13703ac..1589757187 100644 --- a/core/ArchiveProcessor/Rules.php +++ b/core/ArchiveProcessor/Rules.php @@ -15,6 +15,7 @@ use Piwik\Common; use Piwik\Config; use Piwik\Date; use Piwik\Log; +use Piwik\Option; use Piwik\Piwik; use Piwik\Segment; use Piwik\SettingsPiwik; @@ -114,7 +115,7 @@ class Rules return false; } $key = self::FLAG_TABLE_PURGED . "blob_" . $date->toString('Y_m'); - $timestamp = Piwik_GetOption($key); + $timestamp = Option::get($key); // we shall purge temporary archives after their timeout is finished, plus an extra 6 hours // in case archiving is disabled or run once a day, we give it this extra time to run @@ -130,7 +131,7 @@ class Rules && (!$timestamp || $timestamp < time() - $purgeEveryNSeconds) ) { - Piwik_SetOption($key, time()); + Option::set($key, time()); if (self::isBrowserTriggerEnabled()) { // If Browser Archiving is enabled, it is likely there are many more temporary archives @@ -176,12 +177,12 @@ class Rules if ($timeToLiveSeconds <= 0) { throw new Exception(Piwik_TranslateException('General_ExceptionInvalidArchiveTimeToLive')); } - Piwik_SetOption(self::OPTION_TODAY_ARCHIVE_TTL, $timeToLiveSeconds, $autoLoad = true); + Option::set(self::OPTION_TODAY_ARCHIVE_TTL, $timeToLiveSeconds, $autoLoad = true); } public static function getTodayArchiveTimeToLive() { - $timeToLive = Piwik_GetOption(self::OPTION_TODAY_ARCHIVE_TTL); + $timeToLive = Option::get(self::OPTION_TODAY_ARCHIVE_TTL); if ($timeToLive !== false) { return $timeToLive; } @@ -223,7 +224,7 @@ class Rules public static function isBrowserTriggerEnabled() { - $browserArchivingEnabled = Piwik_GetOption(self::OPTION_BROWSER_TRIGGER_ARCHIVING); + $browserArchivingEnabled = Option::get(self::OPTION_BROWSER_TRIGGER_ARCHIVING); if ($browserArchivingEnabled !== false) { return (bool)$browserArchivingEnabled; } @@ -235,7 +236,7 @@ class Rules if (!is_bool($enabled)) { throw new Exception('Browser trigger archiving must be set to true or false.'); } - Piwik_SetOption(self::OPTION_BROWSER_TRIGGER_ARCHIVING, (int)$enabled, $autoLoad = true); + Option::set(self::OPTION_BROWSER_TRIGGER_ARCHIVING, (int)$enabled, $autoLoad = true); Cache::clearCacheGeneral(); } }
\ No newline at end of file diff --git a/core/FrontController.php b/core/FrontController.php index e1068e46d8..ebed44b919 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -307,11 +307,11 @@ class FrontController try { Db::createDatabaseObject(); - Piwik_GetOption('TestingIfDatabaseConnectionWorked'); + Option::get('TestingIfDatabaseConnectionWorked'); } catch (Exception $exception) { if (self::shouldRethrowException()) { throw $exception; - } + } /** * This event is triggered in case a config file is not in the correct format or in case required values diff --git a/core/Http.php b/core/Http.php index 2b30cc620d..ddd773999f 100644 --- a/core/Http.php +++ b/core/Http.php @@ -581,9 +581,9 @@ class Http throw new Exception(Piwik_Translate('General_DownloadFail_HttpRequestFail')); } - Piwik_SetOption($downloadOption, $expectedFileSize); + Option::set($downloadOption, $expectedFileSize); } else { - $expectedFileSize = (int)Piwik_GetOption($downloadOption); + $expectedFileSize = (int)Option::get($downloadOption); if ($expectedFileSize === false) { // sanity check throw new Exception("Trying to continue a download that never started?! That's not supposed to happen..."); } diff --git a/core/Option.php b/core/Option.php index 3e4ad542d3..b784fe0f63 100644 --- a/core/Option.php +++ b/core/Option.php @@ -21,6 +21,65 @@ namespace Piwik; class Option { /** + * Returns the option value for the requested option $name, fetching from database, if not in cache. + * + * @param string $name Key + * @return string|bool Value or false, if not found + */ + public static function get($name) + { + return self::getInstance()->getValue($name); + } + + /** + * Sets the option value in the database and cache + * + * @param string $name + * @param string $value + * @param int $autoLoad if set to 1, this option value will be automatically loaded; should be set to 1 for options that will always be used in the Piwik request. + */ + public static function set($name, $value, $autoload = 0) + { + return self::getInstance()->setValue($name, $value, $autoload); + } + + /** + * Delete key-value pair from database and reload cache. + * + * @param string $name Key to match exactly + * @param string $value Optional value + */ + public static function delete($name, $value = null) + { + return self::getInstance()->deleteValue($name, $value); + } + + /** + * Delete key-value pair(s) from database and reload cache. + * The supplied pattern should use '%' as wildcards, and literal '_' should be escaped. + * + * @param string $name Pattern of key to match. + * @param string $value Optional value + */ + public static function deleteLike($name, $value = null) + { + return self::getInstance()->deleteNameLike($name, $value); + } + + /** + * Clears the cache + * Used in unit tests to reset the state of the object between tests + * + * @return void + */ + public static function clearCache() + { + $option = self::getInstance(); + $option->loaded = false; + $option->all = array(); + } + + /** * @var array */ private $all = array(); @@ -41,7 +100,7 @@ class Option * * @return \Piwik\Option */ - static public function getInstance() + static private function getInstance() { if (self::$instance == null) { self::$instance = new self; @@ -56,13 +115,7 @@ class Option { } - /** - * Returns the option value for the requested option $name, fetching from database, if not in cache. - * - * @param string $name Key - * @return string|bool Value or false, if not found - */ - public function get($name) + private function getValue($name) { $this->autoload(); if (isset($this->all[$name])) { @@ -78,14 +131,7 @@ class Option return $value; } - /** - * Sets the option value in the database and cache - * - * @param string $name - * @param string $value - * @param int $autoLoad if set to 1, this option value will be automatically loaded; should be set to 1 for options that will always be used in the Piwik request. - */ - public function set($name, $value, $autoLoad = 0) + private function setValue($name, $value, $autoLoad = 0) { $autoLoad = (int)$autoLoad; Db::query('INSERT INTO `' . Common::prefixTable('option') . '` (option_name, option_value, autoload) ' . @@ -95,13 +141,7 @@ class Option $this->all[$name] = $value; } - /** - * Delete key-value pair from database and reload cache. - * - * @param string $name Key to match exactly - * @param string $value Optional value - */ - public function delete($name, $value = null) + private function deleteValue($name, $value) { $sql = 'DELETE FROM `' . Common::prefixTable('option') . '` WHERE option_name = ?'; $bind[] = $name; @@ -116,14 +156,7 @@ class Option $this->clearCache(); } - /** - * Delete key-value pair(s) from database and reload cache. - * The supplied pattern should use '%' as wildcards, and literal '_' should be escaped. - * - * @param string $name Pattern of key to match. - * @param string $value Optional value - */ - public function deleteLike($name, $value = null) + private function deleteNameLike($name, $value = null) { $sql = 'DELETE FROM `' . Common::prefixTable('option') . '` WHERE option_name LIKE ?'; $bind[] = $name; @@ -159,15 +192,4 @@ class Option $this->loaded = true; } - /** - * Clears the cache - * Used in unit tests to reset the state of the object between tests - * - * @return void - */ - public function clearCache() - { - $this->loaded = false; - $this->all = array(); - } } diff --git a/core/PluginsManager.php b/core/PluginsManager.php index fbe39c40bd..605451e145 100644 --- a/core/PluginsManager.php +++ b/core/PluginsManager.php @@ -204,7 +204,7 @@ class PluginsManager $this->returnLoadedPluginsInfo(); $plugin = $this->getLoadedPlugin($pluginName); $plugin->uninstall(); - Option::getInstance()->delete('version_' . $pluginName); + Option::delete('version_' . $pluginName); $this->removePluginFromPluginsConfig($pluginName); $this->removePluginFromPluginsInstalledConfig($pluginName); diff --git a/core/SettingsPiwik.php b/core/SettingsPiwik.php index 5dd9d61920..6662b11a39 100644 --- a/core/SettingsPiwik.php +++ b/core/SettingsPiwik.php @@ -125,7 +125,7 @@ class SettingsPiwik } $key = 'piwikUrl'; - $url = Piwik_GetOption($key); + $url = Option::get($key); if (Common::isPhpCliMode() // in case archive.php is triggered with domain localhost || SettingsServer::isArchivePhpTriggered() @@ -141,7 +141,7 @@ class SettingsPiwik || $currentUrl != $url ) { if (strlen($currentUrl) >= strlen('http://a/')) { - Piwik_SetOption($key, $currentUrl, $autoLoad = true); + Option::set($key, $currentUrl, $autoLoad = true); } $url = $currentUrl; } diff --git a/core/TaskScheduler.php b/core/TaskScheduler.php index a81268c4c9..80bbc25f7a 100644 --- a/core/TaskScheduler.php +++ b/core/TaskScheduler.php @@ -103,7 +103,7 @@ class TaskScheduler if (self::taskShouldBeRescheduled($taskName, $timetable)) { // update the scheduled time $timetable[$taskName] = $task->getRescheduledTime(); - Piwik_SetOption(self::TIMETABLE_OPTION_STRING, serialize($timetable)); + Option::set(self::TIMETABLE_OPTION_STRING, serialize($timetable)); } } } @@ -186,7 +186,7 @@ class TaskScheduler static private function getTimetableFromOptionTable() { - return self::getTimetableFromOptionValue(Piwik_GetOption(self::TIMETABLE_OPTION_STRING)); + return self::getTimetableFromOptionValue(Option::get(self::TIMETABLE_OPTION_STRING)); } /** diff --git a/core/Tracker.php b/core/Tracker.php index 0db9fb2adf..0d3a00ee9b 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -353,7 +353,7 @@ class Tracker $cache['lastTrackerCronRun'] = $now; Cache::setCacheGeneral($cache); self::initCorePiwikInTrackerMode(); - Piwik_SetOption('lastTrackerCronRun', $cache['lastTrackerCronRun']); + Option::set('lastTrackerCronRun', $cache['lastTrackerCronRun']); Common::printDebug('-> Scheduled Tasks: Starting...'); // save current user privilege and temporarily assume super user privilege diff --git a/core/Tracker/Cache.php b/core/Tracker/Cache.php index 948d1a34ad..ae328aed38 100644 --- a/core/Tracker/Cache.php +++ b/core/Tracker/Cache.php @@ -13,6 +13,7 @@ namespace Piwik\Tracker; use Piwik\ArchiveProcessor\Rules; use Piwik\CacheFile; use Piwik\Config; +use Piwik\Option; use Piwik\Piwik; use Piwik\Tracker; @@ -106,7 +107,7 @@ class Cache Tracker::initCorePiwikInTrackerMode(); $cacheContent = array( 'isBrowserTriggerEnabled' => Rules::isBrowserTriggerEnabled(), - 'lastTrackerCronRun' => Piwik_GetOption('lastTrackerCronRun'), + 'lastTrackerCronRun' => Option::get('lastTrackerCronRun'), ); /** diff --git a/core/UpdateCheck.php b/core/UpdateCheck.php index a677abdd43..f1ba7edb9a 100644 --- a/core/UpdateCheck.php +++ b/core/UpdateCheck.php @@ -38,13 +38,13 @@ class UpdateCheck $interval = self::CHECK_INTERVAL; } - $lastTimeChecked = Piwik_GetOption(self::LAST_TIME_CHECKED); + $lastTimeChecked = Option::get(self::LAST_TIME_CHECKED); if ($force || $lastTimeChecked === false || time() - $interval > $lastTimeChecked ) { // set the time checked first, so that parallel Piwik requests don't all trigger the http requests - Piwik_SetOption(self::LAST_TIME_CHECKED, time(), $autoLoad = 1); + Option::set(self::LAST_TIME_CHECKED, time(), $autoLoad = 1); $parameters = array( 'piwik_version' => Version::VERSION, 'php_version' => PHP_VERSION, @@ -71,7 +71,7 @@ class UpdateCheck // e.g., disable_functions = fsockopen; allow_url_open = Off $latestVersion = ''; } - Piwik_SetOption(self::LATEST_VERSION, $latestVersion); + Option::set(self::LATEST_VERSION, $latestVersion); } } @@ -83,7 +83,7 @@ class UpdateCheck */ public static function isNewestVersionAvailable() { - $latestVersion = Piwik_GetOption(self::LATEST_VERSION); + $latestVersion = Option::get(self::LATEST_VERSION); if (!empty($latestVersion) && version_compare(Version::VERSION, $latestVersion) == -1 ) { diff --git a/core/Updater.php b/core/Updater.php index 0bbc6280ae..1ccdb78e18 100644 --- a/core/Updater.php +++ b/core/Updater.php @@ -55,7 +55,7 @@ class Updater public static function recordComponentSuccessfullyUpdated($name, $version) { try { - Piwik_SetOption(self::getNameInOptionTable($name), $version, $autoLoad = 1); + Option::set(self::getNameInOptionTable($name), $version, $autoLoad = 1); } catch (\Exception $e) { // case when the option table is not yet created (before 0.2.10) } @@ -245,7 +245,7 @@ class Updater foreach ($this->componentsToCheck as $name => $version) { try { - $currentVersion = Piwik_GetOption(self::getNameInOptionTable($name)); + $currentVersion = Option::get(self::getNameInOptionTable($name)); } catch (\Exception $e) { // mysql error 1146: table doesn't exist if (Db::get()->isErrNo($e, '1146')) { diff --git a/core/Updates/2.0-a13.php b/core/Updates/2.0-a13.php index fac9982240..1e4c0145f4 100644 --- a/core/Updates/2.0-a13.php +++ b/core/Updates/2.0-a13.php @@ -13,6 +13,7 @@ namespace Piwik\Updates; use Piwik\Common; use Piwik\Db; use Piwik\Filesystem; +use Piwik\Option; use Piwik\Updater; use Piwik\Updates; @@ -50,7 +51,7 @@ class Updates_2_0_a13 extends Updates public static function update() { // delete schema version_ - \Piwik\Option::getInstance()->delete('version_Referers'); + Option::delete('version_Referers'); Updater::updateDatabase(__FILE__, self::getSql()); diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php index 1977cf8243..9bf0a4b544 100644 --- a/core/ViewDataTable.php +++ b/core/ViewDataTable.php @@ -1144,7 +1144,7 @@ class ViewDataTable // if it's likely that the report data for this data table has been purged, // set whether we should display a message to that effect. $view->showReportDataWasPurgedMessage = $this->hasReportBeenPurged(); - $view->deleteReportsOlderThan = Piwik_GetOption('delete_reports_older_than'); + $view->deleteReportsOlderThan = Option::get('delete_reports_older_than'); } $view->idSubtable = $this->idSubtable; $view->clientSideParameters = $this->getClientSideParametersToSet(); diff --git a/core/functions.php b/core/functions.php index 6cca433647..38fae1c387 100644 --- a/core/functions.php +++ b/core/functions.php @@ -61,32 +61,6 @@ namespace { } } - - /** - * Returns the option value for the requested option $name - * - * @param string $name Key - * @return string|bool Value or false, if not found - * @api - */ - function Piwik_GetOption($name) - { - return Piwik\Option::getInstance()->get($name); - } - - /** - * Sets the option value in the database - * - * @param string $name - * @param string $value - * @param int $autoLoad if set to 1, this option value will be automatically loaded; should be set to 1 for options that will always be used in the Piwik request. - * @api - */ - function Piwik_SetOption($name, $value, $autoLoad = 0) - { - Piwik\Option::getInstance()->set($name, $value, $autoLoad); - } - /** * Returns the AdminMenu * |