Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobocoder <anthon.pang@gmail.com>2012-03-05 02:04:41 +0400
committerrobocoder <anthon.pang@gmail.com>2012-03-05 02:04:41 +0400
commit884e54cf378bffdea2dd5360af8a260b25352746 (patch)
tree83fe77732234c1c3e858501ab9ab200989732df1
parent775978937e1e393ba764968d5d41f261b488b8a8 (diff)
refs #1713 - merge dev branch to trunk (config class refactoring)
git-svn-id: http://dev.piwik.org/svn/trunk@5951 59fd770c-687e-43c8-a1e3-f5a4ff64c105
-rw-r--r--core/Archive.php4
-rw-r--r--core/ArchiveProcessing.php12
-rw-r--r--core/AssetManager.php2
-rw-r--r--core/Common.php65
-rw-r--r--core/Config.php375
-rw-r--r--core/Config/Compat.php149
-rw-r--r--core/Config/Ini.php55
-rw-r--r--core/Config/Writer.php228
-rw-r--r--core/Controller.php12
-rw-r--r--core/Controller/Admin.php2
-rw-r--r--core/DataTable.php2
-rw-r--r--core/Db/Adapter/Mysqli.php10
-rw-r--r--core/Db/Adapter/Pdo/Mssql.php4
-rw-r--r--core/Db/Adapter/Pdo/Mysql.php2
-rw-r--r--core/Db/Adapter/Pdo/Pgsql.php2
-rw-r--r--core/Db/Schema.php4
-rw-r--r--core/Db/Schema/Myisam.php20
-rw-r--r--core/FrontController.php6
-rw-r--r--core/Http.php22
-rw-r--r--core/IP.php33
-rw-r--r--core/Log.php2
-rw-r--r--core/Mail.php28
-rw-r--r--core/Piwik.php53
-rw-r--r--core/PluginsManager.php41
-rw-r--r--core/Session.php10
-rw-r--r--core/Smarty.php14
-rw-r--r--core/SmartyPlugins/outputfilter.ajaxcdn.php6
-rw-r--r--core/TablePartitioning.php12
-rw-r--r--core/Tracker.php12
-rw-r--r--core/Tracker/Action.php8
-rw-r--r--core/Tracker/Config.php156
-rw-r--r--core/Tracker/GoalManager.php2
-rw-r--r--core/Tracker/IgnoreCookie.php32
-rw-r--r--core/Tracker/Visit.php22
-rw-r--r--core/Translate.php2
-rw-r--r--core/UpdateCheck.php2
-rw-r--r--core/Updates/0.5.4.php24
-rw-r--r--core/Updates/0.6.3.php12
-rw-r--r--core/Updates/1.1.php4
-rw-r--r--core/Updates/1.2.3.php2
-rw-r--r--core/Url.php19
-rw-r--r--core/View.php2
-rw-r--r--core/ViewDataTable.php2
-rw-r--r--core/ViewDataTable/HtmlTable.php2
-rw-r--r--misc/cron/archive.php12
-rw-r--r--misc/test_generateLotsVisitsWebsites.php6
-rw-r--r--piwik.php9
-rw-r--r--plugins/API/API.php4
-rw-r--r--plugins/API/Controller.php2
-rw-r--r--plugins/Actions/Actions.php12
-rw-r--r--plugins/Actions/tests/Actions.test.php7
-rw-r--r--plugins/AnonymizeIP/AnonymizeIP.php3
-rw-r--r--plugins/CoreAdminHome/Controller.php88
-rw-r--r--plugins/CorePluginsAdmin/Controller.php2
-rw-r--r--plugins/CoreUpdater/Controller.php18
-rw-r--r--plugins/CustomVariables/CustomVariables.php6
-rw-r--r--plugins/DBStats/API.php10
-rw-r--r--plugins/Feedback/Controller.php2
-rw-r--r--plugins/ImageGraph/ImageGraph.php2
-rw-r--r--plugins/Installation/Controller.php34
-rw-r--r--plugins/LanguagesManager/LanguagesManager.php4
-rw-r--r--plugins/Live/Controller.php2
-rw-r--r--plugins/Login/Auth.php4
-rw-r--r--plugins/Login/Controller.php47
-rw-r--r--plugins/Login/Login.php10
-rw-r--r--plugins/Login/tests/Login.test.php14
-rw-r--r--plugins/MultiSites/Controller.php6
-rw-r--r--plugins/PDFReports/API.php6
-rw-r--r--plugins/PDFReports/tests/PDFReports.test.php420
-rw-r--r--plugins/PrivacyManager/Controller.php26
-rw-r--r--plugins/PrivacyManager/PrivacyManager.php10
-rw-r--r--plugins/Provider/Provider.php4
-rw-r--r--plugins/Proxy/tests/Proxy.test.php2
-rw-r--r--plugins/Referers/Referers.php4
-rw-r--r--plugins/UserSettings/UserSettings.php4
-rw-r--r--plugins/UsersManager/API.php2
-rw-r--r--plugins/UsersManager/Controller.php12
-rw-r--r--plugins/UsersManager/tests/UsersManager.test.php27
-rwxr-xr-xtests/TestRunner.php7
-rw-r--r--tests/config_test.php2
-rw-r--r--tests/core/API/DocumentationGenerator.test.php4
-rw-r--r--tests/core/ArchiveProcessing.test.php4
-rw-r--r--tests/core/Config.test.php120
-rw-r--r--tests/core/Config/Writer.test.php107
-rwxr-xr-xtests/core/DataTable/Array.test.php2
-rw-r--r--tests/core/DataTable/Renderer.test.php2
-rw-r--r--tests/core/Database.test.php3
-rw-r--r--tests/core/Http.test.php2
-rw-r--r--tests/core/IP.test.php8
-rw-r--r--tests/core/Nonce.test.php2
-rw-r--r--tests/core/PHP_Related.test.php2
-rw-r--r--tests/core/Piwik.test.php2
-rw-r--r--tests/core/ReleaseCheckList.test.php8
-rw-r--r--tests/core/Segment.test.php4
-rw-r--r--tests/core/TablePartitioning.test.php12
-rw-r--r--tests/core/Tracker/Action.test.php7
-rw-r--r--tests/core/Tracker/Config.test.php37
-rw-r--r--tests/core/Url.test.php8
-rw-r--r--tests/integration/Integration.php691
-rw-r--r--tests/integration/proxy-piwik.php14
-rw-r--r--tests/resources/Tracker/Action.config.ini.php4
101 files changed, 1716 insertions, 1635 deletions
diff --git a/core/Archive.php b/core/Archive.php
index 10f18db892..0004ea8d4d 100644
--- a/core/Archive.php
+++ b/core/Archive.php
@@ -391,8 +391,8 @@ abstract class Piwik_Archive
static public function isSegmentationEnabled()
{
return !Piwik::isUserIsAnonymous()
- || Zend_Registry::get('config')->General->anonymous_user_enable_use_segments_API
- ;
+ || Piwik_Config::getInstance()->General['anonymous_user_enable_use_segments_API']
+ ;
}
/**
diff --git a/core/ArchiveProcessing.php b/core/ArchiveProcessing.php
index 67b6c75481..8eb4e1313f 100644
--- a/core/ArchiveProcessing.php
+++ b/core/ArchiveProcessing.php
@@ -226,19 +226,19 @@ abstract class Piwik_ArchiveProcessing
{
case 'day':
$process = new Piwik_ArchiveProcessing_Day();
- $process->debugAlwaysArchive = Zend_Registry::get('config')->Debug->always_archive_data_day;
+ $process->debugAlwaysArchive = Piwik_Config::getInstance()->Debug['always_archive_data_day'];
break;
case 'week':
case 'month':
case 'year':
$process = new Piwik_ArchiveProcessing_Period();
- $process->debugAlwaysArchive = Zend_Registry::get('config')->Debug->always_archive_data_period;
+ $process->debugAlwaysArchive = Piwik_Config::getInstance()->Debug['always_archive_data_period'];
break;
case 'range':
$process = new Piwik_ArchiveProcessing_Period();
- $process->debugAlwaysArchive = Zend_Registry::get('config')->Debug->always_archive_data_range;
+ $process->debugAlwaysArchive = Piwik_Config::getInstance()->Debug['always_archive_data_range'];
break;
default:
@@ -280,7 +280,7 @@ abstract class Piwik_ArchiveProcessing
{
return $timeToLive;
}
- return Zend_Registry::get('config')->General->time_before_today_archive_considered_outdated;
+ return Piwik_Config::getInstance()->General['time_before_today_archive_considered_outdated'];
}
static public function setBrowserTriggerArchiving($enabled)
@@ -299,7 +299,7 @@ abstract class Piwik_ArchiveProcessing
{
return (bool)$browserArchivingEnabled;
}
- return (bool)Zend_Registry::get('config')->General->enable_browser_archiving_triggering;
+ return (bool)Piwik_Config::getInstance()->General['enable_browser_archiving_triggering'];
}
public function getIdArchive()
@@ -945,7 +945,7 @@ abstract class Piwik_ArchiveProcessing
// if browser archiving is not allowed, then archiving is disabled
if(!$segment->isEmpty()
&& !self::isRequestAuthorizedToArchive()
- && Zend_Registry::get('config')->General->browser_archiving_disabled_enforce
+ && Piwik_Config::getInstance()->General['browser_archiving_disabled_enforce']
)
{
Piwik::log("Archiving is disabled because of config setting browser_archiving_disabled_enforce=1");
diff --git a/core/AssetManager.php b/core/AssetManager.php
index aa6f64e2ad..a484177b5a 100644
--- a/core/AssetManager.php
+++ b/core/AssetManager.php
@@ -324,7 +324,7 @@ class Piwik_AssetManager
*/
private static function getDisableMergedAssets()
{
- return Zend_Registry::get('config')->Debug->disable_merged_assets;
+ return Piwik_Config::getInstance()->Debug['disable_merged_assets'];
}
/**
diff --git a/core/Common.php b/core/Common.php
index de74ecf308..64cdc4e1a3 100644
--- a/core/Common.php
+++ b/core/Common.php
@@ -62,18 +62,7 @@ class Piwik_Common
static $prefixTable = null;
if(is_null($prefixTable))
{
- if(!empty($GLOBALS['PIWIK_TRACKER_MODE']))
- {
- $prefixTable = Piwik_Tracker_Config::getInstance()->database['tables_prefix'];
- }
- else
- {
- $config = Zend_Registry::get('config');
- if($config !== false)
- {
- $prefixTable = $config->database->tables_prefix;
- }
- }
+ $prefixTable = Piwik_Config::getInstance()->database['tables_prefix'];
}
return $prefixTable . $table;
}
@@ -98,7 +87,7 @@ class Piwik_Common
Piwik::createAccessObject();
}
try {
- $config = Zend_Registry::get('config');
+ $config = Piwik_Config::getInstance();
} catch (Exception $e) {
Piwik::createConfigObject();
}
@@ -109,7 +98,7 @@ class Piwik_Common
}
$pluginsManager = Piwik_PluginsManager::getInstance();
- $pluginsToLoad = Zend_Registry::get('config')->Plugins->Plugins->toArray();
+ $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins'];
$pluginsForcedNotToLoad = Piwik_Tracker::getPluginsNotToLoad();
$pluginsToLoad = array_diff($pluginsToLoad, $pluginsForcedNotToLoad);
$pluginsManager->loadPlugins( $pluginsToLoad );
@@ -266,7 +255,7 @@ class Piwik_Common
{
// Currently, there is no hourly tasks. When there are some,
// this could be too agressive minimum interval (some hours would be skipped in case of low traffic)
- $minimumInterval = Piwik_Tracker_Config::getInstance()->Tracker['scheduled_tasks_min_interval'];
+ $minimumInterval = Piwik_Config::getInstance()->Tracker['scheduled_tasks_min_interval'];
// If the user disabled browser archiving, he has already setup a cron
// To avoid parallel requests triggering the Scheduled Tasks,
@@ -888,18 +877,7 @@ class Piwik_Common
static $salt = null;
if(is_null($salt))
{
- if(!empty($GLOBALS['PIWIK_TRACKER_MODE']))
- {
- $salt = @Piwik_Tracker_Config::getInstance()->superuser['salt'];
- }
- else
- {
- $config = Zend_Registry::get('config');
- if($config !== false)
- {
- $salt = @$config->superuser->salt;
- }
- }
+ $salt = @Piwik_Config::getInstance()->superuser['salt'];
}
return $salt;
}
@@ -916,18 +894,7 @@ class Piwik_Common
static $hashAlgorithm = null;
if(is_null($hashAlgorithm))
{
- if(!empty($GLOBALS['PIWIK_TRACKER_MODE']))
- {
- $hashAlgorithm = @Piwik_Tracker_Config::getInstance()->General['hash_algorithm'];
- }
- else
- {
- $config = Zend_Registry::get('config');
- if($config !== false)
- {
- $hashAlgorithm = @$config->General->hash_algorithm;
- }
- }
+ $hashAlgorithm = @Piwik_Config::getInstance()->General['hash_algorithm'];
}
if($hashAlgorithm)
@@ -1381,20 +1348,11 @@ class Piwik_Common
*/
static public function getCampaignParameters()
{
- if(!empty($GLOBALS['PIWIK_TRACKER_MODE']))
- {
- $return = array(
- Piwik_Tracker_Config::getInstance()->Tracker['campaign_var_name'],
- Piwik_Tracker_Config::getInstance()->Tracker['campaign_keyword_var_name'],
- );
- }
- else
- {
- $return = array(
- Zend_Registry::get('config')->Tracker->campaign_var_name,
- Zend_Registry::get('config')->Tracker->campaign_keyword_var_name,
- );
- }
+ $return = array(
+ Piwik_Config::getInstance()->Tracker['campaign_var_name'],
+ Piwik_Config::getInstance()->Tracker['campaign_keyword_var_name'],
+ );
+
foreach($return as &$list)
{
if(strpos($list, ',') !== false)
@@ -1406,6 +1364,7 @@ class Piwik_Common
$list = array($list);
}
}
+
array_walk_recursive($return, 'trim');
return $return;
}
diff --git a/core/Config.php b/core/Config.php
index 3e26d18ec8..3be1733209 100644
--- a/core/Config.php
+++ b/core/Config.php
@@ -11,252 +11,193 @@
*/
/**
- * This class is used to access configuration files values.
- * You can also set these values, the updated configuration files will be written at the end of the script execution.
+ * A lightweight class to access the configuration file(s).
*
- * Example reading a value from the configuration file:
- * $minValue = Zend_Registry::get('config')->General->minimum_memory_limit;
+ * For general performance (and specifically, the Tracker), we use deferred (lazy) initialization
+ * and cache sections. We also avoid any dependency on Zend Framework's Zend_Config.
*
- * will read the value minimumMemoryLimit under the [General] section of the config file
+ * We use a parse_ini_file() wrapper to parse the configuration files, in case php's built-in
+ * function is disabled.
+ *
+ * Example reading a value from the configuration:
+ *
+ * $minValue = Piwik_Config::getInstance()->General['minimum_memory_limit'];
+ *
+ * will read the value minimum_memory_limit under the [General] section of the config file.
+ *
+ * Note: if you want to save your changes, you have to use Piwik_Config_Writer
*
* @package Piwik
* @subpackage Piwik_Config
*/
class Piwik_Config
{
- /**
- * When the user modifies the configuration file and there is one value missing, we suggest the default config file
- *
- * @var string
- */
- protected $urlToPiwikHelpMissingValueInConfigurationFile =
- 'http://dev.piwik.org/trac/browser/trunk/config/global.ini.php?format=raw';
-
- protected $defaultConfig = null;
- protected $userConfig = null;
- protected $pathIniFileUserConfig = null;
- protected $pathIniFileDefaultConfig = null;
- protected $configFileUpdated = false;
- protected $doWriteFileWhenUpdated = true;
- protected $cachedConfigArray = array();
- protected $isTestEnvironment = false;
+ static private $instance = null;
/**
- * Returns default relative path for user configuration file
+ * Returns the singleton Piwik_Config
*
- * @return string
+ * @return Piwik_Config
*/
- static public function getDefaultUserConfigPath()
+ static public function getInstance()
{
- return PIWIK_USER_PATH .'/config/config.ini.php';
+ if (self::$instance == null)
+ {
+ self::$instance = new self;
+ }
+ return self::$instance;
}
/**
- * Returns default relative path for global configuration file
+ * Enable test environment
*
- * @return string
+ * @param string $pathLocal
+ * @param string $pathGlobal
*/
- static public function getDefaultDefaultConfigPath()
+ public function setTestEnvironment($pathLocal = null, $pathGlobal = null)
{
- return PIWIK_USER_PATH .'/config/global.ini.php';
- }
+ $this->clear();
- /**
- * Builds the Config object, given the optional path for the user INI file
- * If not specified, it will use the default path
- *
- * @param string $pathIniFileUserConfig
- */
- function __construct($pathIniFileUserConfig = null, $pathIniFileDefaultConfig = null)
- {
- if(is_null($pathIniFileUserConfig))
+ if ($pathLocal)
+ {
+ $this->pathLocal = $pathLocal;
+ }
+
+ if ($pathGlobal)
{
- $pathIniFileUserConfig = self::getDefaultUserConfigPath();
+ $this->pathGlobal = $pathGlobal;
}
- $this->pathIniFileUserConfig = $pathIniFileUserConfig;
- if(is_null($pathIniFileDefaultConfig))
+ $this->init();
+ if(isset($this->configGlobal['database_tests'])
+ || isset($this->configLocal['database_tests']))
{
- $pathIniFileDefaultConfig = self::getDefaultDefaultConfigPath();
+ $this->__get('database_tests');
+ $this->configCache['database'] = $this->configCache['database_tests'];
}
- $this->pathIniFileDefaultConfig = $pathIniFileDefaultConfig;
}
/**
- * By default, when calling setting configuration values using
- * $config->database = array(...)
- * Piwik will automatically save the updated config file in __destruct()
- * This can be disabled (when setting partial configuration values during the installation process for example)
+ * Contains configuration files values
+ *
+ * @var array
*/
- public function disableSavingConfigurationFileUpdates()
- {
- $this->doWriteFileWhenUpdated = false;
- }
+ protected $initialized = false;
+ protected $configGlobal = array();
+ protected $configLocal = array();
+ protected $configCache = array();
+ protected $pathGlobal = null;
+ protected $pathLocal = null;
- public function init()
+ protected function __construct()
{
- if(!is_readable($this->pathIniFileDefaultConfig))
- {
- Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionConfigurationFileNotFound', array($this->pathIniFileDefaultConfig)));
- }
- $this->defaultConfig = new Piwik_Config_Ini($this->pathIniFileDefaultConfig, null, true);
- if(is_null($this->defaultConfig) || count($this->defaultConfig->toArray()) == 0)
- {
- Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionUnreadableFileDisabledMethod', array($this->pathIniFileDefaultConfig, "parse_ini_file()")));
- }
-
- if(!is_readable($this->pathIniFileUserConfig))
- {
- throw new Exception(Piwik_TranslateException('General_ExceptionConfigurationFileNotFound', array($this->pathIniFileUserConfig)));
- }
- $this->userConfig = new Piwik_Config_Ini($this->pathIniFileUserConfig, null, true);
- if(is_null($this->userConfig) || count($this->userConfig->toArray()) == 0)
- {
- Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionUnreadableFileDisabledMethod', array($this->pathIniFileUserConfig, "parse_ini_file()")));
- }
+ $this->pathGlobal = self::getGlobalConfigPath();
+ $this->pathLocal = self::getLocalConfigPath();
}
/**
- * Write user configuration file
+ * Returns absolute path to the global configuration file
*
- * @param array $globalConfig
- * @param array $userConfig
- * @param string $filename
+ * @return string
*/
- function writeConfig($globalConfig, $userConfig, $filename)
+ static public function getGlobalConfigPath()
{
- $configFile = "; <?php exit; ?> DO NOT REMOVE THIS LINE\n";
- $configFile .= "; file automatically generated or modified by Piwik; you can manually override the default values in global.ini.php by redefining them in this file.\n";
-
- foreach($userConfig as $section => $arraySection)
- {
- $arraySection = $arraySection->toArray();
- $configFile .= "[$section]\n";
- foreach($arraySection as $name => $value)
- {
- if(is_numeric($name))
- {
- $name = $section;
- $value = array($value);
- }
-
- if(is_array($value))
- {
- foreach($value as $currentValue)
- {
- $configFile .= $name."[] = \"$currentValue\"\n";
- }
- }
- else
- {
- if(!is_numeric($value))
- {
- $value = "\"$value\"";
- }
- $configFile .= $name.' = '.$value."\n";
- }
- }
- $configFile .= "\n";
- }
- @file_put_contents($filename, $configFile );
+ return PIWIK_USER_PATH .'/config/global.ini.php';
}
/**
- * At the script shutdown, we save the new configuration file, if the user has set some values
+ * Backward compatibility stub
+ *
+ * @todo remove in 2.0
+ * @since 1.7
+ * @deprecated 1.7
*/
- function __destruct()
+ static public function getDefaultDefaultConfigPath()
{
- if($this->configFileUpdated === true
- && $this->doWriteFileWhenUpdated === true)
- {
- $this->writeConfig($this->defaultConfig, $this->userConfig, $this->pathIniFileUserConfig);
- }
+ return self::getGlobalConfigPath();
}
- public function isFileWritable()
+ /**
+ * Returns absolute path to the local configuration file
+ *
+ * @return string
+ */
+ static public function getLocalConfigPath()
{
- return is_writable($this->pathIniFileUserConfig);
+ return PIWIK_USER_PATH .'/config/config.ini.php';
}
/**
- * If called, we use the database_tests credentials
+ * Is local configuration file writable?
+ *
+ * @return bool
*/
- public function setTestEnvironment()
+ public function isFileWritable()
{
- $this->isTestEnvironment = true;
-
- foreach(Piwik_Tracker_Config::$toRestoreFromGlobalConfig as $section)
- {
- $this->$section = $this->defaultConfig->$section->toArray();
- }
-
- $this->database = $this->database_tests->toArray();
-
- // 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();
-
- $this->disableSavingConfigurationFileUpdates();
+ return is_writable($this->pathLocal);
}
/**
- * Is the config file set to use the test values?
- * @return bool
+ * Clear in-memory configuration so it can be reloaded
*/
- public function isTestEnvironment()
+ public function clear()
{
- return $this->isTestEnvironment;
+ $this->configGlobal = array();
+ $this->configLocal = array();
+ $this->configCache = array();
+ $this->initialized = false;
+
+ $this->pathGlobal = self::getGlobalConfigPath();
+ $this->pathLocal = self::getLocalConfigPath();
}
/**
- * Called when setting configuration values eg.
- * Zend_Registry::get('config')->MyConfigSection = 'foobar';
+ * Read configuration from files into memory
*
- * The values will be saved in the configuration file at the end of the script @see __destruct()
- *
- * @param string $name
- * @param mixed $values
+ * @throws Exception if local config file is not readable; exits for other errors
*/
- public function __set($name, $values)
+ public function init()
{
- $this->cachedConfigArray = array();
- $this->checkWritePermissionOnFile();
- if(is_null($this->userConfig))
+ $this->initialized = true;
+
+ // read defaults from global.ini.php
+ if(!is_readable($this->pathGlobal))
{
- $this->userConfig = new Zend_Config(array(), true);
+ Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionConfigurationFileNotFound', array($this->pathGlobal)));
}
- $values = self::encodeValues($values);
- if(is_array($values)
- || $this->userConfig->$name != $values)
+
+ $this->configGlobal = _parse_ini_file($this->pathGlobal, true);
+ if(empty($this->configGlobal))
{
- $this->configFileUpdated = true;
+ Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionUnreadableFileDisabledMethod', array($this->pathGlobal, "parse_ini_file()")));
}
- $this->userConfig->$name = $values;
- }
- private function encodeValues($values)
- {
- if(is_array($values))
+ // read the local settings from config.ini.php
+ if(!is_readable($this->pathLocal))
{
- foreach($values as &$value)
- {
- $value = self::encodeValues($value);
- }
+ throw new Exception(Piwik_TranslateException('General_ExceptionConfigurationFileNotFound', array($this->pathLocal)));
}
- else
+
+ $this->configLocal = _parse_ini_file($this->pathLocal, true);
+ if(empty($this->configLocal))
{
- $values = htmlentities($values, ENT_COMPAT);
+ Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionUnreadableFileDisabledMethod', array($this->pathLocal, "parse_ini_file()")));
}
- return $values;
}
- private function decodeValues($values)
+ /**
+ * Decode HTML entities
+ *
+ * @param mixed $values
+ * @return mixed
+ */
+ protected function decodeValues($values)
{
if(is_array($values))
{
foreach($values as &$value)
{
- $value = self::decodeValues($value);
+ $value = $this->decodeValues($value);
}
}
else
@@ -266,78 +207,62 @@ class Piwik_Config
return $values;
}
- protected function checkWritePermissionOnFile()
+ /**
+ * Magic get methods catching calls to $config->var_name
+ * Returns the value if found in the configuration
+ *
+ * @param string $name
+ * @return string|array The value requested, returned by reference
+ * @throws Exception if the value requested not found in both files
+ */
+ public function &__get( $name )
{
- static $enoughPermission = null;
- if(is_null($enoughPermission))
+ if(!$this->initialized)
{
- if($this->doWriteFileWhenUpdated)
- {
- Piwik::checkDirectoriesWritableOrDie( array('/config/') );
- }
- $enoughPermission = true;
+ $this->init();
}
- return $enoughPermission;
- }
- /**
- * Loop through the Default and the User configuration objects and cache them in arrays.
- * This slightly helps reducing the Zend overhead when accessing config entries hundreds of times.
- */
- protected function cacheConfigArray()
- {
- $allSections = array();
- foreach($this->defaultConfig as $sectionName => $valueInDefaultConfig)
+ // check cache for merged section
+ if (isset($this->configCache[$name]))
{
- $allSections[] = $sectionName;
+ $tmp =& $this->configCache[$name];
+ return $tmp;
}
- if(!is_null($this->userConfig))
+
+ $section = null;
+
+ // merge corresponding sections from global and local settings
+ if(isset($this->configGlobal[$name]))
{
- foreach($this->userConfig as $sectionName => $valueInUserConfig)
- {
- $allSections[] = $sectionName;
- }
+ $section = $this->configGlobal[$name];
+ }
+ if(isset($this->configLocal[$name]))
+ {
+ // local settings override the global defaults
+ $section = $section
+ ? array_merge($section, $this->configLocal[$name])
+ : $this->configLocal[$name];
}
- $allSections = array_unique($allSections);
- foreach($allSections as $sectionName)
+ if ($section === null)
{
- $section = array();
- if(($valueInDefaultConfig = $this->defaultConfig->$sectionName) !== null)
- {
- $valueInDefaultConfig = $valueInDefaultConfig->toArray();
- $section = array_merge($section, $valueInDefaultConfig);
- }
- if( !is_null($this->userConfig)
- && null !== ($valueInUserConfig = $this->userConfig->$sectionName))
- {
- $valueInUserConfig = $valueInUserConfig->toArray();
- $valueInUserConfig = self::decodeValues($valueInUserConfig);
- $section = array_merge($section, $valueInUserConfig);
- }
- $this->cachedConfigArray[$sectionName] = new Zend_Config($section, true);
+ throw new Exception("Error while trying to read a specific config file entry <b>'$name'</b> from your configuration files.</b>If you just completed a Piwik upgrade, please check that the file config/global.ini.php was overwritten by the latest Piwik version.");
}
+
+ // cache merged section for later
+ $this->configCache[$name] = $this->decodeValues($section);
+ $tmp =& $this->configCache[$name];
+ return $tmp;
}
/**
- * Called when getting a configuration value, eg. Zend_Registry::get('config')->superuser->login
+ * Set value
*
- * @param string $name
- * @return mixed value
- *
- * @throws exception if the value was not found in the configuration file
+ * @param string $name This corresponds to the section name
+ * @param mixed $value
*/
- public function __get($name)
+ public function __set($name, $value)
{
- if(empty($this->cachedConfigArray))
- {
- $this->cacheConfigArray();
- }
- if(!isset($this->cachedConfigArray[$name]))
- {
- throw new Exception("Error while trying to read a specific config file entry <b>'$name'</b> in your configuration file <b>config/global.ini.php</b>
- This problem would usually appear after a Piwik upgrade. If so, please check that the file config/global.ini.php was overwritten with the equivalent file from the latest Piwik version.");
- }
- return $this->cachedConfigArray[$name];
+ $this->configCache[$name] = $value;
}
}
diff --git a/core/Config/Compat.php b/core/Config/Compat.php
new file mode 100644
index 0000000000..ea238d52d7
--- /dev/null
+++ b/core/Config/Compat.php
@@ -0,0 +1,149 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ * @version $Id: Config.php $
+ *
+ * @category Piwik
+ * @package Piwik
+ */
+
+/**
+ * Backward compatibility ayer
+ *
+ * @todo remove this in 2.0
+ * @since 1.7
+ * @deprecated 1.7
+ * @see Piwik::createConfigObject()
+ *
+ * @package Piwik
+ * @subpackage Piwik_Config
+ */
+class Piwik_Config_Compat_Array
+{
+ private $data;
+
+ /**
+ * Constructor
+ *
+ * @param array $data configuration section
+ */
+ public function __construct(array $data)
+ {
+ $this->data = $data;
+ }
+
+ /**
+ * Get value by name
+ *
+ * @param string $name
+ * @return mixed
+ */
+ public function __get($name)
+ {
+ $tmp = $this->data[$name];
+ return is_array($tmp) ? new Piwik_Config_Compat_Array($tmp) : $tmp;
+ }
+
+ /**
+ * Set name, value pair
+ *
+ * @param string $name
+ * @param mixed $value
+ */
+ public function __set($name, $value)
+ {
+ if (is_object($value) && get_class($value) == 'Piwik_Config_Compat_Array')
+ {
+ $value = $value->toArray();
+ }
+
+ $this->data[$name] = $value;
+ }
+
+ /**
+ * Convert object to array
+ *
+ * @return array
+ */
+ public function toArray()
+ {
+ return $this->data;
+ }
+}
+
+class Piwik_Config_Compat
+{
+ private $config;
+ private $data;
+ private $enabled;
+
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ $this->config = Piwik_Config_Writer::getInstance();
+ $this->data = array();
+ $this->enabled = true;
+ }
+
+ /**
+ * Destructor
+ */
+ public function __destruct()
+ {
+ if ($this->enabled)
+ {
+ $this->config->forceSave();
+ Piwik_Config::getInstance()->clear();
+ }
+ else
+ {
+ $this->config->clear();
+ }
+ }
+
+ /**
+ * Get value by name
+ *
+ * @param string $name
+ * @return mixed
+ */
+ public function __get($name)
+ {
+ if (!isset($this->data[$name]))
+ {
+ $this->data[$name] = $this->config->__get($name);
+ }
+
+ $tmp = $this->data[$name];
+ return is_array($tmp) ? new Piwik_Config_Compat_Array($tmp) : $tmp;
+ }
+
+ /**
+ * Set name, value pair
+ *
+ * @param string $name
+ * @param mixed $value
+ */
+ public function __set($name, $value)
+ {
+ if (is_object($value) && get_class($value) == 'Piwik_Config_Compat_Array')
+ {
+ $value = $value->toArray();
+ }
+
+ $this->config->__set($name, $value);
+ }
+
+ /**
+ * Disable saving of configuration changes
+ */
+ public function disableSavingConfigurationFileUpdates()
+ {
+ $this->enabled = false;
+ }
+}
diff --git a/core/Config/Ini.php b/core/Config/Ini.php
deleted file mode 100644
index 22b02560a7..0000000000
--- a/core/Config/Ini.php
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-/**
- * Piwik - Open source web analytics
- *
- * @link http://piwik.org
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- * @version $Id$
- *
- * @category Piwik
- * @package Piwik
- */
-
-/**
- * Subclasses Zend_Config_Ini so we can use our own parse_ini_file() wrapper.
- *
- * @package Piwik
- * @subpackage Piwik_Config
- */
-class Piwik_Config_Ini extends Zend_Config_Ini
-{
- /**
- * Handle any errors from parse_ini_file
- *
- * @param integer $errno
- * @param string $errstr
- * @param string $errfile
- * @param integer $errline
- */
- public function _parseFileErrorHandler($errno, $errstr, $errfile, $errline)
- {
- $this->_loadFileErrorHandler($errno, $errstr, $errfile, $errline);
- }
-
- /**
- * Load ini file configuration
- *
- * Derived from Zend_Config_Ini->_loadIniFile() and Zend_Config_Ini->_parseIniFile()
- * @license New BSD License
- *
- * @param string $filename
- * @return array
- */
- protected function _loadIniFile($filename)
- {
- set_error_handler(array($this, '_parseFileErrorHandler'));
- $iniArray = _parse_ini_file($filename, true);
- restore_error_handler();
- // Check if there was an error while loading the file
- if ($this->_loadFileErrorStr !== null) {
- throw new Zend_Config_Exception($this->_loadFileErrorStr);
- }
-
- return $iniArray;
- }
-}
diff --git a/core/Config/Writer.php b/core/Config/Writer.php
new file mode 100644
index 0000000000..b605ecdeb2
--- /dev/null
+++ b/core/Config/Writer.php
@@ -0,0 +1,228 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ * @version $Id$
+ *
+ * @category Piwik
+ * @package Piwik
+ */
+
+/**
+ * This class extends the base Piwik_Config class to save in-memory changes to the local
+ * configuration file.
+ *
+ * Example reading a value from the configuration:
+ *
+ * $minValue = Piwik_Config_Writer::getInstance()->General['minimum_memory_limit'];
+ *
+ * will read the value minimum_memory_limit under the [General] section of the config file.
+ *
+ * Example setting a section in the configuration:
+ *
+ * $brandingConfig = array(
+ * 'use_custom_logo' => 1,
+ * );
+ * Piwik_Config_Writer::getInstance()->setConfigSection('branding', $brandingConfig);
+ *
+ * Example setting an option within a section in the configuration:
+ *
+ * Piwik_Config_Writer::getInstance()->setConfigOption('branding', 'use_custom_logo', '1');
+ *
+ * @package Piwik
+ * @subpackage Piwik_Config
+ */
+class Piwik_Config_Writer extends Piwik_Config
+{
+ static private $instance = null;
+
+ /**
+ * Returns the singleton Piwik_Config
+ *
+ * @return Piwik_Config
+ */
+ static public function getInstance()
+ {
+ if (self::$instance == null)
+ {
+ self::$instance = new self;
+ }
+ return self::$instance;
+ }
+
+ /**
+ * Read configuration files into memory
+ *
+ * @throws Exception if file is not read/writable or contains no configuration
+ */
+ public function init()
+ {
+ Piwik::checkDirectoriesWritableOrDie( array('/config/') );
+
+ if(file_exists($this->pathLocal)
+ && !is_writable($this->pathLocal))
+ {
+ throw new Exception(Piwik_TranslateException('General_ExceptionUnwritableFileDisabledMethod', array($this->pathLocal)));
+ }
+
+ parent::init();
+ }
+
+ /**
+ * Comparison function
+ *
+ * @param mixed $elem1
+ * @param mixed $elem2
+ * @return int;
+ */
+ static function compareElements($elem1, $elem2)
+ {
+ if (is_array($elem1)) {
+ if (is_array($elem2))
+ {
+ return strcmp(serialize($elem1), serialize($elem2));
+ }
+ return 1;
+ }
+ if (is_array($elem2))
+ return -1;
+
+ if ((string)$elem1 === (string)$elem2)
+ return 0;
+
+ return ((string)$elem1 > (string)$elem2) ? 1 : -1;
+ }
+
+ /**
+ * Compare arrays and return difference, such that:
+ *
+ * $modified = array_merge($original, $difference);
+ *
+ * @param array $original original array
+ * @param array $modified modified array
+ * @return array differences between original and modified
+ */
+ public function array_unmerge($original, $modified)
+ {
+ // return key/value pairs for keys in $modified but not in $original
+ // return key/value pairs for keys in both $modified and $original, but values differ
+ // ignore keys that are in $original but not in $modified
+
+ return array_udiff_assoc($modified, $original, array(__CLASS__, 'compareElements'));
+ }
+
+ /**
+ * Encode HTML entities
+ *
+ * @param mixed $values
+ * @return mixed
+ */
+ protected function encodeValues($values)
+ {
+ if(is_array($values))
+ {
+ foreach($values as &$value)
+ {
+ $value = $this->encodeValues($value);
+ }
+ }
+ else
+ {
+ $values = htmlentities($values, ENT_COMPAT);
+ }
+ return $values;
+ }
+
+ /**
+ * Write user configuration file
+ *
+ * @param array $configLocal
+ * @param array $configGlobal
+ * @param array $configCache
+ * @param string $pathLocal
+ */
+ public function writeConfig($configLocal, $configGlobal, $configCache, $pathLocal)
+ {
+ $dirty = false;
+
+ $output = "; <?php exit; ?> DO NOT REMOVE THIS LINE\n";
+ $output .= "; file automatically generated or modified by Piwik; you can manually override the default values in global.ini.php by redefining them in this file.\n";
+
+ if ($configCache)
+ {
+ foreach($configLocal as $name => $section)
+ {
+ if (!isset($configCache[$name]))
+ {
+ $configCache[$name] = $this->decodeValues($section);
+ }
+ }
+
+ foreach($configCache as $name => $section)
+ {
+ $configLocal = $this->array_unmerge($configGlobal[$name], $configCache[$name]);
+ if (count($configLocal) == 0)
+ {
+ continue;
+ }
+
+ $dirty = true;
+
+ $output .= "[$name]\n";
+
+ foreach($configLocal as $name => $value)
+ {
+ $value = $this->encodeValues($value);
+
+ if(is_numeric($name))
+ {
+ $name = $section;
+ $value = array($value);
+ }
+
+ if(is_array($value))
+ {
+ foreach($value as $currentValue)
+ {
+ $output .= $name."[] = \"$currentValue\"\n";
+ }
+ }
+ else
+ {
+ if(!is_numeric($value))
+ {
+ $value = "\"$value\"";
+ }
+ $output .= $name.' = '.$value."\n";
+ }
+ }
+ $output .= "\n";
+ }
+
+ if ($dirty)
+ {
+ @file_put_contents($pathLocal, $output );
+ }
+ }
+
+ $this->clear();
+ }
+
+ /**
+ * Force save
+ */
+ public function forceSave()
+ {
+ $this->writeConfig($this->configLocal, $this->configGlobal, $this->configCache, $this->pathLocal);
+ }
+
+ /**
+ * At the script shutdown, we save the new configuration file, if the user has set some values
+ */
+ public function __destruct()
+ {
+ $this->forceSave();
+ }
+}
diff --git a/core/Controller.php b/core/Controller.php
index 19b29f5d2c..82f5233574 100644
--- a/core/Controller.php
+++ b/core/Controller.php
@@ -462,14 +462,14 @@ abstract class Piwik_Controller
protected function setBasicVariablesView($view)
{
$view->topMenu = Piwik_GetTopMenu();
- $view->debugTrackVisitsInsidePiwikUI = Zend_Registry::get('config')->Debug->track_visits_inside_piwik_ui;
+ $view->debugTrackVisitsInsidePiwikUI = Piwik_Config::getInstance()->Debug['track_visits_inside_piwik_ui'];
$view->isSuperUser = Zend_Registry::get('access')->isSuperUser();
- $view->isCustomLogo = Zend_Registry::get('config')->branding->use_custom_logo;
+ $view->isCustomLogo = Piwik_Config::getInstance()->branding['use_custom_logo'];
$view->logoHeader = Piwik_API_API::getInstance()->getHeaderLogoUrl();
$view->logoLarge = Piwik_API_API::getInstance()->getLogoUrl();
- $view->enableFrames = Zend_Registry::get('config')->General->enable_framed_pages
- || Zend_Registry::get('config')->General->enable_framed_logins;
+ $view->enableFrames = Piwik_Config::getInstance()->General['enable_framed_pages']
+ || Piwik_Config::getInstance()->General['enable_framed_logins'];
if(!$view->enableFrames)
{
$view->setXFrameOptions('sameorigin');
@@ -674,7 +674,7 @@ abstract class Piwik_Controller
$userSettingsDate = Piwik_UsersManager_API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE);
if($userSettingsDate === false)
{
- return Zend_Registry::get('config')->General->default_day;
+ return Piwik_Config::getInstance()->General['default_day'];
}
if($userSettingsDate == 'yesterday')
{
@@ -698,7 +698,7 @@ abstract class Piwik_Controller
$userSettingsDate = Piwik_UsersManager_API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE);
if($userSettingsDate === false)
{
- return Zend_Registry::get('config')->General->default_period;
+ return Piwik_Config::getInstance()->General['default_period'];
}
if(in_array($userSettingsDate, array('today','yesterday')))
{
diff --git a/core/Controller/Admin.php b/core/Controller/Admin.php
index 1aafd2a9a7..8a66fe0fa8 100644
--- a/core/Controller/Admin.php
+++ b/core/Controller/Admin.php
@@ -28,7 +28,7 @@ abstract class Piwik_Controller_Admin extends Piwik_Controller
$view->currentAdminMenuName = Piwik_GetCurrentAdminMenuName();
- $view->enableFrames = Zend_Registry::get('config')->General->enable_framed_settings;
+ $view->enableFrames = Piwik_Config::getInstance()->General['enable_framed_settings'];
if(!$view->enableFrames)
{
$view->setXFrameOptions('sameorigin');
diff --git a/core/DataTable.php b/core/DataTable.php
index 01e16aecd4..33f86c5163 100644
--- a/core/DataTable.php
+++ b/core/DataTable.php
@@ -998,7 +998,7 @@ class Piwik_DataTable
// we then serialize the rows and store them in the serialized dataTable
$addToRows = array( self::ID_SUMMARY_ROW => $this->summaryRow );
- if ($this->parents && Zend_Registry::get('config')->General->enable_archive_parents_of_datatable)
+ if ($this->parents && Piwik_Config::getInstance()->General['enable_archive_parents_of_datatable'])
{
$addToRows[self::ID_PARENTS] = $this->parents;
}
diff --git a/core/Db/Adapter/Mysqli.php b/core/Db/Adapter/Mysqli.php
index c2fceb69cf..f4a926058f 100644
--- a/core/Db/Adapter/Mysqli.php
+++ b/core/Db/Adapter/Mysqli.php
@@ -47,11 +47,11 @@ class Piwik_Db_Adapter_Mysqli extends Zend_Db_Adapter_Mysqli implements Piwik_Db
public function checkServerVersion()
{
$serverVersion = $this->getServerVersion();
- $requiredVersion = Zend_Registry::get('config')->General->minimum_mysql_version;
- if(version_compare($serverVersion, $requiredVersion) === -1)
- {
- throw new Exception(Piwik_TranslateException('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion)));
- }
+ $requiredVersion = Piwik_Config::getInstance()->General['minimum_mysql_version'];
+ if(version_compare($serverVersion, $requiredVersion) === -1)
+ {
+ throw new Exception(Piwik_TranslateException('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion)));
+ }
}
/**
diff --git a/core/Db/Adapter/Pdo/Mssql.php b/core/Db/Adapter/Pdo/Mssql.php
index 9fc63cc17d..f126da4d57 100644
--- a/core/Db/Adapter/Pdo/Mssql.php
+++ b/core/Db/Adapter/Pdo/Mssql.php
@@ -134,7 +134,7 @@ class Piwik_Db_Pdo_Mssql extends Zend_Db_Adapter_Pdo_Mssql implements Piwik_Db_A
public function checkServerVersion()
{
$serverVersion = $this->getServerVersion();
- $requiredVersion = Zend_Registry::get('config')->General->minimum_mssql_version;
+ $requiredVersion = Piwik_Config::getInstance()->General['minimum_mssql_version'];
if(version_compare($serverVersion, $requiredVersion) === -1)
{
throw new Exception(Piwik_TranslateException('General_ExceptionDatabaseVersion', array('MSSQL', $serverVersion, $requiredVersion)));
@@ -248,7 +248,7 @@ class Piwik_Db_Pdo_Mssql extends Zend_Db_Adapter_Pdo_Mssql implements Piwik_Db_A
try
{
$version = $this->_connection->getAttribute(PDO::ATTR_CLIENT_VERSION);
- $requiredVersion = Zend_Registry::get('config')->General->minimum_mssql_client_version;
+ $requiredVersion = Piwik_Config::getInstance()->General['minimum_mssql_client_version'];
if(version_compare($version['DriverVer'], $requiredVersion) === -1)
{
throw new Exception(Piwik_TranslateException('General_ExceptionDatabaseVersion', array('MSSQL', $serverVersion, $requiredVersion)));
diff --git a/core/Db/Adapter/Pdo/Mysql.php b/core/Db/Adapter/Pdo/Mysql.php
index 76b313c564..e2c7ce2a61 100644
--- a/core/Db/Adapter/Pdo/Mysql.php
+++ b/core/Db/Adapter/Pdo/Mysql.php
@@ -79,7 +79,7 @@ class Piwik_Db_Adapter_Pdo_Mysql extends Zend_Db_Adapter_Pdo_Mysql implements Pi
public function checkServerVersion()
{
$serverVersion = $this->getServerVersion();
- $requiredVersion = Zend_Registry::get('config')->General->minimum_mysql_version;
+ $requiredVersion = Piwik_Config::getInstance()->General['minimum_mysql_version'];
if(version_compare($serverVersion, $requiredVersion) === -1)
{
throw new Exception(Piwik_TranslateException('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion)));
diff --git a/core/Db/Adapter/Pdo/Pgsql.php b/core/Db/Adapter/Pdo/Pgsql.php
index 459f611cc8..ebe2a33912 100644
--- a/core/Db/Adapter/Pdo/Pgsql.php
+++ b/core/Db/Adapter/Pdo/Pgsql.php
@@ -40,7 +40,7 @@ class Piwik_Db_Adapter_Pdo_Pgsql extends Zend_Db_Adapter_Pdo_Pgsql implements Pi
public function checkServerVersion()
{
$databaseVersion = $this->getServerVersion();
- $requiredVersion = Zend_Registry::get('config')->General->minimum_pgsql_version;
+ $requiredVersion = Piwik_Config::getInstance()->General['minimum_pgsql_version'];
if(version_compare($databaseVersion, $requiredVersion) === -1)
{
throw new Exception(Piwik_TranslateException('General_ExceptionDatabaseVersion', array('PostgreSQL', $databaseVersion, $requiredVersion)));
diff --git a/core/Db/Schema.php b/core/Db/Schema.php
index c96bf3d6bc..de9f9418db 100644
--- a/core/Db/Schema.php
+++ b/core/Db/Schema.php
@@ -125,8 +125,8 @@ class Piwik_Db_Schema
Piwik_PostEvent('Schema.loadSchema', $schema);
if($schema === null)
{
- $config = Zend_Registry::get('config');
- $dbInfos = $config->database->toArray();
+ $config = Piwik_Config::getInstance();
+ $dbInfos = $config->database;
if(isset($dbInfos['schema']))
{
$schemaName = $dbInfos['schema'];
diff --git a/core/Db/Schema/Myisam.php b/core/Db/Schema/Myisam.php
index d32fdeec80..dbe12367a6 100644
--- a/core/Db/Schema/Myisam.php
+++ b/core/Db/Schema/Myisam.php
@@ -53,8 +53,8 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
*/
public function getTablesCreateSql()
{
- $config = Zend_Registry::get('config');
- $prefixTables = $config->database->tables_prefix;
+ $config = Piwik_Config::getInstance();
+ $prefixTables = $config->database['tables_prefix'];
$tables = array(
'user' => "CREATE TABLE {$prefixTables}user (
login VARCHAR(100) NOT NULL,
@@ -409,8 +409,8 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
public function getTablesNames()
{
$aTables = array_keys($this->getTablesCreateSql());
- $config = Zend_Registry::get('config');
- $prefixTables = $config->database->tables_prefix;
+ $config = Piwik_Config::getInstance();
+ $prefixTables = $config->database['tables_prefix'];
$return = array();
foreach($aTables as $table)
{
@@ -434,8 +434,8 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
|| $forceReload === true)
{
$db = Zend_Registry::get('db');
- $config = Zend_Registry::get('config');
- $prefixTables = $config->database->tables_prefix;
+ $config = Piwik_Config::getInstance();
+ $prefixTables = $config->database['tables_prefix'];
// '_' matches any character; force it to be literal
$prefixTables = str_replace('_', '\_', $prefixTables);
@@ -479,7 +479,7 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
{
if(is_null($dbName))
{
- $dbName = Zend_Registry::get('config')->database->dbname;
+ $dbName = Piwik_Config::getInstance()->database['dbname'];
}
Piwik_Exec("CREATE DATABASE IF NOT EXISTS ".$dbName." DEFAULT CHARACTER SET utf8");
}
@@ -489,7 +489,7 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
*/
public function dropDatabase()
{
- $dbName = Zend_Registry::get('config')->database->dbname;
+ $dbName = Piwik_Config::getInstance()->database['dbname'];
Piwik_Exec("DROP DATABASE IF EXISTS " . $dbName);
}
@@ -500,8 +500,8 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
public function createTables()
{
$db = Zend_Registry::get('db');
- $config = Zend_Registry::get('config');
- $prefixTables = $config->database->tables_prefix;
+ $config = Piwik_Config::getInstance();
+ $prefixTables = $config->database['tables_prefix'];
$tablesAlreadyInstalled = $this->getTablesInstalled();
$tablesToCreate = $this->getTablesCreateSql();
diff --git a/core/FrontController.php b/core/FrontController.php
index c6ad7b873f..a5cac6615d 100644
--- a/core/FrontController.php
+++ b/core/FrontController.php
@@ -240,7 +240,7 @@ class Piwik_FrontController
Piwik_Session::start();
}
- if(Zend_Registry::get('config')->General->maintenance_mode == 1
+ if(Piwik_Config::getInstance()->General['maintenance_mode'] == 1
&& !Piwik_Common::isPhpCliMode())
{
$format = Piwik_Common::getRequestVar('format', '');
@@ -256,7 +256,7 @@ class Piwik_FrontController
if(!Piwik_Common::isPhpCliMode()
- && Zend_Registry::get('config')->General->force_ssl == 1
+ && Piwik_Config::getInstance()->General['force_ssl'] == 1
&& !Piwik::isHttps())
{
$url = Piwik_Url::getCurrentUrl();
@@ -266,7 +266,7 @@ class Piwik_FrontController
$pluginsManager = Piwik_PluginsManager::getInstance();
- $pluginsToLoad = Zend_Registry::get('config')->Plugins->Plugins->toArray();
+ $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins'];
$pluginsManager->loadPlugins( $pluginsToLoad );
if($exceptionToThrow)
diff --git a/core/Http.php b/core/Http.php
index ed0e4a62d7..779e056762 100644
--- a/core/Http.php
+++ b/core/Http.php
@@ -109,24 +109,10 @@ class Piwik_Http
$userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Piwik/'.Piwik_Version::VERSION;
// proxy configuration
- if(!empty($GLOBALS['PIWIK_TRACKER_MODE']))
- {
- $proxyHost = Piwik_Tracker_Config::getInstance()->proxy['host'];
- $proxyPort = Piwik_Tracker_Config::getInstance()->proxy['port'];
- $proxyUser = Piwik_Tracker_Config::getInstance()->proxy['username'];
- $proxyPassword = Piwik_Tracker_Config::getInstance()->proxy['password'];
- }
- else
- {
- $config = Zend_Registry::get('config');
- if($config !== false)
- {
- $proxyHost = $config->proxy->host;
- $proxyPort = $config->proxy->port;
- $proxyUser = $config->proxy->username;
- $proxyPassword = $config->proxy->password;
- }
- }
+ $proxyHost = Piwik_Config::getInstance()->proxy['host'];
+ $proxyPort = Piwik_Config::getInstance()->proxy['port'];
+ $proxyUser = Piwik_Config::getInstance()->proxy['username'];
+ $proxyPassword = Piwik_Config::getInstance()->proxy['password'];
if($method == 'socket')
{
diff --git a/core/IP.php b/core/IP.php
index 3d4fbee5fb..8e52059abe 100644
--- a/core/IP.php
+++ b/core/IP.php
@@ -357,19 +357,7 @@ class Piwik_IP
*/
static public function getIpFromHeader()
{
- $clientHeaders = null;
- if(!empty($GLOBALS['PIWIK_TRACKER_MODE']))
- {
- $clientHeaders = @Piwik_Tracker_Config::getInstance()->General['proxy_client_headers'];
- }
- else
- {
- $config = Zend_Registry::get('config');
- if($config !== false && isset($config->General->proxy_client_headers))
- {
- $clientHeaders = $config->General->proxy_client_headers->toArray();
- }
- }
+ $clientHeaders = @Piwik_Config::getInstance()->General['proxy_client_headers'];
if(!is_array($clientHeaders))
{
$clientHeaders = array();
@@ -394,24 +382,7 @@ class Piwik_IP
*/
static public function getNonProxyIpFromHeader($default, $proxyHeaders)
{
- $proxyIps = null;
- if(!empty($GLOBALS['PIWIK_TRACKER_MODE']))
- {
- $proxyIps = @Piwik_Tracker_Config::getInstance()->General['proxy_ips'];
- }
- else
- {
- try {
- $config = Zend_Registry::get('config');
- } catch(Exception $e) {
- $config = false;
- }
-
- if($config !== false && isset($config->General->proxy_ips))
- {
- $proxyIps = $config->General->proxy_ips->toArray();
- }
- }
+ $proxyIps = @Piwik_Config::getInstance()->General['proxy_ips'];
if(!is_array($proxyIps))
{
$proxyIps = array();
diff --git a/core/Log.php b/core/Log.php
index c13f504d55..c4523c1748 100644
--- a/core/Log.php
+++ b/core/Log.php
@@ -36,7 +36,7 @@ abstract class Piwik_Log extends Zend_Log
$this->currentRequestKey = substr( Piwik_Common::generateUniqId(), 0, 8);
- $log_dir = Zend_Registry::get('config')->log->logger_file_path;
+ $log_dir = Piwik_Config::getInstance()->log['logger_file_path'];
if($log_dir[0] != '/' && $log_dir[0] != DIRECTORY_SEPARATOR)
{
$log_dir = PIWIK_USER_PATH . '/' . $log_dir;
diff --git a/core/Mail.php b/core/Mail.php
index 1aceab1b62..1abe8f0cb3 100644
--- a/core/Mail.php
+++ b/core/Mail.php
@@ -31,7 +31,7 @@ class Piwik_Mail extends Zend_Mail
public function setFrom($email, $name = null)
{
- $hostname = Zend_Registry::get('config')->mail->defaultHostnameIfEmpty;
+ $hostname = Piwik_Config::getInstance()->mail['defaultHostnameIfEmpty'];
$piwikHost = Piwik_Url::getCurrentHost($hostname);
// If known Piwik URL, use it instead of "localhost"
@@ -49,24 +49,24 @@ class Piwik_Mail extends Zend_Mail
private function initSmtpTransport()
{
- $config = Zend_Registry::get('config')->mail;
- if ( empty($config->host)
- || $config->transport != 'smtp')
+ $mailConfig = Piwik_Config::getInstance()->mail;
+ if ( empty($mailConfig['host'])
+ || $mailConfig['transport'] != 'smtp')
{
return;
}
$smtpConfig = array();
- if (!empty($config->type))
- $smtpConfig['auth'] = strtolower($config->type);
- if (!empty($config->username))
- $smtpConfig['username'] = $config->username;
- if (!empty($config->password))
- $smtpConfig['password'] = $config->password;
- if (!empty($config->encryption))
- $smtpConfig['ssl'] = $config->encryption;
+ if (!empty($mailConfig['type']))
+ $smtpConfig['auth'] = strtolower($mailConfig['type']);
+ if (!empty($mailConfig['username']))
+ $smtpConfig['username'] = $mailConfig['username'];
+ if (!empty($mailConfig['password']))
+ $smtpConfig['password'] = $mailConfig['password'];
+ if (!empty($mailConfig['encryption']))
+ $smtpConfig['ssl'] = $mailConfig['encryption'];
- $tr = new Zend_Mail_Transport_Smtp($config->host, $smtpConfig);
+ $tr = new Zend_Mail_Transport_Smtp($mailConfig['host'], $smtpConfig);
Piwik_Mail::setDefaultTransport($tr);
- ini_set("smtp_port", $config->port);
+ ini_set("smtp_port", $mailConfig['port']);
}
}
diff --git a/core/Piwik.php b/core/Piwik.php
index 0095cc0b34..3757810367 100644
--- a/core/Piwik.php
+++ b/core/Piwik.php
@@ -49,7 +49,7 @@ class Piwik
static public function isUniqueVisitorsEnabled($periodLabel)
{
return in_array($periodLabel, array('day', 'week', 'month'))
- || Zend_Registry::get('config')->General->enable_processing_unique_visitors_year_and_range ;
+ || Piwik_Config::getInstance()->General['enable_processing_unique_visitors_year_and_range'];
}
/*
@@ -96,7 +96,7 @@ class Piwik
*/
static public function install()
{
- Piwik_Common::mkdir(PIWIK_USER_PATH . '/' . Zend_Registry::get('config')->smarty->compile_dir);
+ Piwik_Common::mkdir(PIWIK_USER_PATH . '/' . Piwik_Config::getInstance()->smarty['compile_dir']);
}
/**
@@ -1029,14 +1029,14 @@ class Piwik
{
return false;
}
- $minimumMemoryLimit = Zend_Registry::get('config')->General->minimum_memory_limit;
+ $minimumMemoryLimit = Piwik_Config::getInstance()->General['minimum_memory_limit'];
if(Piwik_Common::isArchivePhpTriggered()
&& Piwik::isUserIsSuperUser())
{
// archive.php: no time limit, high memory limit
self::setMaxExecutionTime(0);
- $minimumMemoryLimitWhenArchiving = Zend_Registry::get('config')->General->minimum_memory_limit_when_archiving;
+ $minimumMemoryLimitWhenArchiving = Piwik_Config::getInstance()->General['minimum_memory_limit_when_archiving'];
if($memoryLimit < $minimumMemoryLimitWhenArchiving)
{
return self::setMemoryLimit($minimumMemoryLimitWhenArchiving);
@@ -1084,9 +1084,9 @@ class Piwik
{
try {
$shouldLog = (Piwik_Common::isPhpCliMode()
- || Zend_Registry::get('config')->log->log_only_when_cli == 0)
+ || Piwik_Config::getInstance()->log['log_only_when_cli'] == 0)
&&
- ( Zend_Registry::get('config')->log->log_only_when_debug_parameter == 0
+ ( Piwik_Config::getInstance()->log['log_only_when_debug_parameter'] == 0
|| isset($_REQUEST['debug']))
;
} catch(Exception $e) {
@@ -1603,8 +1603,8 @@ class Piwik
*/
static public function getWebsitesCountToDisplay()
{
- $count = max(Zend_Registry::get('config')->General->site_selector_max_sites,
- Zend_Registry::get('config')->General->autocomplete_min_sites);
+ $count = max(Piwik_Config::getInstance()->General['site_selector_max_sites'],
+ Piwik_Config::getInstance()->General['autocomplete_min_sites']);
return (int)$count;
}
@@ -1617,7 +1617,7 @@ class Piwik
if (is_null($cachedResult))
{
- $segments = Zend_Registry::get('config')->Segments->toArray();
+ $segments = Piwik_Config::getInstance()->Segments;
$cachedResult = isset($segments['Segments']) ? $segments['Segments'] : '';
}
@@ -1650,8 +1650,8 @@ class Piwik
*/
static public function getSuperUserEmail()
{
- $superuser = Zend_Registry::get('config')->superuser;
- return $superuser->email;
+ $superuser = Piwik_Config::getInstance()->superuser;
+ return $superuser['email'];
}
/**
@@ -1964,16 +1964,16 @@ class Piwik
*/
static public function createDatabaseObject( $dbInfos = null )
{
- $config = Zend_Registry::get('config');
+ $config = Piwik_Config::getInstance();
if(is_null($dbInfos))
{
- $dbInfos = $config->database->toArray();
+ $dbInfos = $config->database;
}
Piwik_PostEvent('Reporting.getDatabaseConfig', $dbInfos);
- $dbInfos['profiler'] = $config->Debug->enable_sql_profiler;
+ $dbInfos['profiler'] = $config->Debug['enable_sql_profiler'];
$db = null;
Piwik_PostEvent('Reporting.createDatabase', $db);
@@ -2025,7 +2025,7 @@ class Piwik
*/
static public function createLogObject()
{
- $configAPI = Zend_Registry::get('config')->log;
+ $configAPI = Piwik_Config::getInstance()->log;
$aLoggers = array(
'logger_api_call' => new Piwik_Log_APICall,
@@ -2080,14 +2080,15 @@ class Piwik
/**
* Create configuration object
- *
- * @param string $pathConfigFile
*/
- static public function createConfigObject( $pathConfigFile = null )
+ static public function createConfigObject()
{
- $config = new Piwik_Config($pathConfigFile);
- Zend_Registry::set('config', $config);
+ // instantiate the singleton
+ $config = Piwik_Config::getInstance();
$config->init();
+
+ // for backward compatibility
+ Zend_Registry::set('config', new Piwik_Config_Compat());
}
/*
@@ -2150,7 +2151,7 @@ class Piwik
*/
static public function isChecksEnabled()
{
- return Zend_Registry::get('config')->General->disable_checks_usernames_attributes == 0;
+ return Piwik_Config::getInstance()->General['disable_checks_usernames_attributes'] == 0;
}
/**
@@ -2413,7 +2414,7 @@ class Piwik
);
// hack for charset mismatch
- if(!self::isDatabaseConnectionUTF8() && !isset(Zend_Registry::get('config')->database->charset))
+ if(!self::isDatabaseConnectionUTF8() && !isset(Piwik_Config::getInstance()->database['charset']))
{
$fileSpec['charset'] = 'latin1';
}
@@ -2473,17 +2474,17 @@ class Piwik
*/
static public function getArchiveProcessingLockName($idsite, $period, Piwik_Segment $segment)
{
- $config = Zend_Registry::get('config');
+ $config = Piwik_Config::getInstance();
$lockName = 'piwik.'
- . $config->database->dbname . '.'
- . $config->database->tables_prefix . '/'
+ . $config->database['dbname'] . '.'
+ . $config->database['tables_prefix'] . '/'
. $idsite . '/'
. (!$segment->isEmpty() ? $segment->getHash().'/' : '' )
. $period->getId() . '/'
. $period->getDateStart()->toString('Y-m-d') . ','
. $period->getDateEnd()->toString('Y-m-d');
- return $lockName .'/'. md5($lockName . $config->superuser->salt);
+ return $lockName .'/'. md5($lockName . $config->superuser['salt']);
}
/**
diff --git a/core/PluginsManager.php b/core/PluginsManager.php
index f164cd2f17..75008bd878 100644
--- a/core/PluginsManager.php
+++ b/core/PluginsManager.php
@@ -131,27 +131,29 @@ class Piwik_PluginsManager
*/
public function deactivatePlugin($pluginName)
{
+ $configWriter = Piwik_Config_Writer::getInstance();
+
$plugins = $this->pluginsToLoad;
- $key = array_search($pluginName,$plugins);
+ $key = array_search($pluginName, $plugins);
if($key !== false)
{
unset($plugins[$key]);
- Zend_Registry::get('config')->Plugins = $plugins;
+ $configWriter->Plugins['Plugins'] = $plugins;
}
- $pluginsTracker = Zend_Registry::get('config')->Plugins_Tracker->Plugins_Tracker;
+ $pluginsTracker = Piwik_Config::getInstance()->Plugins_Tracker['Plugins_Tracker'];
if(!is_null($pluginsTracker))
{
- $pluginsTracker = $pluginsTracker->toArray();
- $key = array_search($pluginName,$pluginsTracker);
+ $key = array_search($pluginName, $pluginsTracker);
if($key !== false)
{
unset($pluginsTracker[$key]);
- Zend_Registry::get('config')->Plugins_Tracker = array('Plugins_Tracker' => $pluginsTracker);
+ $configWriter->Plugins_Tracker['Plugins_Tracker'] = $pluginsTracker;
}
}
// Delete merged js/css files to force regenerations to exclude the deactivated plugin
+ Piwik_Config::getInstance()->clear();
Piwik::deleteAllCacheOnUpdate();
}
@@ -177,14 +179,14 @@ class Piwik_PluginsManager
*/
public function activatePlugin($pluginName)
{
- $plugins = Zend_Registry::get('config')->Plugins->Plugins->toArray();
- if(in_array($pluginName,$plugins))
+ $plugins = Piwik_Config::getInstance()->Plugins['Plugins'];
+ if(in_array($pluginName, $plugins))
{
throw new Exception("Plugin '$pluginName' already activated.");
}
$existingPlugins = $this->readPluginsDirectory();
- if( array_search($pluginName,$existingPlugins) === false)
+ if( array_search($pluginName, $existingPlugins) === false)
{
throw new Exception("Unable to find the plugin '$pluginName'.");
}
@@ -197,7 +199,8 @@ class Piwik_PluginsManager
$plugins[] = $pluginName;
// the config file will automatically be saved with the new plugin
- Zend_Registry::get('config')->Plugins = $plugins;
+ $configWriter = Piwik_Config_Writer::getInstance();
+ $configWriter->Plugins['Plugins'] = $plugins;
// Delete merged js/css files to force regenerations to include the activated plugin
Piwik::deleteAllCacheOnUpdate();
@@ -527,11 +530,7 @@ class Piwik_PluginsManager
*/
public function getInstalledPluginsName()
{
- if(!class_exists('Zend_Registry', false))
- {
- throw new Exception("Not possible to list installed plugins (case Tracker module)");
- }
- $pluginNames = Zend_Registry::get('config')->PluginsInstalled->PluginsInstalled->toArray();
+ $pluginNames = Piwik_Config::getInstance()->PluginsInstalled['PluginsInstalled'];
return $pluginNames;
}
@@ -550,7 +549,8 @@ class Piwik_PluginsManager
{
$this->installPlugin($plugin);
$pluginsInstalled[] = $pluginName;
- Zend_Registry::get('config')->PluginsInstalled = array('PluginsInstalled' => $pluginsInstalled);
+ $configWriter = Piwik_Config_Writer::getInstance();
+ $configWriter->PluginsInstalled['PluginsInstalled'] = $pluginsInstalled;
}
$information = $plugin->getInformation();
@@ -559,19 +559,16 @@ class Piwik_PluginsManager
if(isset($information['TrackerPlugin'])
&& $information['TrackerPlugin'] === true)
{
- $pluginsTracker = Zend_Registry::get('config')->Plugins_Tracker->Plugins_Tracker;
+ $pluginsTracker = Piwik_Config::getInstance()->Plugins_Tracker['Plugins_Tracker'];
if(is_null($pluginsTracker))
{
$pluginsTracker = array();
}
- else
- {
- $pluginsTracker = $pluginsTracker->toArray();
- }
if(!in_array($pluginName, $pluginsTracker))
{
$pluginsTracker[] = $pluginName;
- Zend_Registry::get('config')->Plugins_Tracker = array('Plugins_Tracker' => $pluginsTracker);
+ $configWriter = Piwik_Config_Writer::getInstance();
+ $configWriter->Plugins_Tracker['Plugins_Tracker'] = $pluginsTracker;
}
}
}
diff --git a/core/Session.php b/core/Session.php
index 2e60aa09ec..c0d5a2494a 100644
--- a/core/Session.php
+++ b/core/Session.php
@@ -27,9 +27,9 @@ class Piwik_Session extends Zend_Session
*/
public static function isFileBasedSessions()
{
- $config = Zend_Registry::get('config');
- return !isset($config->General->session_save_handler)
- || $config->General->session_save_handler === 'files';
+ $config = Piwik_Config::getInstance();
+ return !isset($config->General['session_save_handler'])
+ || $config->General['session_save_handler'] === 'files';
}
/**
@@ -71,7 +71,7 @@ class Piwik_Session extends Zend_Session
@ini_set('session.referer_check', '');
$currentSaveHandler = ini_get('session.save_handler');
- $config = Zend_Registry::get('config');
+ $config = Piwik_Config::getInstance();
if (self::isFileBasedSessions())
{
@@ -85,7 +85,7 @@ class Piwik_Session extends Zend_Session
@ini_set('session.save_handler', 'files');
@ini_set('session.save_path', $sessionPath);
}
- else if ($config->General->session_save_handler === 'dbtable'
+ else if ($config->General['session_save_handler'] === 'dbtable'
|| in_array($currentSaveHandler, array('user', 'mm')))
{
// We consider these to be misconfigurations, in that:
diff --git a/core/Smarty.php b/core/Smarty.php
index e60f8ced9f..a64f65686b 100644
--- a/core/Smarty.php
+++ b/core/Smarty.php
@@ -37,26 +37,26 @@ class Piwik_Smarty extends Smarty
if(count($smConf) == 0)
{
- $smConf = Zend_Registry::get('config')->smarty;
+ $smConf = Piwik_Config::getInstance()->smarty;
}
foreach($smConf as $key => $value)
{
$this->$key = $value;
}
- $this->template_dir = $smConf->template_dir->toArray();
+ $this->template_dir = $smConf['template_dir'];
array_walk($this->template_dir, array("Piwik_Smarty","addPiwikPath"), PIWIK_INCLUDE_PATH);
- $this->plugins_dir = $smConf->plugins_dir->toArray();
+ $this->plugins_dir = $smConf['plugins_dir'];
array_walk($this->plugins_dir, array("Piwik_Smarty","addPiwikPath"), PIWIK_INCLUDE_PATH);
- $this->compile_dir = $smConf->compile_dir;
+ $this->compile_dir = $smConf['compile_dir'];
Piwik_Smarty::addPiwikPath($this->compile_dir, null, PIWIK_USER_PATH);
- $this->cache_dir = $smConf->cache_dir;
+ $this->cache_dir = $smConf['cache_dir'];
Piwik_Smarty::addPiwikPath($this->cache_dir, null, PIWIK_USER_PATH);
- $error_reporting = $smConf->error_reporting;
+ $error_reporting = $smConf['error_reporting'];
if($error_reporting != (string)(int)$error_reporting)
{
$error_reporting = self::bitwise_eval($error_reporting);
@@ -67,7 +67,7 @@ class Piwik_Smarty extends Smarty
{
$this->load_filter('output', 'cachebuster');
- $use_ajax_cdn = Zend_Registry::get('config')->General->use_ajax_cdn;
+ $use_ajax_cdn = Piwik_Config::getInstance()->General['use_ajax_cdn'];
if($use_ajax_cdn)
{
$this->load_filter('output', 'ajaxcdn');
diff --git a/core/SmartyPlugins/outputfilter.ajaxcdn.php b/core/SmartyPlugins/outputfilter.ajaxcdn.php
index 97d562f4b9..cf7fb535fa 100644
--- a/core/SmartyPlugins/outputfilter.ajaxcdn.php
+++ b/core/SmartyPlugins/outputfilter.ajaxcdn.php
@@ -27,9 +27,9 @@
*/
function smarty_outputfilter_ajaxcdn($source, &$smarty)
{
- $jquery_version = Zend_Registry::get('config')->General->jquery_version;
- $jqueryui_version = Zend_Registry::get('config')->General->jqueryui_version;
- $swfobject_version = Zend_Registry::get('config')->General->swfobject_version;
+ $jquery_version = Piwik_Config::getInstance()->General['jquery_version'];
+ $jqueryui_version = Piwik_Config::getInstance()->General['jqueryui_version'];
+ $swfobject_version = Piwik_Config::getInstance()->General['swfobject_version'];
$pattern = array(
'~<link rel="stylesheet" type="text/css" href="libs/jquery/themes/([^"]*)" />~',
diff --git a/core/TablePartitioning.php b/core/TablePartitioning.php
index 5473d20a49..84e7761bbf 100644
--- a/core/TablePartitioning.php
+++ b/core/TablePartitioning.php
@@ -72,8 +72,8 @@ abstract class Piwik_TablePartitioning
$db = Zend_Registry::get('db');
$sql = Piwik::getTableCreateSql($this->tableName);
- $config = Zend_Registry::get('config');
- $prefixTables = $config->database->tables_prefix;
+ $config = Piwik_Config::getInstance();
+ $prefixTables = $config->database['tables_prefix'];
$sql = str_replace( $prefixTables . $this->tableName, $this->generatedTableName, $sql);
try {
$db->query( $sql );
@@ -109,8 +109,8 @@ class Piwik_TablePartitioning_Monthly extends Piwik_TablePartitioning
}
protected function generateTableName()
{
- $config = Zend_Registry::get('config');
- return $config->database->tables_prefix . $this->tableName . "_" . date("Y_m", $this->timestamp);
+ $config = Piwik_Config::getInstance();
+ return $config->database['tables_prefix'] . $this->tableName . "_" . date("Y_m", $this->timestamp);
}
}
@@ -128,7 +128,7 @@ class Piwik_TablePartitioning_Daily extends Piwik_TablePartitioning
}
protected function generateTableName()
{
- $config = Zend_Registry::get('config');
- return $config->database->tables_prefix . $this->tableName . "_" . date("Y_m_d", $this->timestamp);
+ $config = Piwik_Config::getInstance();
+ return $config->database['tables_prefix'] . $this->tableName . "_" . date("Y_m_d", $this->timestamp);
}
}
diff --git a/core/Tracker.php b/core/Tracker.php
index 1b96dd86fe..c78cc34d8e 100644
--- a/core/Tracker.php
+++ b/core/Tracker.php
@@ -215,7 +215,7 @@ class Piwik_Tracker
public static function connectPiwikTrackerDb()
{
$db = null;
- $configDb = Piwik_Tracker_Config::getInstance()->database;
+ $configDb = Piwik_Config::getInstance()->database;
if(!isset($configDb['port']))
{
@@ -329,7 +329,7 @@ class Piwik_Tracker
}
try{
- $pluginsTracker = Piwik_Tracker_Config::getInstance()->Plugins_Tracker;
+ $pluginsTracker = Piwik_Config::getInstance()->Plugins_Tracker;
if(is_array($pluginsTracker)
&& count($pluginsTracker) != 0)
{
@@ -359,7 +359,7 @@ class Piwik_Tracker
protected function handleDisabledTracker()
{
- $saveStats = Piwik_Tracker_Config::getInstance()->Tracker['record_statistics'];
+ $saveStats = Piwik_Config::getInstance()->Tracker['record_statistics'];
if($saveStats == 0)
{
$this->setState(self::STATE_LOGGING_DISABLE);
@@ -372,8 +372,8 @@ class Piwik_Tracker
if( $tokenAuth )
{
- $superUserLogin = Piwik_Tracker_Config::getInstance()->superuser['login'];
- $superUserPassword = Piwik_Tracker_Config::getInstance()->superuser['password'];
+ $superUserLogin = Piwik_Config::getInstance()->superuser['login'];
+ $superUserPassword = Piwik_Config::getInstance()->superuser['password'];
if( md5($superUserLogin . $superUserPassword ) == $tokenAuth )
{
$this->authenticated = true;
@@ -404,7 +404,7 @@ class Piwik_Tracker
*/
protected function handleTrackingApi()
{
- $shouldAuthenticate = Piwik_Tracker_Config::getInstance()->Tracker['tracking_requests_require_authentication'];
+ $shouldAuthenticate = Piwik_Config::getInstance()->Tracker['tracking_requests_require_authentication'];
if($shouldAuthenticate)
{
if(!$this->authenticateSuperUserOrAdmin())
diff --git a/core/Tracker/Action.php b/core/Tracker/Action.php
index 7b5b7d8e99..c25bb4d6d6 100644
--- a/core/Tracker/Action.php
+++ b/core/Tracker/Action.php
@@ -478,9 +478,9 @@ class Piwik_Tracker_Action implements Piwik_Tracker_Action_Interface
$url = Piwik_Common::getRequestVar( 'url', '', 'string', $this->request);
// get the delimiter, by default '/'; BC, we read the old action_category_delimiter first (see #1067)
- $actionCategoryDelimiter = isset(Piwik_Tracker_Config::getInstance()->General['action_category_delimiter'])
- ? Piwik_Tracker_Config::getInstance()->General['action_category_delimiter']
- : Piwik_Tracker_Config::getInstance()->General['action_url_category_delimiter'];
+ $actionCategoryDelimiter = isset(Piwik_Config::getInstance()->General['action_category_delimiter'])
+ ? Piwik_Config::getInstance()->General['action_category_delimiter']
+ : Piwik_Config::getInstance()->General['action_url_category_delimiter'];
// create an array of the categories delimited by the delimiter
$split = explode($actionCategoryDelimiter, $actionName);
@@ -520,7 +520,7 @@ class Piwik_Tracker_Action implements Piwik_Tracker_Action_Interface
$string = trim($string);
$string = str_replace(array("\n", "\r", "\0"), '', $string);
- $limit = Piwik_Tracker_Config::getInstance()->Tracker['page_maximum_length'];
+ $limit = Piwik_Config::getInstance()->Tracker['page_maximum_length'];
return substr($string, 0, $limit);
}
}
diff --git a/core/Tracker/Config.php b/core/Tracker/Config.php
index e66ec9fae7..35117961d8 100644
--- a/core/Tracker/Config.php
+++ b/core/Tracker/Config.php
@@ -1,166 +1,34 @@
<?php
/**
* Piwik - Open source web analytics
- *
+ *
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
* @version $Id$
- *
+ *
* @category Piwik
* @package Piwik
*/
/**
- * Simple class to access the configuration file
- *
- * This is essentially a simple version of Zend_Config that we wrote
- * because of performance reasons.
- * The Tracker module can't afford a dependency with the Zend_Framework.
- *
- * It's using the php.net/parse_ini_file function to parse the configuration files.
- * It can be used to access both user config.ini.php and piwik global.ini.php config file.
- *
+ * Backward compatibility layer
+ *
+ * @todo remove this in 2.0
+ * @since 1.7
+ * @deprecated 1.7
+ *
* @package Piwik
- * @subpackage Piwik_Tracker
+ * @subpackage Piwik_Tracker_Config
*/
class Piwik_Tracker_Config
{
- static private $instance = null;
-
- /*
- * For Unit tests, the locally overwritten config/config.ini.php should not interfere with Integration tests.
- * We therefore overwrite the config files with the default values from global.ini.php when running these tests
- * @see setTestEnvironment()
- */
- static public $toRestoreFromGlobalConfig = array('Debug', 'General', 'Tracker');
-
/**
- * Returns singleton
+ * Returns the singleton Piwik_Config
*
- * @return Piwik_Tracker_Config
+ * @return Piwik_Config
*/
static public function getInstance()
{
- if (self::$instance == null)
- {
- self::$instance = new self;
- }
- return self::$instance;
- }
-
- /**
- * Re-inits the object
- * Useful after the instance was messed up with (on purpose) in tests
- */
- public function clear()
- {
- $this->configGlobal = false;
- $this->configUser = false;
- $this->initialized = false;
- }
-
- /**
- * Contains configuration files values
- *
- * @var array
- */
- protected $initialized = false;
- protected $configGlobal = false;
- protected $configUser = false;
-
- public function init($pathIniFileUser = null, $pathIniFileGlobal = null)
- {
- if(is_null($pathIniFileGlobal))
- {
- $pathIniFileGlobal = PIWIK_USER_PATH . '/config/global.ini.php';
- }
- $this->configGlobal = _parse_ini_file($pathIniFileGlobal, true);
-
- if(is_null($pathIniFileUser))
- {
- $pathIniFileUser = PIWIK_USER_PATH . '/config/config.ini.php';
- }
- $this->configUser = _parse_ini_file($pathIniFileUser, true);
- if($this->configUser)
- {
- foreach($this->configUser as $section => &$sectionValues)
- {
- foreach($sectionValues as $name => &$value)
- {
- if(is_array($value))
- {
- $value = array_map("html_entity_decode", $value);
- }
- else
- {
- $value = html_entity_decode($value);
- }
- }
- }
- }
- $this->initialized = true;
- }
-
- /**
- * Magic get methods catching calls to $config->var_name
- * Returns the value if found in the
- *
- * @param string $name
- * @return mixed The value requested, usually a string
- * @throws exception if the value requested not found in both files
- */
- public function __get( $name )
- {
- if(!$this->initialized)
- {
- $this->init();
- }
-
- $section = array();
- if(isset($this->configGlobal[$name]))
- {
- $section = array_merge($section, $this->configGlobal[$name]);
- }
- if(isset($this->configUser[$name]))
- {
- $section = array_merge($section, $this->configUser[$name]);
- }
- return count($section) ? $section : null;
- }
-
- /**
- * If called, we use the database_tests credentials
- * and test configuration overrides
- */
- public function setTestEnvironment()
- {
- if(!$this->initialized)
- {
- $this->init();
- }
- foreach(self::$toRestoreFromGlobalConfig as $section)
- {
- if(isset($this->configGlobal[$section]))
- {
- $this->configUser[$section] = $this->configGlobal[$section];
- }
- }
- $this->database = $this->database_tests;
- $this->PluginsInstalled = array();
- }
- /**
- * Should only be used in tests/
- */
- public function setTestValue($section, $name, $value = false)
- {
- // Case setting the whole section at once
- if($value === false)
- {
- $this->configUser[$section] = $name;
- }
- else
- {
- $this->configUser[$section][$name] = $value;
- }
+ return Piwik_Config::getInstance();
}
}
diff --git a/core/Tracker/GoalManager.php b/core/Tracker/GoalManager.php
index 59ff328ae5..eaf14e0905 100644
--- a/core/Tracker/GoalManager.php
+++ b/core/Tracker/GoalManager.php
@@ -231,7 +231,7 @@ class Piwik_Tracker_GoalManager
? $visitorInformation['location_country']
: Piwik_Common::getCountry(
Piwik_Common::getBrowserLanguage(),
- $enableLanguageToCountryGuess = Piwik_Tracker_Config::getInstance()->Tracker['enable_language_to_country_guess'],
+ $enableLanguageToCountryGuess = Piwik_Config::getInstance()->Tracker['enable_language_to_country_guess'],
$visitorInformation['location_ip']
);
diff --git a/core/Tracker/IgnoreCookie.php b/core/Tracker/IgnoreCookie.php
index e85e66d82c..e80458a49a 100644
--- a/core/Tracker/IgnoreCookie.php
+++ b/core/Tracker/IgnoreCookie.php
@@ -25,20 +25,8 @@ class Piwik_Tracker_IgnoreCookie
*/
static public function getTrackingCookie()
{
- if(!empty($GLOBALS['PIWIK_TRACKER_MODE']))
- {
- $cookie_name = @Piwik_Tracker_Config::getInstance()->Tracker['cookie_name'];
- $cookie_path = @Piwik_Tracker_Config::getInstance()->Tracker['cookie_path'];
- }
- else
- {
- $config = Zend_Registry::get('config');
- if($config !== false)
- {
- $cookie_name = @$config->Tracker->cookie_name;
- $cookie_path = @$config->Tracker->cookie_path;
- }
- }
+ $cookie_name = @Piwik_Config::getInstance()->Tracker['cookie_name'];
+ $cookie_path = @Piwik_Config::getInstance()->Tracker['cookie_path'];
return new Piwik_Cookie($cookie_name, null, $cookie_path);
}
@@ -50,20 +38,8 @@ class Piwik_Tracker_IgnoreCookie
*/
static public function getIgnoreCookie()
{
- if(!empty($GLOBALS['PIWIK_TRACKER_MODE']))
- {
- $cookie_name = @Piwik_Tracker_Config::getInstance()->Tracker['ignore_visits_cookie_name'];
- $cookie_path = @Piwik_Tracker_Config::getInstance()->Tracker['cookie_path'];
- }
- else
- {
- $config = Zend_Registry::get('config');
- if($config !== false)
- {
- $cookie_name = @$config->Tracker->ignore_visits_cookie_name;
- $cookie_path = @$config->Tracker->cookie_path;
- }
- }
+ $cookie_name = @Piwik_Config::getInstance()->Tracker['ignore_visits_cookie_name'];
+ $cookie_path = @Piwik_Config::getInstance()->Tracker['cookie_path'];
return new Piwik_Cookie($cookie_name, null, $cookie_path);
}
diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php
index 6fc12b8198..938937c75d 100644
--- a/core/Tracker/Visit.php
+++ b/core/Tracker/Visit.php
@@ -376,7 +376,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
// Will be updated in cookie
$timeSpentRefererAction = $this->getCurrentTimestamp() - $this->visitorInfo['visit_last_action_time'];
- if($timeSpentRefererAction > Piwik_Tracker_Config::getInstance()->Tracker['visit_standard_length'])
+ if($timeSpentRefererAction > Piwik_Config::getInstance()->Tracker['visit_standard_length'])
{
$timeSpentRefererAction = 0;
}
@@ -458,7 +458,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
$idcookie = $this->getVisitorIdcookie();
- $defaultTimeOnePageVisit = Piwik_Tracker_Config::getInstance()->Tracker['default_time_one_page_visit'];
+ $defaultTimeOnePageVisit = Piwik_Config::getInstance()->Tracker['default_time_one_page_visit'];
// Days since first visit
$cookieFirstVisitTimestamp = Piwik_Common::getRequestVar('_idts', 0, 'int', $this->request);
@@ -498,7 +498,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
// User settings
$userInfo = $this->getUserSettingsInformation();
$country = Piwik_Common::getCountry($userInfo['location_browser_lang'],
- $enableLanguageToCountryGuess = Piwik_Tracker_Config::getInstance()->Tracker['enable_language_to_country_guess'],
+ $enableLanguageToCountryGuess = Piwik_Config::getInstance()->Tracker['enable_language_to_country_guess'],
$this->getVisitorIp());
// Referrer data
@@ -797,7 +797,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
*/
protected function getCookieName()
{
- return Piwik_Tracker_Config::getInstance()->Tracker['cookie_name'];
+ return Piwik_Config::getInstance()->Tracker['cookie_name'];
}
/**
@@ -807,7 +807,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
*/
protected function getCookieExpire()
{
- return $this->getCurrentTimestamp() + Piwik_Tracker_Config::getInstance()->Tracker['cookie_expire'];
+ return $this->getCurrentTimestamp() + Piwik_Config::getInstance()->Tracker['cookie_expire'];
}
/**
@@ -817,12 +817,12 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
*/
protected function getCookiePath()
{
- return Piwik_Tracker_Config::getInstance()->Tracker['cookie_path'];
+ return Piwik_Config::getInstance()->Tracker['cookie_path'];
}
protected function shouldUseThirdPartyCookie()
{
- return (bool)Piwik_Tracker_Config::getInstance()->Tracker['use_third_party_id_cookie'];
+ return (bool)Piwik_Config::getInstance()->Tracker['use_third_party_id_cookie'];
}
/**
@@ -944,11 +944,11 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
$bindSql = array();
- $timeLookBack = date('Y-m-d H:i:s', $this->getCurrentTimestamp() - Piwik_Tracker_Config::getInstance()->Tracker['visit_standard_length']);
+ $timeLookBack = date('Y-m-d H:i:s', $this->getCurrentTimestamp() - Piwik_Config::getInstance()->Tracker['visit_standard_length']);
// This setting would be enabled for Intranet websites, to ensure that visitors using all the same computer config, same IP
// are not counted as 1 visitor. In this case, we want to enforce and trust the visitor ID from the cookie.
- $trustCookiesOnly = Piwik_Tracker_Config::getInstance()->Tracker['trust_visitors_cookies'];
+ $trustCookiesOnly = Piwik_Config::getInstance()->Tracker['trust_visitors_cookies'];
$shouldMatchOneFieldOnly = ($matchVisitorId && $trustCookiesOnly) || !$matchVisitorId;
@@ -1029,7 +1029,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
$visitRow = Piwik_Tracker::getDatabase()->fetch($sql, $bindSql);
// var_dump($sql);var_dump($bindSql);var_dump($visitRow);
- if( !Piwik_Tracker_Config::getInstance()->Debug['tracker_always_new_visitor']
+ if( !Piwik_Config::getInstance()->Debug['tracker_always_new_visitor']
&& $visitRow
&& count($visitRow) > 0)
{
@@ -1234,7 +1234,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface
{
return isset($this->visitorInfo['visit_last_action_time'])
&& ($this->visitorInfo['visit_last_action_time']
- > ($this->getCurrentTimestamp() - Piwik_Tracker_Config::getInstance()->Tracker['visit_standard_length']));
+ > ($this->getCurrentTimestamp() - Piwik_Config::getInstance()->Tracker['visit_standard_length']));
}
/**
diff --git a/core/Translate.php b/core/Translate.php
index cd5db35ad8..f3ded9695e 100644
--- a/core/Translate.php
+++ b/core/Translate.php
@@ -126,7 +126,7 @@ class Piwik_Translate
public function getLanguageDefault()
{
- return Zend_Registry::get('config')->General->default_language;
+ return Piwik_Config::getInstance()->General['default_language'];
}
/**
diff --git a/core/UpdateCheck.php b/core/UpdateCheck.php
index 54d7a6c690..6cff6cf202 100644
--- a/core/UpdateCheck.php
+++ b/core/UpdateCheck.php
@@ -44,7 +44,7 @@ class Piwik_UpdateCheck
'timezone' => Piwik_SitesManager_API::getInstance()->getDefaultTimezone(),
);
- $url = Zend_Registry::get('config')->General->api_service_url
+ $url = Piwik_Config::getInstance()->General['api_service_url']
. '/1.0/getLatestVersion/'
. '?' . http_build_query($parameters, '', '&');
$timeout = self::SOCKET_TIMEOUT;
diff --git a/core/Updates/0.5.4.php b/core/Updates/0.5.4.php
index e2650b3ea5..d00f4f1d90 100644
--- a/core/Updates/0.5.4.php
+++ b/core/Updates/0.5.4.php
@@ -25,19 +25,16 @@ class Piwik_Updates_0_5_4 extends Piwik_Updates
static function update()
{
- $config = Zend_Registry::get('config');
+ $config = Piwik_Config_Writer::getInstance();
$salt = Piwik_Common::generateUniqId();
- if(!isset($config->superuser->salt))
+ if(!isset($config->superuser['salt']))
{
try {
- if(is_writable( Piwik_Config::getDefaultUserConfigPath() ))
+ if(is_writable( Piwik_Config_Writer::getLocalConfigPath() ))
{
- $superuser_info = $config->superuser->toArray();
- $superuser_info['salt'] = $salt;
- $config->superuser = $superuser_info;
-
+ $config->setConfigOption('superuser', 'salt', $salt);
$config->__destruct();
- Piwik::createConfigObject();
+ Piwik_Config::getInstance()->clear();
}
else
{
@@ -48,18 +45,17 @@ class Piwik_Updates_0_5_4 extends Piwik_Updates
}
}
- $config = Zend_Registry::get('config');
- $plugins = $config->Plugins->toArray();
+ $config = Piwik_Config_Writer::getInstance();
+ $plugins = $config->Plugins;
if(!in_array('MultiSites', $plugins))
{
try {
- if(is_writable( Piwik_Config::getDefaultUserConfigPath() ))
+ if(is_writable( Piwik_Config_Writer::getLocalConfigPath() ))
{
$plugins[] = 'MultiSites';
- $config->Plugins = $plugins;
-
+ $config->setConfigSection('Plugins', $plugins);
$config->__destruct();
- Piwik::createConfigObject();
+ Piwik_Config::getInstance()->clear();
}
else
{
diff --git a/core/Updates/0.6.3.php b/core/Updates/0.6.3.php
index 093dc7c76b..2610365602 100644
--- a/core/Updates/0.6.3.php
+++ b/core/Updates/0.6.3.php
@@ -27,18 +27,16 @@ class Piwik_Updates_0_6_3 extends Piwik_Updates
static function update()
{
- $config = Zend_Registry::get('config');
- $dbInfos = $config->database->toArray();
+ $config = Piwik_Config_Writer::getInstance();
+ $dbInfos = $config->database;
if(!isset($dbInfos['schema']))
{
try {
- if(is_writable( Piwik_Config::getDefaultUserConfigPath() ))
+ if(is_writable( Piwik_Config_Writer::getLocalConfigPath() ))
{
- $dbInfos['schema'] = 'Myisam';
- $config->database = $dbInfos;
-
+ $config->setConfigOption('database', 'schema', 'Myisam');
$config->__destruct();
- Piwik::createConfigObject();
+ Piwik_Config::getInstance()->clear();
}
else
{
diff --git a/core/Updates/1.1.php b/core/Updates/1.1.php
index 1d0eb04be8..a2cc94ec12 100644
--- a/core/Updates/1.1.php
+++ b/core/Updates/1.1.php
@@ -17,9 +17,9 @@ class Piwik_Updates_1_1 extends Piwik_Updates
{
static function update($schema = 'Myisam')
{
- $config = Zend_Registry::get('config');
+ $config = Piwik_Config::getInstance();
- $rootLogin = $config->superuser->login;
+ $rootLogin = $config->superuser['login'];
try {
// throws an exception if invalid
Piwik::checkValidLoginString($rootLogin);
diff --git a/core/Updates/1.2.3.php b/core/Updates/1.2.3.php
index 234a29a72a..6282030e04 100644
--- a/core/Updates/1.2.3.php
+++ b/core/Updates/1.2.3.php
@@ -19,7 +19,7 @@ class Piwik_Updates_1_2_3 extends Piwik_Updates
{
return array(
// LOAD DATA INFILE uses the database's charset
- 'ALTER DATABASE `'. Zend_Registry::get('config')->database->dbname .'` DEFAULT CHARACTER SET utf8' => false,
+ 'ALTER DATABASE `'. Piwik_Config::getInstance()->database['dbname'] .'` DEFAULT CHARACTER SET utf8' => false,
// Various performance improvements schema updates
'ALTER TABLE `'. Piwik_Common::prefixTable('log_visit') .'`
diff --git a/core/Url.php b/core/Url.php
index f906588803..e6013a8b77 100644
--- a/core/Url.php
+++ b/core/Url.php
@@ -148,13 +148,7 @@ class Piwik_Url
*/
static public function getCurrentScheme()
{
- try {
- $config = Zend_Registry::get('config');
- } catch(Exception $e) {
- $config = false;
- }
- $assume_secure_protocol = $config !== false && $config->General->assume_secure_protocol;
-
+ $assume_secure_protocol = @Piwik_Config::getInstance()->General['assume_secure_protocol'];
if($assume_secure_protocol
|| (isset($_SERVER['HTTPS'])
&& ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] === true))
@@ -174,16 +168,7 @@ class Piwik_Url
*/
static public function getCurrentHost($default = 'unknown')
{
- $hostHeaders = null;
- try {
- $config = Zend_Registry::get('config');
- } catch(Exception $e) {
- $config = false;
- }
- if($config !== false && $config->General->proxy_host_headers)
- {
- $hostHeaders = $config->General->proxy_host_headers->toArray();
- }
+ $hostHeaders = @Piwik_Config::getInstance()->General['proxy_host_headers'];
if(!is_array($hostHeaders))
{
$hostHeaders = array();
diff --git a/core/View.php b/core/View.php
index c0442c4090..f7508a5cca 100644
--- a/core/View.php
+++ b/core/View.php
@@ -97,7 +97,7 @@ class Piwik_View implements Piwik_View_Interface
$this->latest_version_available = Piwik_UpdateCheck::isNewestVersionAvailable();
$this->disableLink = Piwik_Common::getRequestVar('disableLink', 0, 'int');
$this->isWidget = Piwik_Common::getRequestVar('widget', 0, 'int');
- if(Zend_Registry::get('config')->General->autocomplete_min_sites <= count($sites))
+ if(Piwik_Config::getInstance()->General['autocomplete_min_sites'] <= count($sites))
{
$this->show_autocompleter = true;
}
diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php
index ce2c68f294..65d0293fef 100644
--- a/core/ViewDataTable.php
+++ b/core/ViewDataTable.php
@@ -304,7 +304,7 @@ abstract class Piwik_ViewDataTable
$this->viewProperties['show_footer_icons'] = ($this->idSubtable == false);
$this->viewProperties['apiMethodToRequestDataTable'] = $this->apiMethodToRequestDataTable;
$this->viewProperties['uniqueId'] = $this->getUniqueIdViewDataTable();
- $this->viewProperties['exportLimit'] = Zend_Registry::get('config')->General->API_datatable_default_limit;
+ $this->viewProperties['exportLimit'] = Piwik_Config::getInstance()->General['API_datatable_default_limit'];
$standardColumnNameToTranslation = array_merge(
Piwik_API_API::getInstance()->getDefaultMetrics(),
diff --git a/core/ViewDataTable/HtmlTable.php b/core/ViewDataTable/HtmlTable.php
index 2ae78bedf2..1277ba29c5 100644
--- a/core/ViewDataTable/HtmlTable.php
+++ b/core/ViewDataTable/HtmlTable.php
@@ -50,7 +50,7 @@ class Piwik_ViewDataTable_HtmlTable extends Piwik_ViewDataTable
$this->dataTableTemplate = 'CoreHome/templates/datatable.tpl';
$this->variablesDefault['enable_sort'] = '1';
$this->setSortedColumn('nb_visits', 'desc');
- $this->setLimit(Zend_Registry::get('config')->General->datatable_default_limit);
+ $this->setLimit(Piwik_Config::getInstance()->General['datatable_default_limit']);
$this->handleLowPopulation();
}
diff --git a/misc/cron/archive.php b/misc/cron/archive.php
index ccd8c079c2..f009d89632 100644
--- a/misc/cron/archive.php
+++ b/misc/cron/archive.php
@@ -555,9 +555,9 @@ class Archiving
private function initLog()
{
- Zend_Registry::get('config')->disableSavingConfigurationFileUpdates();
- Zend_Registry::get('config')->log->log_only_when_debug_parameter = 0;
- Zend_Registry::get('config')->log->logger_message = array("logger_message" => "screen");
+ $config = Piwik_Config::getInstance();
+ $config->log['log_only_when_debug_parameter'] = 0;
+ $config->log['logger_message'] = array("logger_message" => "screen");
Piwik::createLogObject();
if(!function_exists("curl_multi_init")) {
@@ -729,8 +729,8 @@ class Archiving
protected function initTokenAuth()
{
- $login = Zend_Registry::get('config')->superuser->login;
- $md5Password = Zend_Registry::get('config')->superuser->password;
+ $login = Piwik_Config::getInstance()->superuser['login'];
+ $md5Password = Piwik_Config::getInstance()->superuser['password'];
$this->token_auth = md5( $login . $md5Password ) ;
$this->login = $login;
}
@@ -760,7 +760,7 @@ class Archiving
$piwikUrl .= '/';
}
}
- if(Zend_Registry::get('config')->General->force_ssl == 1)
+ if(Piwik_Config::getInstance()->General['force_ssl'] == 1)
{
$piwikUrl = str_replace('http://', 'https://', $piwikUrl);
}
diff --git a/misc/test_generateLotsVisitsWebsites.php b/misc/test_generateLotsVisitsWebsites.php
index 1289a4f779..808eee40a2 100644
--- a/misc/test_generateLotsVisitsWebsites.php
+++ b/misc/test_generateLotsVisitsWebsites.php
@@ -20,9 +20,9 @@ class Piwik_StressTests_CopyLogs
{
function init()
{
- Zend_Registry::get('config')->disableSavingConfigurationFileUpdates();
- Zend_Registry::get('config')->log->log_only_when_debug_parameter = 0;
- Zend_Registry::get('config')->log->logger_message = array("logger_message" => "screen");
+ $config = Piwik_Config::getInstance();
+ $config->log['log_only_when_debug_parameter'] = 0;
+ $config->log['logger_message'] = array("logger_message" => "screen");
Piwik::createLogObject();
}
diff --git a/piwik.php b/piwik.php
index eb6a85f14d..c80f3517ea 100644
--- a/piwik.php
+++ b/piwik.php
@@ -42,7 +42,7 @@ require_once PIWIK_INCLUDE_PATH .'/core/Plugin.php';
require_once PIWIK_INCLUDE_PATH .'/core/Common.php';
require_once PIWIK_INCLUDE_PATH .'/core/IP.php';
require_once PIWIK_INCLUDE_PATH .'/core/Tracker.php';
-require_once PIWIK_INCLUDE_PATH .'/core/Tracker/Config.php';
+require_once PIWIK_INCLUDE_PATH .'/core/Config.php';
require_once PIWIK_INCLUDE_PATH .'/core/Tracker/Db.php';
require_once PIWIK_INCLUDE_PATH .'/core/Tracker/IgnoreCookie.php';
require_once PIWIK_INCLUDE_PATH .'/core/Tracker/Visit.php';
@@ -68,12 +68,7 @@ if($GLOBALS['PIWIK_TRACKER_DEBUG'] === true)
set_exception_handler('Piwik_ExceptionHandler');
printDebug("Debug enabled - Input parameters: <br/>" . var_export($_GET, true));
Piwik_Tracker_Db::enableProfiling();
- // Config might have been created by proxy-piwik.php
- try {
- $config = Zend_Registry::get('config');
- } catch (Exception $e) {
- Piwik::createConfigObject();
- }
+ Piwik::createConfigObject();
Piwik::createLogObject();
}
diff --git a/plugins/API/API.php b/plugins/API/API.php
index 56f000a08c..620357102c 100644
--- a/plugins/API/API.php
+++ b/plugins/API/API.php
@@ -358,7 +358,7 @@ class Piwik_API_API
public function getLogoUrl($pathOnly=false)
{
$logo = 'themes/default/images/logo.png';
- if(Zend_Registry::get('config')->branding->use_custom_logo == 1
+ if(Piwik_Config::getInstance()->branding['use_custom_logo'] == 1
&& file_exists(Piwik_Common::getPathToPiwikRoot() .'/themes/logo.png'))
{
$logo = 'themes/logo.png';
@@ -378,7 +378,7 @@ class Piwik_API_API
public function getHeaderLogoUrl($pathOnly=false)
{
$logo = 'themes/default/images/logo-header.png';
- if(Zend_Registry::get('config')->branding->use_custom_logo == 1
+ if(Piwik_Config::getInstance()->branding['use_custom_logo'] == 1
&& file_exists(Piwik_Common::getPathToPiwikRoot() .'/themes/logo-header.png'))
{
$logo = 'themes/logo-header.png';
diff --git a/plugins/API/Controller.php b/plugins/API/Controller.php
index 06c9ec6563..163003fa65 100644
--- a/plugins/API/Controller.php
+++ b/plugins/API/Controller.php
@@ -21,7 +21,7 @@ class Piwik_API_Controller extends Piwik_Controller
// when calling the API through http, we limit the number of returned results
if(!isset($_GET['filter_limit']))
{
- $_GET['filter_limit'] = Zend_Registry::get('config')->General->API_datatable_default_limit;
+ $_GET['filter_limit'] = Piwik_Config::getInstance()->General['API_datatable_default_limit'];
}
$request = new Piwik_API_Request('token_auth='.Piwik_Common::getRequestVar('token_auth', 'anonymous', 'string'));
echo $request->process();
diff --git a/plugins/Actions/Actions.php b/plugins/Actions/Actions.php
index 08d3c942ad..865b28db5d 100644
--- a/plugins/Actions/Actions.php
+++ b/plugins/Actions/Actions.php
@@ -367,21 +367,21 @@ class Piwik_Actions extends Piwik_Plugin
public function __construct()
{
// for BC, we read the old style delimiter first (see #1067)
- $actionDelimiter = Zend_Registry::get('config')->General->action_category_delimiter;
+ $actionDelimiter = @Piwik_Config::getInstance()->General['action_category_delimiter'];
if(empty($actionDelimiter))
{
- self::$actionUrlCategoryDelimiter = Zend_Registry::get('config')->General->action_url_category_delimiter;
- self::$actionTitleCategoryDelimiter = Zend_Registry::get('config')->General->action_title_category_delimiter;
+ self::$actionUrlCategoryDelimiter = Piwik_Config::getInstance()->General['action_url_category_delimiter'];
+ self::$actionTitleCategoryDelimiter = Piwik_Config::getInstance()->General['action_title_category_delimiter'];
}
else
{
self::$actionUrlCategoryDelimiter = self::$actionTitleCategoryDelimiter = $actionDelimiter;
}
- self::$defaultActionName = Zend_Registry::get('config')->General->action_default_name;
+ self::$defaultActionName = Piwik_Config::getInstance()->General['action_default_name'];
$this->columnToSortByBeforeTruncation = Piwik_Archive::INDEX_NB_VISITS;
- $this->maximumRowsInDataTableLevelZero = Zend_Registry::get('config')->General->datatable_archiving_maximum_rows_actions;
- $this->maximumRowsInSubDataTable = Zend_Registry::get('config')->General->datatable_archiving_maximum_rows_subtable_actions;
+ $this->maximumRowsInDataTableLevelZero = Piwik_Config::getInstance()->General['datatable_archiving_maximum_rows_actions'];
+ $this->maximumRowsInSubDataTable = Piwik_Config::getInstance()->General['datatable_archiving_maximum_rows_subtable_actions'];
}
function archivePeriod( $notification )
diff --git a/plugins/Actions/tests/Actions.test.php b/plugins/Actions/tests/Actions.test.php
index 607676a157..8deefaadeb 100644
--- a/plugins/Actions/tests/Actions.test.php
+++ b/plugins/Actions/tests/Actions.test.php
@@ -6,7 +6,6 @@ if(!defined('PIWIK_CONFIG_TEST_INCLUDED'))
require_once 'Actions/Actions.php';
require_once 'Tracker/Action.php';
-require_once 'Tracker/Config.php';
class Test_Piwik_Actions extends UnitTestCase
{
@@ -15,14 +14,14 @@ class Test_Piwik_Actions extends UnitTestCase
{
$userFile = PIWIK_INCLUDE_PATH . '/tests/resources/plugins/Actions/Actions.config.ini.php';
Piwik::createConfigObject($userFile);
- Piwik_Translate::getInstance()->loadEnglishTranslation();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Translate::getInstance()->loadEnglishTranslation();
+ Piwik_Config::getInstance()->setTestEnvironment();
}
function tearDown()
{
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
}
function test_getActionExplodedNames()
diff --git a/plugins/AnonymizeIP/AnonymizeIP.php b/plugins/AnonymizeIP/AnonymizeIP.php
index 821c5efac2..8b0f7c8b9c 100644
--- a/plugins/AnonymizeIP/AnonymizeIP.php
+++ b/plugins/AnonymizeIP/AnonymizeIP.php
@@ -69,7 +69,6 @@ class Piwik_AnonymizeIP extends Piwik_Plugin
function setVisitorIpAddress($notification)
{
$ip =& $notification->getNotificationObject();
- $ip = self::applyIPMask($ip, Piwik_Tracker_Config::getInstance()->Tracker['ip_address_mask_length']);
+ $ip = self::applyIPMask($ip, Piwik_Config::getInstance()->Tracker['ip_address_mask_length']);
}
-
}
diff --git a/plugins/CoreAdminHome/Controller.php b/plugins/CoreAdminHome/Controller.php
index fb48bc8866..b2a354b4a8 100644
--- a/plugins/CoreAdminHome/Controller.php
+++ b/plugins/CoreAdminHome/Controller.php
@@ -16,9 +16,9 @@
*/
class Piwik_CoreAdminHome_Controller extends Piwik_Controller_Admin
{
- const LOGO_HEIGHT = 300;
- const LOGO_SMALL_HEIGHT = 100;
-
+ const LOGO_HEIGHT = 300;
+ const LOGO_SMALL_HEIGHT = 100;
+
public function index()
{
return $this->redirectToIndex('UsersManager', 'userSettings');
@@ -31,32 +31,32 @@ class Piwik_CoreAdminHome_Controller extends Piwik_Controller_Admin
if(Piwik::isUserIsSuperUser())
{
- $enableBrowserTriggerArchiving = Piwik_ArchiveProcessing::isBrowserTriggerArchivingEnabled();
- $todayArchiveTimeToLive = Piwik_ArchiveProcessing::getTodayArchiveTimeToLive();
- $showWarningCron = false;
- if(!$enableBrowserTriggerArchiving
- && $todayArchiveTimeToLive < 3600)
- {
- $showWarningCron = true;
- }
- $view->showWarningCron = $showWarningCron;
- $view->todayArchiveTimeToLive = $todayArchiveTimeToLive;
- $view->enableBrowserTriggerArchiving = $enableBrowserTriggerArchiving;
-
- if(!Zend_Registry::get('config')->isFileWritable())
- {
- $view->configFileNotWritable = true;
- }
- $view->mail = Zend_Registry::get('config')->mail->toArray();
+ $enableBrowserTriggerArchiving = Piwik_ArchiveProcessing::isBrowserTriggerArchivingEnabled();
+ $todayArchiveTimeToLive = Piwik_ArchiveProcessing::getTodayArchiveTimeToLive();
+ $showWarningCron = false;
+ if(!$enableBrowserTriggerArchiving
+ && $todayArchiveTimeToLive < 3600)
+ {
+ $showWarningCron = true;
+ }
+ $view->showWarningCron = $showWarningCron;
+ $view->todayArchiveTimeToLive = $todayArchiveTimeToLive;
+ $view->enableBrowserTriggerArchiving = $enableBrowserTriggerArchiving;
+
+ if(!Piwik_Config::getInstance()->isFileWritable())
+ {
+ $view->configFileNotWritable = true;
+ }
+ $view->mail = Piwik_Config::getInstance()->mail;
- $view->branding = Zend_Registry::get('config')->branding->toArray();
+ $view->branding = Piwik_Config::getInstance()->branding;
$directoryWritable = is_writable(PIWIK_DOCUMENT_ROOT.'/themes/');
$logoFilesWriteable = is_writeable(PIWIK_DOCUMENT_ROOT.'/themes/logo.png') && is_writeable(PIWIK_DOCUMENT_ROOT.'/themes/logo-header.png');
$view->logosWriteable = ($logoFilesWriteable || $directoryWritable) && ini_get('file_uploads') == 1;
}
- $view->language = Piwik_LanguagesManager::getLanguageCodeForCurrentUser();
+ $view->language = Piwik_LanguagesManager::getLanguageCodeForCurrentUser();
$this->setBasicVariablesView($view);
$view->topMenu = Piwik_GetTopMenu();
$view->menu = Piwik_GetAdminMenu();
@@ -68,28 +68,26 @@ class Piwik_CoreAdminHome_Controller extends Piwik_Controller_Admin
Piwik::checkUserIsSuperUser();
$response = new Piwik_API_ResponseBuilder(Piwik_Common::getRequestVar('format'));
try {
- $this->checkTokenInUrl();
- $enableBrowserTriggerArchiving = Piwik_Common::getRequestVar('enableBrowserTriggerArchiving');
- $todayArchiveTimeToLive = Piwik_Common::getRequestVar('todayArchiveTimeToLive');
+ $this->checkTokenInUrl();
+ $enableBrowserTriggerArchiving = Piwik_Common::getRequestVar('enableBrowserTriggerArchiving');
+ $todayArchiveTimeToLive = Piwik_Common::getRequestVar('todayArchiveTimeToLive');
- Piwik_ArchiveProcessing::setBrowserTriggerArchiving((bool)$enableBrowserTriggerArchiving);
- Piwik_ArchiveProcessing::setTodayArchiveTimeToLive($todayArchiveTimeToLive);
-
- // Update email settings
- $mail = Zend_Registry::get('config')->mail;
- $mail->transport = (Piwik_Common::getRequestVar('mailUseSmtp') == '1') ? 'smtp' : '';
- $mail->port = Piwik_Common::getRequestVar('mailPort', '');
- $mail->host = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailHost', ''));
- $mail->type = Piwik_Common::getRequestVar('mailType', '');
- $mail->username = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailUsername', ''));
- $mail->password = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailPassword', ''));
- $mail->encryption = Piwik_Common::getRequestVar('mailEncryption', '');
- Zend_Registry::get('config')->mail = $mail->toArray();
+ Piwik_ArchiveProcessing::setBrowserTriggerArchiving((bool)$enableBrowserTriggerArchiving);
+ Piwik_ArchiveProcessing::setTodayArchiveTimeToLive($todayArchiveTimeToLive);
+
+ // Update email settings
+ $mail = array();
+ $mail['transport'] = (Piwik_Common::getRequestVar('mailUseSmtp') == '1') ? 'smtp' : '';
+ $mail['port'] = Piwik_Common::getRequestVar('mailPort', '');
+ $mail['host'] = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailHost', ''));
+ $mail['type'] = Piwik_Common::getRequestVar('mailType', '');
+ $mail['username'] = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailUsername', ''));
+ $mail['password'] = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailPassword', ''));
+ $mail['encryption'] = Piwik_Common::getRequestVar('mailEncryption', '');
+ Piwik_Config_Writer::getInstance()->mail = $mail;
// update branding settings
- $branding = Zend_Registry::get('config')->branding;
- $branding->use_custom_logo = Piwik_Common::getRequestVar('useCustomLogo', '0');
- Zend_Registry::get('config')->branding = $branding->toArray();
+ Piwik_Config_Writer::getInstance()->branding['use_custom_logo'] = Piwik_Common::getRequestVar('useCustomLogo', '0');
$toReturn = $response->getResponse();
} catch(Exception $e ) {
@@ -99,10 +97,10 @@ class Piwik_CoreAdminHome_Controller extends Piwik_Controller_Admin
}
/**
- * Shows the "Track Visits" checkbox.
- */
- public function optOut()
- {
+ * Shows the "Track Visits" checkbox.
+ */
+ public function optOut()
+ {
$trackVisits = !Piwik_Tracker_IgnoreCookie::isIgnoreCookieFound();
$nonce = Piwik_Common::getRequestVar('nonce', false);
diff --git a/plugins/CorePluginsAdmin/Controller.php b/plugins/CorePluginsAdmin/Controller.php
index 51f0f657d2..aa85d01570 100644
--- a/plugins/CorePluginsAdmin/Controller.php
+++ b/plugins/CorePluginsAdmin/Controller.php
@@ -44,7 +44,7 @@ class Piwik_CorePluginsAdmin_Controller extends Piwik_Controller_Admin
$view->pluginsName = $plugins;
$this->setBasicVariablesView($view);
$view->menu = Piwik_GetAdminMenu();
- if(!Zend_Registry::get('config')->isFileWritable())
+ if(!Piwik_Config::getInstance()->isFileWritable())
{
$view->configFileNotWritable = true;
}
diff --git a/plugins/CoreUpdater/Controller.php b/plugins/CoreUpdater/Controller.php
index eb2f4672a2..4042bdee31 100644
--- a/plugins/CoreUpdater/Controller.php
+++ b/plugins/CoreUpdater/Controller.php
@@ -32,7 +32,7 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
$view = Piwik_View::factory('update_new_version_available');
$view->piwik_version = Piwik_Version::VERSION;
$view->piwik_new_version = $newVersion;
- $view->piwik_latest_version_url = Zend_Registry::get('config')->General->latest_version_url;
+ $view->piwik_latest_version_url = Piwik_Config::getInstance()->General['latest_version_url'];
$view->can_auto_update = Piwik::canAutoUpdate();
$view->makeWritableCommands = Piwik::getAutoUpdateMakeWritableMessage();
echo $view->render();
@@ -45,7 +45,7 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
Piwik::setMaxExecutionTime(0);
- $url = Zend_Registry::get('config')->General->latest_version_url;
+ $url = Piwik_Config::getInstance()->General['latest_version_url'];
$steps = array(
array('oneClick_Download', Piwik_Translate('CoreUpdater_DownloadingUpdateFromX', $url)),
array('oneClick_Unpack', Piwik_Translate('CoreUpdater_UnpackingTheUpdate')),
@@ -91,7 +91,7 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
Piwik::checkDirectoriesWritableOrDie( array(self::PATH_TO_EXTRACT_LATEST_VERSION) );
// we catch exceptions in the caller (i.e., oneClickUpdate)
- $url = Zend_Registry::get('config')->General->latest_version_url . '?cb=' . $this->newVersion;
+ $url = Piwik_Config::getInstance()->General['latest_version_url'] . '?cb=' . $this->newVersion;
$fetched = Piwik_Http::fetchRemoteFile($url, $this->pathPiwikZip);
}
@@ -122,11 +122,11 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
private function oneClick_Verify()
{
$someExpectedFiles = array(
- '/config/global.ini.php',
- '/index.php',
- '/core/Piwik.php',
- '/piwik.php',
- '/plugins/API/API.php'
+ '/config/global.ini.php',
+ '/index.php',
+ '/core/Piwik.php',
+ '/piwik.php',
+ '/plugins/API/API.php'
);
foreach($someExpectedFiles as $file)
{
@@ -275,7 +275,7 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
// handle case of existing database with no tables
if(!Piwik::isInstalled())
{
- $this->errorMessages[] = Piwik_Translate('CoreUpdater_EmptyDatabaseError', Zend_Registry::get('config')->database->dbname);
+ $this->errorMessages[] = Piwik_Translate('CoreUpdater_EmptyDatabaseError', Piwik_Config::getInstance()->database['dbname']);
$this->coreError = true;
$currentVersion = 'N/A';
}
diff --git a/plugins/CustomVariables/CustomVariables.php b/plugins/CustomVariables/CustomVariables.php
index 7b463b81a0..4669f14b05 100644
--- a/plugins/CustomVariables/CustomVariables.php
+++ b/plugins/CustomVariables/CustomVariables.php
@@ -4,7 +4,7 @@
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- * @version $Id: CustomVariables.php 5235 2011-09-27 07:20:45Z matt $
+ * @version $Id$
*
* @category Piwik_Plugins
* @package Piwik_CustomVariables
@@ -131,8 +131,8 @@ class Piwik_CustomVariables extends Piwik_Plugin
function __construct()
{
- $this->maximumRowsInDataTableLevelZero = Zend_Registry::get('config')->General->datatable_archiving_maximum_rows_referers;
- $this->maximumRowsInSubDataTable = Zend_Registry::get('config')->General->datatable_archiving_maximum_rows_subtable_referers;
+ $this->maximumRowsInDataTableLevelZero = Piwik_Config::getInstance()->General['datatable_archiving_maximum_rows_referers'];
+ $this->maximumRowsInSubDataTable = Piwik_Config::getInstance()->General['datatable_archiving_maximum_rows_subtable_referers'];
}
protected $interestByCustomVariables = array();
diff --git a/plugins/DBStats/API.php b/plugins/DBStats/API.php
index bdce31c12a..7ba5ab49ed 100644
--- a/plugins/DBStats/API.php
+++ b/plugins/DBStats/API.php
@@ -33,15 +33,7 @@ class Piwik_DBStats_API
if(function_exists('mysql_connect'))
{
- $configDb = Zend_Registry::get('config')->database->toArray();
- // we decode the password. Password is html encoded because it's enclosed between " double quotes
- $configDb['password'] = htmlspecialchars_decode($configDb['password']);
- if(!isset($configDb['port']))
- {
- // before 0.2.4 there is no port specified in config file
- $configDb['port'] = '3306';
- }
-
+ $configDb = Piwik_Config::getInstance()->database;
$link = mysql_connect($configDb['host'], $configDb['username'], $configDb['password']);
$status = mysql_stat($link);
mysql_close($link);
diff --git a/plugins/Feedback/Controller.php b/plugins/Feedback/Controller.php
index e2f55a8e50..e279429272 100644
--- a/plugins/Feedback/Controller.php
+++ b/plugins/Feedback/Controller.php
@@ -34,7 +34,7 @@ class Piwik_Feedback_Controller extends Piwik_Controller
$nonce = Piwik_Common::getRequestVar('nonce', '', 'string');
$view = Piwik_View::factory('sent');
- $view->feedbackEmailAddress = Zend_Registry::get('config')->General->feedback_email_address;
+ $view->feedbackEmailAddress = Piwik_Config::getInstance()->General['feedback_email_address'];
try
{
$minimumBodyLength = 40;
diff --git a/plugins/ImageGraph/ImageGraph.php b/plugins/ImageGraph/ImageGraph.php
index 96a6c368f3..c28e200ed0 100644
--- a/plugins/ImageGraph/ImageGraph.php
+++ b/plugins/ImageGraph/ImageGraph.php
@@ -77,7 +77,7 @@ class Piwik_ImageGraph extends Piwik_Plugin
$piwikSite = new Piwik_Site($idSite);
if($periodForSinglePeriodGraph == 'range')
{
- $periodForMultiplePeriodGraph = Zend_Registry::get('config')->General->graphs_default_period_to_plot_when_period_range;
+ $periodForMultiplePeriodGraph = Piwik_Config::getInstance()->General['graphs_default_period_to_plot_when_period_range'];
$dateForMultiplePeriodGraph = $dateForSinglePeriodGraph;
}
else
diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php
index 58bd600daa..4da8bed3f8 100644
--- a/plugins/Installation/Controller.php
+++ b/plugins/Installation/Controller.php
@@ -80,7 +80,7 @@ class Piwik_Installation_Controller extends Piwik_Controller
$this->getInstallationSteps(),
__FUNCTION__
);
- $view->newInstall = !file_exists(Piwik_Config::getDefaultUserConfigPath());
+ $view->newInstall = !file_exists(Piwik_Config::getLocalConfigPath());
$view->errorMessage = $message;
$this->skipThisStep( __FUNCTION__ );
$view->showNextStep = $view->newInstall;
@@ -387,7 +387,7 @@ class Piwik_Installation_Controller extends Piwik_Controller
$this->session->superuser_infos = $superUserInfos;
- $url = Zend_Registry::get('config')->General->api_service_url;
+ $url = Piwik_Config::getInstance()->General['api_service_url'];
$url .= '/1.0/subscribeNewsletter/';
$params = array(
'email' => $form->getSubmitValue('email'),
@@ -519,7 +519,7 @@ class Piwik_Installation_Controller extends Piwik_Controller
);
$this->skipThisStep( __FUNCTION__ );
- if(!file_exists(Piwik_Config::getDefaultUserConfigPath()))
+ if(!file_exists(Piwik_Config::getLocalConfigPath()))
{
$this->writeConfigFileFromSession();
}
@@ -551,8 +551,7 @@ class Piwik_Installation_Controller extends Piwik_Controller
protected function createDbFromSessionInformation()
{
$dbInfos = $this->session->db_infos;
- Zend_Registry::get('config')->disableSavingConfigurationFileUpdates();
- Zend_Registry::get('config')->database = $dbInfos;
+ Piwik_Config::getInstance()->database = $dbInfos;
Piwik::createDatabaseObject($dbInfos);
}
@@ -566,14 +565,21 @@ class Piwik_Installation_Controller extends Piwik_Controller
{
return;
}
- $config = Zend_Registry::get('config');
- $config->superuser = $this->session->superuser_infos;
- $dbInfos = $this->session->db_infos;
- $config->database = $dbInfos;
- if(!empty($this->session->general_infos))
- {
- $config->General = $this->session->general_infos;
+ $config = Piwik_Config_Writer::getInstance();
+ try {
+ // expect exception since config.ini.php doesn't exist yet
+ $config->init();
+ } catch(Exception $e) {
+ $config->superuser = $this->session->superuser_infos;
+ $config->database = $this->session->db_infos;
+
+ if(!empty($this->session->general_infos))
+ {
+ $config->General = $this->session->general_infos;
+ }
+
+ $config->forceSave();
}
unset($this->session->superuser_infos);
@@ -613,7 +619,7 @@ class Piwik_Installation_Controller extends Piwik_Controller
}
else
{
- if(file_exists(Piwik_Config::getDefaultUserConfigPath()))
+ if(file_exists(Piwik_Config::getLocalConfigPath()))
{
$error = true;
}
@@ -679,7 +685,7 @@ class Piwik_Installation_Controller extends Piwik_Controller
public static function getSystemInformation()
{
global $piwik_minimumPHPVersion;
- $minimumMemoryLimit = Zend_Registry::get('config')->General->minimum_memory_limit;
+ $minimumMemoryLimit = Piwik_Config::getInstance()->General['minimum_memory_limit'];
$infos = array();
diff --git a/plugins/LanguagesManager/LanguagesManager.php b/plugins/LanguagesManager/LanguagesManager.php
index 96037c91cb..febbd562f7 100644
--- a/plugins/LanguagesManager/LanguagesManager.php
+++ b/plugins/LanguagesManager/LanguagesManager.php
@@ -177,7 +177,7 @@ class Piwik_LanguagesManager extends Piwik_Plugin
*/
static public function getLanguageForSession()
{
- $cookieName = Zend_Registry::get('config')->General->language_cookie_name;
+ $cookieName = Piwik_Config::getInstance()->General['language_cookie_name'];
$cookie = new Piwik_Cookie($cookieName);
if($cookie->isCookieFound())
{
@@ -198,7 +198,7 @@ class Piwik_LanguagesManager extends Piwik_Plugin
return false;
}
- $cookieName = Zend_Registry::get('config')->General->language_cookie_name;
+ $cookieName = Piwik_Config::getInstance()->General['language_cookie_name'];
$cookie = new Piwik_Cookie($cookieName, 0);
$cookie->set('language', $languageCode);
$cookie->save();
diff --git a/plugins/Live/Controller.php b/plugins/Live/Controller.php
index c1d6b42f01..e865af2432 100644
--- a/plugins/Live/Controller.php
+++ b/plugins/Live/Controller.php
@@ -26,7 +26,7 @@ class Piwik_Live_Controller extends Piwik_Controller
$view = Piwik_View::factory('index');
$view->idSite = $this->idSite;
$view = $this->setCounters($view);
- $view->liveRefreshAfterMs = (int)Zend_Registry::get('config')->General->live_widget_refresh_after_seconds * 1000;
+ $view->liveRefreshAfterMs = (int)Piwik_Config::getInstance()->General['live_widget_refresh_after_seconds'] * 1000;
$view->visitors = $this->getLastVisitsStart($fetchPlease = true);
$view->liveTokenAuth = Piwik::getCurrentUserTokenAuth();
return $this->render($view, $fetch);
diff --git a/plugins/Login/Auth.php b/plugins/Login/Auth.php
index bd52367c49..af5bd063ee 100644
--- a/plugins/Login/Auth.php
+++ b/plugins/Login/Auth.php
@@ -36,8 +36,8 @@ class Piwik_Login_Auth implements Piwik_Auth
*/
public function authenticate()
{
- $rootLogin = Zend_Registry::get('config')->superuser->login;
- $rootPassword = Zend_Registry::get('config')->superuser->password;
+ $rootLogin = Piwik_Config::getInstance()->superuser['login'];
+ $rootPassword = Piwik_Config::getInstance()->superuser['password'];
$rootToken = Piwik_UsersManager_API::getInstance()->getTokenAuth($rootLogin, $rootPassword);
if(is_null($this->login))
diff --git a/plugins/Login/Controller.php b/plugins/Login/Controller.php
index 84dd044484..a727519779 100644
--- a/plugins/Login/Controller.php
+++ b/plugins/Login/Controller.php
@@ -93,16 +93,16 @@ class Piwik_Login_Controller extends Piwik_Controller
*/
private function configureView($view)
{
- $this->setBasicVariablesView($view);
-
+ $this->setBasicVariablesView($view);
+
$view->linkTitle = Piwik::getRandomTitle();
- $view->forceSslLogin = Zend_Registry::get('config')->General->force_ssl_login;
+ $view->forceSslLogin = Piwik_Config::getInstance()->General['force_ssl_login'];
// crsf token: don't trust the submitted value; generate/fetch it from session data
$view->nonce = Piwik_Nonce::getNonce('Piwik_Login.login');
}
-
+
/**
* Form-less login
* @see how to use it on http://piwik.org/faq/how-to/#faq_30
@@ -120,18 +120,18 @@ class Piwik_Login_Controller extends Piwik_Controller
}
$login = Piwik_Common::getRequestVar('login', null, 'string');
- if($login == Zend_Registry::get('config')->superuser->login)
- {
+ if($login == Piwik_Config::getInstance()->superuser['login'])
+ {
throw new Exception(Piwik_TranslateException('Login_ExceptionInvalidSuperUserAuthenticationMethod', array("logme")));
}
$currentUrl = 'index.php';
-
+
if(($idSite = Piwik_Common::getRequestVar('idSite', false, 'int')) !== false)
- {
+ {
$currentUrl .= '?idSite='.$idSite;
}
-
+
$urlToRedirect = Piwik_Common::getRequestVar('url', $currentUrl, 'string');
$urlToRedirect = Piwik_Common::unsanitizeInputValue($urlToRedirect);
@@ -196,7 +196,7 @@ class Piwik_Login_Controller extends Piwik_Controller
{
return Piwik_Translate('Login_InvalidNonceOrHeadersOrReferer', array('<a href="?module=Proxy&action=redirect&url='.urlencode('http://piwik.org/faq/how-to-install/#faq_98').'" target="_blank">', '</a>'));
}
-
+
/**
* Validate user (by username or email address).
*
@@ -241,8 +241,8 @@ class Piwik_Login_Controller extends Piwik_Controller
$mail->setBodyText($bodyText);
- $fromEmailName = Zend_Registry::get('config')->General->login_password_recovery_email_name;
- $fromEmailAddress = Zend_Registry::get('config')->General->login_password_recovery_email_address;
+ $fromEmailName = Piwik_Config::getInstance()->General['login_password_recovery_email_name'];
+ $fromEmailAddress = Piwik_Config::getInstance()->General['login_password_recovery_email_address'];
$mail->setFrom($fromEmailAddress, $fromEmailName);
@$mail->send();
}
@@ -286,7 +286,7 @@ class Piwik_Login_Controller extends Piwik_Controller
$view = Piwik_View::factory('resetPassword');
$view->AccessErrorString = $messageNoAccess;
- $view->forceSslLogin = Zend_Registry::get('config')->General->force_ssl_login;
+ $view->forceSslLogin = Piwik_Config::getInstance()->General['force_ssl_login'];
$view->addForm( $form );
$this->configureView($view);
echo $view->render();
@@ -318,12 +318,13 @@ class Piwik_Login_Controller extends Piwik_Controller
{
if( $user['email'] == Piwik::getSuperUserEmail() )
{
- if(!Zend_Registry::get('config')->isFileWritable())
- {
- throw new Exception(Piwik_Translate('General_ConfigFileIsNotWritable', array("(config/config.ini.php)","<br/>")));
- }
+ if(!Piwik_Config::getInstance()->isFileWritable())
+ {
+ throw new Exception(Piwik_Translate('General_ConfigFileIsNotWritable', array("(config/config.ini.php)","<br/>")));
+ }
+
$user['password'] = md5($password);
- Zend_Registry::get('config')->superuser = $user;
+ Piwik_Config_Writer::getInstance()->superuser = $user;
}
else
{
@@ -352,12 +353,12 @@ class Piwik_Login_Controller extends Piwik_Controller
$user = null;
if( $loginMail == Piwik::getSuperUserEmail()
- || $loginMail == Zend_Registry::get('config')->superuser->login )
+ || $loginMail == Piwik_Config::getInstance()->superuser['login'] )
{
$user = array(
- 'login' => Zend_Registry::get('config')->superuser->login,
+ 'login' => Piwik_Config::getInstance()->superuser['login'],
'email' => Piwik::getSuperUserEmail(),
- 'password' => Zend_Registry::get('config')->superuser->password,
+ 'password' => Piwik_Config::getInstance()->superuser['password'],
);
}
else if( Piwik_UsersManager_API::getInstance()->userExists($loginMail) )
@@ -431,7 +432,7 @@ class Piwik_Login_Controller extends Piwik_Controller
*/
static public function clearSession()
{
- $authCookieName = Zend_Registry::get('config')->General->login_cookie_name;
+ $authCookieName = Piwik_Config::getInstance()->General['login_cookie_name'];
$cookie = new Piwik_Cookie($authCookieName);
$cookie->delete();
@@ -458,7 +459,7 @@ class Piwik_Login_Controller extends Piwik_Controller
*/
protected function checkForceSslLogin()
{
- $forceSslLogin = Zend_Registry::get('config')->General->force_ssl_login;
+ $forceSslLogin = Piwik_Config::getInstance()->General['force_ssl_login'];
if($forceSslLogin
&& !Piwik::isHttps())
{
diff --git a/plugins/Login/Login.php b/plugins/Login/Login.php
index 92dd6bfb95..1f836e72cb 100644
--- a/plugins/Login/Login.php
+++ b/plugins/Login/Login.php
@@ -84,9 +84,9 @@ class Piwik_Login extends Piwik_Plugin
return;
}
- $authCookieName = Zend_Registry::get('config')->General->login_cookie_name;
+ $authCookieName = Piwik_Config::getInstance()->General['login_cookie_name'];
$authCookieExpiry = 0;
- $authCookiePath = Zend_Registry::get('config')->General->login_cookie_path;
+ $authCookiePath = Piwik_Config::getInstance()->General['login_cookie_path'];
$authCookie = new Piwik_Cookie($authCookieName, $authCookieExpiry, $authCookiePath);
$defaultLogin = 'anonymous';
$defaultTokenAuth = 'anonymous';
@@ -119,9 +119,9 @@ class Piwik_Login extends Piwik_Plugin
$auth->setTokenAuth($tokenAuth);
$authResult = $auth->authenticate();
- $authCookieName = Zend_Registry::get('config')->General->login_cookie_name;
- $authCookieExpiry = $rememberMe ? time() + Zend_Registry::get('config')->General->login_cookie_expire : 0;
- $authCookiePath = Zend_Registry::get('config')->General->login_cookie_path;
+ $authCookieName = Piwik_Config::getInstance()->General['login_cookie_name'];
+ $authCookieExpiry = $rememberMe ? time() + Piwik_Config::getInstance()->General['login_cookie_expire'] : 0;
+ $authCookiePath = Piwik_Config::getInstance()->General['login_cookie_path'];
$cookie = new Piwik_Cookie($authCookieName, $authCookieExpiry, $authCookiePath);
if(!$authResult->isValid())
diff --git a/plugins/Login/tests/Login.test.php b/plugins/Login/tests/Login.test.php
index 207bf4124e..ef6815ba15 100644
--- a/plugins/Login/tests/Login.test.php
+++ b/plugins/Login/tests/Login.test.php
@@ -12,12 +12,12 @@ require_once 'Database.test.php';
class Test_Piwik_Login extends Test_Database
{
- function setUp()
- {
- parent::setUp();
+ function setUp()
+ {
+ parent::setUp();
// setup the access layer
- $pseudoMockAccess = new FakeAccess;
+ $pseudoMockAccess = new FakeAccess;
FakeAccess::setIdSitesView( array(1,2));
FakeAccess::setIdSitesAdmin( array(3,4));
@@ -26,12 +26,12 @@ class Test_Piwik_Login extends Test_Database
Zend_Registry::set('access', $pseudoMockAccess);
// we make sure the tests don't depend on the config file content
- Zend_Registry::get('config')->superuser = array(
+ Piwik_Config::getInstance()->superuser = array(
'login'=>'superusertest',
'password'=>md5('passwordsuperusertest'),
'email'=>'superuser@example.com'
);
- }
+ }
public function test_authenticate()
{
@@ -175,7 +175,7 @@ class Test_Piwik_Login extends Test_Database
$rc = $auth->authenticate();
$this->assertEqual( $rc->getCode(), Piwik_Auth_Result::SUCCESS );
- $user = Zend_Registry::get('config')->superuser->toArray();
+ $user = Piwik_Config::getInstance()->superuser;
$password = $user['password'];
$tokenAuth = Piwik_UsersManager_API::getInstance()->getTokenAuth($user['login'], $password);
diff --git a/plugins/MultiSites/Controller.php b/plugins/MultiSites/Controller.php
index fdcd2e5bc9..5ec0c442e0 100644
--- a/plugins/MultiSites/Controller.php
+++ b/plugins/MultiSites/Controller.php
@@ -28,7 +28,7 @@ class Piwik_MultiSites_Controller extends Piwik_Controller
{
parent::__construct();
- $this->limit = Zend_Registry::get('config')->General->all_websites_website_per_page;
+ $this->limit = Piwik_Config::getInstance()->General['all_websites_website_per_page'];
}
function index()
@@ -152,12 +152,12 @@ class Piwik_MultiSites_Controller extends Piwik_Controller
Piwik_Date::factory('now', 'UTC+14')->toString('Y-m-d'))))
{
- $view->autoRefreshTodayReport = Zend_Registry::get('config')->General->multisites_refresh_after_seconds;
+ $view->autoRefreshTodayReport = Piwik_Config::getInstance()->General['multisites_refresh_after_seconds'];
}
$this->setGeneralVariablesView($view);
$this->setMinDateView($minDate, $view);
$this->setMaxDateView($maxDate, $view);
- $view->show_sparklines = Zend_Registry::get('config')->General->show_multisites_sparklines;
+ $view->show_sparklines = Piwik_Config::getInstance()->General['show_multisites_sparklines'];
echo $view->render();
}
diff --git a/plugins/PDFReports/API.php b/plugins/PDFReports/API.php
index b4e54215be..62f511cd0d 100644
--- a/plugins/PDFReports/API.php
+++ b/plugins/PDFReports/API.php
@@ -461,7 +461,7 @@ class Piwik_PDFReports_API
{
$emails[] = Piwik::getCurrentUserEmail();
}
- elseif($report['login'] == Zend_Registry::get('config')->superuser->login)
+ elseif($report['login'] == Piwik_Config::getInstance()->superuser['login'])
{
$emails[] = Piwik::getSuperUserEmail();
}
@@ -506,10 +506,10 @@ class Piwik_PDFReports_API
$mail = new Piwik_Mail();
$mail->setSubject($subject);
- $fromEmailName = Zend_Registry::get('config')->branding->use_custom_logo
+ $fromEmailName = Piwik_Config::getInstance()->branding['use_custom_logo']
? Piwik_Translate('CoreHome_WebAnalyticsReports')
: Piwik_Translate('PDFReports_PiwikReports');
- $fromEmailAddress = Zend_Registry::get('config')->General->noreply_email_address;
+ $fromEmailAddress = Piwik_Config::getInstance()->General['noreply_email_address'];
$attachmentName = $subject;
$mail->setFrom($fromEmailAddress, $fromEmailName);
diff --git a/plugins/PDFReports/tests/PDFReports.test.php b/plugins/PDFReports/tests/PDFReports.test.php
index 373528570a..6311e60b94 100644
--- a/plugins/PDFReports/tests/PDFReports.test.php
+++ b/plugins/PDFReports/tests/PDFReports.test.php
@@ -13,219 +13,223 @@ require_once PIWIK_PATH_TEST_TO_ROOT . '/plugins/PDFReports/PDFReports.php';
class Test_Piwik_PDFReports extends Test_Database
{
protected $idSiteAccess;
- function setUp()
- {
- parent::setUp();
-
+
+ function setUp()
+ {
+ parent::setUp();
+
// setup the access layer
- $pseudoMockAccess = new FakeAccess;
+ $pseudoMockAccess = new FakeAccess;
FakeAccess::$superUser = true;
//finally we set the user as a super user by default
Zend_Registry::set('access', $pseudoMockAccess);
- Piwik_PluginsManager::getInstance()->loadPlugins( array('API', 'UserCountry', 'PDFReports') );
+ Piwik_PluginsManager::getInstance()->loadPlugins( array('API', 'UserCountry', 'LanguagesManager', 'PDFReports') );
+ $plugin = Piwik_PluginsManager::getInstance()->getLoadedPlugin('LanguagesManager');
+ $plugin->install();
+ $plugin = Piwik_PluginsManager::getInstance()->getLoadedPlugin('PDFReports');
+ $plugin->install();
Piwik_PluginsManager::getInstance()->installLoadedPlugins();
- Piwik_PDFReports_API::$cache = array();
-
- $this->idSiteAccess = Piwik_SitesManager_API::getInstance()->addSite("Test",array("http://piwik.net"));
-
- $idSite = Piwik_SitesManager_API::getInstance()->addSite("Test",array("http://piwik.net"));
+ Piwik_PDFReports_API::$cache = array();
+
+ $this->idSiteAccess = Piwik_SitesManager_API::getInstance()->addSite("Test",array("http://piwik.net"));
+
+ $idSite = Piwik_SitesManager_API::getInstance()->addSite("Test",array("http://piwik.net"));
FakeAccess::setIdSitesView( array($this->idSiteAccess,2));
-
- }
-
- function tearDown()
- {
- Piwik_Query('TRUNCATE '.Piwik_Common::prefixTable('pdf'));
- Piwik_PDFReports_API::$cache = array();
- }
-
- function test_addReport_getReports()
- {
- $data = array(
- 'idsite' => $this->idSiteAccess,
- 'description' => 'test description"',
- 'period' => 'day',
- 'format' => 'pdf',
- 'aggregate_reports_format' => '1',
- 'reports' => 'UserCountry_getCountry',
- 'email_me' => 1,
- 'additional_emails' => 'test@test.com, t2@test.com',
- );
-
- $dataWebsiteTwo = $data;
- $dataWebsiteTwo['idsite'] = 2;
- $dataWebsiteTwo['period'] = 'month';
-
- $idReportTwo = $this->_createReport($dataWebsiteTwo);
- // Testing getReports without parameters
- $tmp = Piwik_PDFReports_API::getInstance()->getReports();
- $report = reset($tmp);
- $this->_checkReportsEqual($report, $dataWebsiteTwo);
-
- $idReport = $this->_createReport($data);
-
- // Passing 3 parameters
- $tmp = Piwik_PDFReports_API::getInstance()->getReports($this->idSiteAccess, $data['period'], $idReport);
- $report = reset($tmp);
- $this->_checkReportsEqual($report, $data);
-
- // Passing only idsite
- $tmp = Piwik_PDFReports_API::getInstance()->getReports($this->idSiteAccess);
- $report = reset($tmp);
- $this->_checkReportsEqual($report, $data);
-
- // Passing only period
- $tmp = Piwik_PDFReports_API::getInstance()->getReports($idSite=false, $data['period']);
- $report = reset($tmp);
- $this->_checkReportsEqual($report, $data);
-
- // Passing only idreport
- $tmp = Piwik_PDFReports_API::getInstance()->getReports($idSite=false,$period=false, $idReport);
- $report = reset($tmp);
- $this->_checkReportsEqual($report, $data);
-
- }
-
- function test_getReports_idReportNotFound()
- {
- try {
- $report = Piwik_PDFReports_API::getInstance()->getReports($idSite=false,$period=false, $idReport = 1);
- var_dump($report);
- $this->fail();
- } catch(Exception $e) {
- $this->pass();
- }
- }
-
- function test_getReports_invalidPermission()
- {
- $data = $this->_getAddReportData();
- $idReport = $this->_createReport($data);
-
- try {
- $report = Piwik_PDFReports_API::getInstance()->getReports($idSite=44,$period=false, $idReport);
- $this->fail();
- } catch(Exception $e){
- $this->pass();
- }
- }
-
- function test_addReport_invalidWebsite()
- {
- $data = $this->_getAddReportData();
- $data['idsite'] = 33;
- try {
- $idReport = $this->_createReport($data);
- $this->fail();
- } catch(Exception $e){
- $this->pass();
- }
- }
-
- function test_addReport_invalidPeriod()
- {
- $data = $this->_getAddReportData();
- $data['period'] = 'dx';
- try {
- $idReport = $this->_createReport($data);
- $this->fail();
- } catch(Exception $e){
- $this->pass();
- }
- }
-
- function test_updateReport()
- {
- $dataBefore = $this->_getAddReportData();
- $idReport = $this->_createReport($dataBefore);
- $dataAfter = $this->_getYetAnotherAddReportData();
- $this->_updateReport($idReport, $dataAfter);
- $tmp = Piwik_PDFReports_API::getInstance()->getReports($idSite=false,$period=false, $idReport);
- $newReport = reset($tmp);
- $this->_checkReportsEqual($newReport, $dataAfter);
- }
-
- function test_deleteReport()
- {
- // Deletes non existing report throws exception
- try {
- Piwik_PDFReports_API::getInstance()->deleteReport($idReport = 1);
- $this->fail();
- } catch(Exception $e) {
- $this->pass();
- }
-
- $idReport = $this->_createReport($this->_getYetAnotherAddReportData());
- $this->assertEqual(1, count(Piwik_PDFReports_API::getInstance()->getReports()));
+
+ }
+
+ function tearDown()
+ {
+ Piwik_Query('TRUNCATE '.Piwik_Common::prefixTable('pdf'));
+ Piwik_PDFReports_API::$cache = array();
+ }
+
+ function test_addReport_getReports()
+ {
+ $data = array(
+ 'idsite' => $this->idSiteAccess,
+ 'description' => 'test description"',
+ 'period' => 'day',
+ 'format' => 'pdf',
+ 'aggregate_reports_format' => '1',
+ 'reports' => 'UserCountry_getCountry',
+ 'email_me' => 1,
+ 'additional_emails' => 'test@test.com, t2@test.com',
+ );
+
+ $dataWebsiteTwo = $data;
+ $dataWebsiteTwo['idsite'] = 2;
+ $dataWebsiteTwo['period'] = 'month';
+
+ $idReportTwo = $this->_createReport($dataWebsiteTwo);
+ // Testing getReports without parameters
+ $tmp = Piwik_PDFReports_API::getInstance()->getReports();
+ $report = reset($tmp);
+ $this->_checkReportsEqual($report, $dataWebsiteTwo);
+
+ $idReport = $this->_createReport($data);
+
+ // Passing 3 parameters
+ $tmp = Piwik_PDFReports_API::getInstance()->getReports($this->idSiteAccess, $data['period'], $idReport);
+ $report = reset($tmp);
+ $this->_checkReportsEqual($report, $data);
+
+ // Passing only idsite
+ $tmp = Piwik_PDFReports_API::getInstance()->getReports($this->idSiteAccess);
+ $report = reset($tmp);
+ $this->_checkReportsEqual($report, $data);
+
+ // Passing only period
+ $tmp = Piwik_PDFReports_API::getInstance()->getReports($idSite=false, $data['period']);
+ $report = reset($tmp);
+ $this->_checkReportsEqual($report, $data);
+
+ // Passing only idreport
+ $tmp = Piwik_PDFReports_API::getInstance()->getReports($idSite=false,$period=false, $idReport);
+ $report = reset($tmp);
+ $this->_checkReportsEqual($report, $data);
+ }
+
+ function test_getReports_idReportNotFound()
+ {
+ try {
+ $report = Piwik_PDFReports_API::getInstance()->getReports($idSite=false,$period=false, $idReport = 1);
+ var_dump($report);
+ $this->fail();
+ } catch(Exception $e) {
+ $this->pass();
+ }
+ }
+
+ function test_getReports_invalidPermission()
+ {
+ $data = $this->_getAddReportData();
+ $idReport = $this->_createReport($data);
+
+ try {
+ $report = Piwik_PDFReports_API::getInstance()->getReports($idSite=44,$period=false, $idReport);
+ $this->fail();
+ } catch(Exception $e){
+ $this->pass();
+ }
+ }
+
+ function test_addReport_invalidWebsite()
+ {
+ $data = $this->_getAddReportData();
+ $data['idsite'] = 33;
+ try {
+ $idReport = $this->_createReport($data);
+ $this->fail();
+ } catch(Exception $e){
+ $this->pass();
+ }
+ }
+
+ function test_addReport_invalidPeriod()
+ {
+ $data = $this->_getAddReportData();
+ $data['period'] = 'dx';
+ try {
+ $idReport = $this->_createReport($data);
+ $this->fail();
+ } catch(Exception $e){
+ $this->pass();
+ }
+ }
+
+ function test_updateReport()
+ {
+ $dataBefore = $this->_getAddReportData();
+ $idReport = $this->_createReport($dataBefore);
+ $dataAfter = $this->_getYetAnotherAddReportData();
+ $this->_updateReport($idReport, $dataAfter);
+ $tmp = Piwik_PDFReports_API::getInstance()->getReports($idSite=false,$period=false, $idReport);
+ $newReport = reset($tmp);
+ $this->_checkReportsEqual($newReport, $dataAfter);
+ }
+
+ function test_deleteReport()
+ {
+ // Deletes non existing report throws exception
+ try {
+ Piwik_PDFReports_API::getInstance()->deleteReport($idReport = 1);
+ $this->fail();
+ } catch(Exception $e) {
+ $this->pass();
+ }
+
+ $idReport = $this->_createReport($this->_getYetAnotherAddReportData());
+ $this->assertEqual(1, count(Piwik_PDFReports_API::getInstance()->getReports()));
Piwik_PDFReports_API::getInstance()->deleteReport($idReport);
- $this->assertEqual(0, count(Piwik_PDFReports_API::getInstance()->getReports()));
- }
-
-
- function _getAddReportData()
- {
- return array(
- 'idsite' => $this->idSiteAccess,
- 'description' => 'test description"',
- 'period' => 'day',
- 'format' => 'pdf',
- 'aggregate_reports_format' => '1',
- 'reports' => 'UserCountry_getCountry',
- 'email_me' => 1,
- 'additional_emails' => 'test@test.com, t2@test.com',
- );
- }
-
- function _getYetAnotherAddReportData()
- {
- return array(
- 'idsite' => $this->idSiteAccess,
- 'description' => 'very very long and possibly truncated description. very very long and possibly truncated description. very very long and possibly truncated description. very very long and possibly truncated description. very very long and possibly truncated description. ',
- 'period' => 'month',
- 'format' => 'pdf',
- 'aggregate_reports_format' => '1',
- 'reports' => 'UserCountry_getContinent',
- 'email_me' => 0,
- 'additional_emails' => 'blabla@ec.fr',
- );
- }
- function _createReport($data)
- {
- $idReport = Piwik_PDFReports_API::getInstance()->addReport(
- $data['idsite'],
- $data['description'],
- $data['period'],
- $data['format'],
- $data['aggregate_reports_format'],
- $data['reports'],
- $data['email_me'],
- $data['additional_emails']);
- return $idReport;
- }
-
- function _updateReport($idReport, $data)
- {
- //$idReport, $idSite, $description, $period, $reports, $emailMe = true, $additionalEmails = false)
- $idReport = Piwik_PDFReports_API::getInstance()->updateReport(
- $idReport,
- $data['idsite'],
- $data['description'],
- $data['period'],
- $data['format'],
- $data['aggregate_reports_format'],
- $data['reports'],
- $data['email_me'],
- $data['additional_emails']);
- return $idReport;
- }
- function _checkReportsEqual($report, $data)
- {
- foreach($data as $key => $value)
- {
- if($key == 'additional_emails') $value = str_replace(' ','', $value);
- if($key == 'description') $value = substr($value,0,250);
- $this->assertEqual($value, $report[$key], "Error for $key for report ".var_export($report ,true)." and data ".var_export($data,true)." ---> %s ");
- }
- }
-
+ $this->assertEqual(0, count(Piwik_PDFReports_API::getInstance()->getReports()));
+ }
+
+
+ function _getAddReportData()
+ {
+ return array(
+ 'idsite' => $this->idSiteAccess,
+ 'description' => 'test description"',
+ 'period' => 'day',
+ 'format' => 'pdf',
+ 'aggregate_reports_format' => '1',
+ 'reports' => 'UserCountry_getCountry',
+ 'email_me' => 1,
+ 'additional_emails' => 'test@test.com, t2@test.com',
+ );
+ }
+
+ function _getYetAnotherAddReportData()
+ {
+ return array(
+ 'idsite' => $this->idSiteAccess,
+ 'description' => 'very very long and possibly truncated description. very very long and possibly truncated description. very very long and possibly truncated description. very very long and possibly truncated description. very very long and possibly truncated description. ',
+ 'period' => 'month',
+ 'format' => 'pdf',
+ 'aggregate_reports_format' => '1',
+ 'reports' => 'UserCountry_getContinent',
+ 'email_me' => 0,
+ 'additional_emails' => 'blabla@ec.fr',
+ );
+ }
+ function _createReport($data)
+ {
+ $idReport = Piwik_PDFReports_API::getInstance()->addReport(
+ $data['idsite'],
+ $data['description'],
+ $data['period'],
+ $data['format'],
+ $data['aggregate_reports_format'],
+ $data['reports'],
+ $data['email_me'],
+ $data['additional_emails']);
+ return $idReport;
+ }
+
+ function _updateReport($idReport, $data)
+ {
+ //$idReport, $idSite, $description, $period, $reports, $emailMe = true, $additionalEmails = false)
+ $idReport = Piwik_PDFReports_API::getInstance()->updateReport(
+ $idReport,
+ $data['idsite'],
+ $data['description'],
+ $data['period'],
+ $data['format'],
+ $data['aggregate_reports_format'],
+ $data['reports'],
+ $data['email_me'],
+ $data['additional_emails']);
+ return $idReport;
+ }
+
+ function _checkReportsEqual($report, $data)
+ {
+ foreach($data as $key => $value)
+ {
+ if($key == 'additional_emails') $value = str_replace(' ','', $value);
+ if($key == 'description') $value = substr($value,0,250);
+ $this->assertEqual($value, $report[$key], "Error for $key for report ".var_export($report ,true)." and data ".var_export($data,true)." ---> %s ");
+ }
+ }
}
diff --git a/plugins/PrivacyManager/Controller.php b/plugins/PrivacyManager/Controller.php
index bdd9bc3e39..172eef809f 100644
--- a/plugins/PrivacyManager/Controller.php
+++ b/plugins/PrivacyManager/Controller.php
@@ -29,20 +29,20 @@ class Piwik_PrivacyManager_Controller extends Piwik_Controller_Admin
{
case("formMaskLength"):
$this->handlePluginState(Piwik_Common::getRequestVar("anonymizeIPEnable", 0));
- $maskLength = Zend_Registry::get('config')->Tracker;
- $maskLength->ip_address_mask_length = Piwik_Common::getRequestVar("maskLength", 1);
- Zend_Registry::get('config')->Tracker = $maskLength->toArray();
+ $trackerConfig = Piwik_Config_Writer::getInstance()->Tracker;
+ $trackerConfig['ip_address_mask_length'] = Piwik_Common::getRequestVar("maskLength", 1);
+ Piwik_Config::getInstance()->Tracker = $trackerConfig;
break;
case("formDeleteSettings"):
- $deleteLogs = Zend_Registry::get('config')->Deletelogs;
- $deleteLogs->delete_logs_enable = Piwik_Common::getRequestVar("deleteEnable", 0);
- $deleteLogs->delete_logs_schedule_lowest_interval = Piwik_Common::getRequestVar("deleteLowestInterval", 7);
- $deleteLogs->delete_logs_older_than = ((int)Piwik_Common::getRequestVar("deleteOlderThan", 180) < 7) ?
+ $deleteLogs = Piwik_Config_Writer::getInstance()->Deletelogs;
+ $deleteLogs['delete_logs_enable'] = Piwik_Common::getRequestVar("deleteEnable", 0);
+ $deleteLogs['delete_logs_schedule_lowest_interval'] = Piwik_Common::getRequestVar("deleteLowestInterval", 7);
+ $deleteLogs['delete_logs_older_than'] = ((int)Piwik_Common::getRequestVar("deleteOlderThan", 180) < 7) ?
7 : Piwik_Common::getRequestVar("deleteOlderThan", 180);
- $deleteLogs->delete_max_rows_per_run = Piwik_Common::getRequestVar("deleteMaxRows", 100);
+ $deleteLogs['delete_max_rows_per_run'] = Piwik_Common::getRequestVar("deleteMaxRows", 100);
- Zend_Registry::get('config')->Deletelogs = $deleteLogs->toArray();
+ Piwik_Config::getInstance()->Deletelogs = $deleteLogs;
break;
default: //do nothing
@@ -66,8 +66,8 @@ class Piwik_PrivacyManager_Controller extends Piwik_Controller_Admin
}
$view->language = Piwik_LanguagesManager::getLanguageCodeForCurrentUser();
- if (!Zend_Registry::get('config')->isFileWritable())
- {
+ if (!Piwik_Config::getInstance()->isFileWritable())
+ {
$view->configFileNotWritable = true;
}
@@ -86,7 +86,7 @@ class Piwik_PrivacyManager_Controller extends Piwik_Controller_Admin
$anonymizeIP["name"] = self::ANONYMIZE_IP_PLUGIN_NAME;
$anonymizeIP["enabled"] = Piwik_PluginsManager::getInstance()->isPluginActivated(self::ANONYMIZE_IP_PLUGIN_NAME);
- $anonymizeIP["maskLength"] = Zend_Registry::get('config')->Tracker->ip_address_mask_length;
+ $anonymizeIP["maskLength"] = Piwik_Config::getInstance()->Tracker['ip_address_mask_length'];
$anonymizeIP["info"] = Piwik_PluginsManager::getInstance()->getLoadedPlugin(self::ANONYMIZE_IP_PLUGIN_NAME)->getInformation();
return $anonymizeIP;
@@ -97,7 +97,7 @@ class Piwik_PrivacyManager_Controller extends Piwik_Controller_Admin
Piwik::checkUserIsSuperUser();
$deleteLogsInfos = array();
$taskScheduler = new Piwik_TaskScheduler();
- $deleteLogsInfos["config"] = Zend_Registry::get('config')->Deletelogs->toArray();
+ $deleteLogsInfos["config"] = Piwik_Config::getInstance()->Deletelogs;
$privacyManager = new Piwik_PrivacyManager();
$deleteLogsInfos["deleteTables"] = implode(", ", $privacyManager->getDeleteTableLogTables());
diff --git a/plugins/PrivacyManager/PrivacyManager.php b/plugins/PrivacyManager/PrivacyManager.php
index 73965cd6ed..e008922f14 100644
--- a/plugins/PrivacyManager/PrivacyManager.php
+++ b/plugins/PrivacyManager/PrivacyManager.php
@@ -68,10 +68,10 @@ class Piwik_PrivacyManager extends Piwik_Plugin
*/
function deleteLogTables()
{
- $deleteSettings = Zend_Registry::get('config')->Deletelogs;
+ $deleteSettings = Piwik_Config::getInstance()->Deletelogs;
//Make sure, log deletion is enabled
- if ($deleteSettings->delete_logs_enable == 0) {
+ if ($deleteSettings['delete_logs_enable'] == 0) {
return;
}
@@ -84,13 +84,13 @@ class Piwik_PrivacyManager extends Piwik_Plugin
//Make sure, log purging is allowed to run now
$lastDelete = Piwik_GetOption(self::OPTION_LAST_DELETE_PIWIK_LOGS);
- $deleteIntervalSeconds = $this->getDeleteIntervalInSeconds($deleteSettings->delete_logs_schedule_lowest_interval);
+ $deleteIntervalSeconds = $this->getDeleteIntervalInSeconds($deleteSettings['delete_logs_schedule_lowest_interval']);
if ($lastDelete === false ||
($lastDelete !== false && ((int)$lastDelete + $deleteIntervalSeconds) <= time())
) {
- $maxIdVisit = $this->getDeleteIdVisitOffset($deleteSettings->delete_logs_older_than);
+ $maxIdVisit = $this->getDeleteIdVisitOffset($deleteSettings['delete_logs_older_than']);
$logTables = $this->getDeleteTableLogTables();
@@ -111,7 +111,7 @@ class Piwik_PrivacyManager extends Piwik_Plugin
}
foreach ($logTables as $logTable) {
- $this->deleteRowsFromTable($logTable, $maxIdVisit, $deleteSettings->delete_max_rows_per_run * self::DELETE_MAX_ROWS_MULTIPLICATOR);
+ $this->deleteRowsFromTable($logTable, $maxIdVisit, $deleteSettings['delete_max_rows_per_run'] * self::DELETE_MAX_ROWS_MULTIPLICATOR);
}
//optimize table overhead after deletion
diff --git a/plugins/Provider/Provider.php b/plugins/Provider/Provider.php
index 139b15e2ec..60214f8268 100644
--- a/plugins/Provider/Provider.php
+++ b/plugins/Provider/Provider.php
@@ -114,7 +114,7 @@ class Piwik_Provider extends Piwik_Plugin
function archivePeriod( $notification )
{
- $maximumRowsInDataTable = Zend_Registry::get('config')->General->datatable_archiving_maximum_rows_standard;
+ $maximumRowsInDataTable = Piwik_Config::getInstance()->General['datatable_archiving_maximum_rows_standard'];
$archiveProcessing = $notification->getNotificationObject();
if(!$archiveProcessing->shouldProcessReportsForPlugin($this->getPluginName())) return;
@@ -137,7 +137,7 @@ class Piwik_Provider extends Piwik_Plugin
$interestByProvider = $archiveProcessing->getArrayInterestForLabel($labelSQL);
$tableProvider = $archiveProcessing->getDataTableFromArray($interestByProvider);
$columnToSortByBeforeTruncation = Piwik_Archive::INDEX_NB_VISITS;
- $maximumRowsInDataTable = Zend_Registry::get('config')->General->datatable_archiving_maximum_rows_standard;
+ $maximumRowsInDataTable = Piwik_Config::getInstance()->General['datatable_archiving_maximum_rows_standard'];
$archiveProcessing->insertBlobRecord($recordName, $tableProvider->getSerialized($maximumRowsInDataTable, null, $columnToSortByBeforeTruncation));
destroy($tableProvider);
}
diff --git a/plugins/Proxy/tests/Proxy.test.php b/plugins/Proxy/tests/Proxy.test.php
index b775f5f7aa..d84e15a4d0 100644
--- a/plugins/Proxy/tests/Proxy.test.php
+++ b/plugins/Proxy/tests/Proxy.test.php
@@ -9,7 +9,7 @@ class Test_Piwik_Proxy extends UnitTestCase
public function test_isAcceptableRemoteUrl()
{
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
$data = array(
// piwik white list (and used in homepage)
diff --git a/plugins/Referers/Referers.php b/plugins/Referers/Referers.php
index 64c39b71f3..eab4c37a0d 100644
--- a/plugins/Referers/Referers.php
+++ b/plugins/Referers/Referers.php
@@ -222,8 +222,8 @@ class Piwik_Referers extends Piwik_Plugin
function __construct()
{
$this->columnToSortByBeforeTruncation = Piwik_Archive::INDEX_NB_VISITS;
- $this->maximumRowsInDataTableLevelZero = Zend_Registry::get('config')->General->datatable_archiving_maximum_rows_referers;
- $this->maximumRowsInSubDataTable = Zend_Registry::get('config')->General->datatable_archiving_maximum_rows_subtable_referers;
+ $this->maximumRowsInDataTableLevelZero = Piwik_Config::getInstance()->General['datatable_archiving_maximum_rows_referers'];
+ $this->maximumRowsInSubDataTable = Piwik_Config::getInstance()->General['datatable_archiving_maximum_rows_subtable_referers'];
}
/**
diff --git a/plugins/UserSettings/UserSettings.php b/plugins/UserSettings/UserSettings.php
index b49dd75cac..68da147ebc 100644
--- a/plugins/UserSettings/UserSettings.php
+++ b/plugins/UserSettings/UserSettings.php
@@ -246,7 +246,7 @@ class Piwik_UserSettings extends Piwik_Plugin
function archiveDay( $notification )
{
require_once PIWIK_INCLUDE_PATH . '/plugins/UserSettings/functions.php';
- $maximumRowsInDataTable = Zend_Registry::get('config')->General->datatable_archiving_maximum_rows_standard;
+ $maximumRowsInDataTable = Piwik_Config::getInstance()->General['datatable_archiving_maximum_rows_standard'];
$columnToSortByBeforeTruncation = Piwik_Archive::INDEX_NB_VISITS;
$archiveProcessing = $notification->getNotificationObject();
@@ -313,7 +313,7 @@ class Piwik_UserSettings extends Piwik_Plugin
if(!$archiveProcessing->shouldProcessReportsForPlugin($this->getPluginName())) return;
- $maximumRowsInDataTable = Zend_Registry::get('config')->General->datatable_archiving_maximum_rows_standard;
+ $maximumRowsInDataTable = Piwik_Config::getInstance()->General['datatable_archiving_maximum_rows_standard'];
$dataTableToSum = array(
'UserSettings_configuration',
diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php
index c8ac766e19..5b071f468b 100644
--- a/plugins/UsersManager/API.php
+++ b/plugins/UsersManager/API.php
@@ -622,7 +622,7 @@ class Piwik_UsersManager_API
private function checkUserIsNotSuperUser( $userLogin )
{
- if($userLogin == Zend_Registry::get('config')->superuser->login)
+ if($userLogin == Piwik_Config::getInstance()->superuser['login'])
{
throw new Exception(Piwik_TranslateException("UsersManager_ExceptionSuperUser"));
}
diff --git a/plugins/UsersManager/Controller.php b/plugins/UsersManager/Controller.php
index 63028e8aba..29b29efa96 100644
--- a/plugins/UsersManager/Controller.php
+++ b/plugins/UsersManager/Controller.php
@@ -108,7 +108,7 @@ class Piwik_UsersManager_Controller extends Piwik_Controller_Admin
$userSettingsDate = Piwik_UsersManager_API::getInstance()->getUserPreference($user, Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE);
if($userSettingsDate === false)
{
- return Zend_Registry::get('config')->General->default_day;
+ return Piwik_Config::getInstance()->General['default_day'];
}
return $userSettingsDate;
}
@@ -127,7 +127,7 @@ class Piwik_UsersManager_Controller extends Piwik_Controller_Admin
{
$view->userAlias = $userLogin;
$view->userEmail = Piwik::getSuperUserEmail();
- if(!Zend_Registry::get('config')->isFileWritable())
+ if(!Piwik_Config::getInstance()->isFileWritable())
{
$view->configFileNotWritable = true;
}
@@ -277,24 +277,24 @@ class Piwik_UsersManager_Controller extends Piwik_Controller_Admin
$userLogin = Piwik::getCurrentUserLogin();
if(Piwik::isUserIsSuperUser())
{
- $superUser = Zend_Registry::get('config')->superuser;
+ $superUser = Piwik_Config_Writer::getInstance()->superuser;
$updatedSuperUser = false;
if($newPassword !== false)
{
$newPassword = Piwik_Common::unsanitizeInputValue($newPassword);
$md5PasswordSuperUser = md5($newPassword);
- $superUser->password = $md5PasswordSuperUser;
+ $superUser['password'] = $md5PasswordSuperUser;
$updatedSuperUser = true;
}
if($superUser->email != $email)
{
- $superUser->email = $email;
+ $superUser['email'] = $email;
$updatedSuperUser = true;
}
if($updatedSuperUser)
{
- Zend_Registry::get('config')->superuser = $superUser->toArray();
+ Piwik_Config::getInstance()->superuser = $superUser;
}
}
else
diff --git a/plugins/UsersManager/tests/UsersManager.test.php b/plugins/UsersManager/tests/UsersManager.test.php
index 8641c08a79..af3a6e6629 100644
--- a/plugins/UsersManager/tests/UsersManager.test.php
+++ b/plugins/UsersManager/tests/UsersManager.test.php
@@ -8,26 +8,37 @@ require_once PIWIK_PATH_TEST_TO_ROOT . '/tests/core/Database.test.php';
class Test_Piwik_UsersManager extends Test_Database
{
- function setUp()
- {
- parent::setUp();
+ function __construct()
+ {
+ parent::__construct();
+
+ Piwik_Config::getInstance()->setTestEnvironment();
+ Piwik_PluginsManager::getInstance()->unloadPlugins();
+ Piwik_PluginsManager::getInstance()->loadPlugins( array('LanguagesManager') );
+ $plugin = Piwik_PluginsManager::getInstance()->getLoadedPlugin('LanguagesManager');
+ $plugin->install();
+ }
+
+ function setUp()
+ {
+ parent::setUp();
// setup the access layer
- $pseudoMockAccess = new FakeAccess;
+ $pseudoMockAccess = new FakeAccess;
FakeAccess::setIdSitesView( array(1,2));
FakeAccess::setIdSitesAdmin( array(3,4));
//finally we set the user as a super user by default
FakeAccess::$superUser = true;
Zend_Registry::set('access', $pseudoMockAccess);
-
+
// we make sure the tests don't depend on the config file content
- Zend_Registry::get('config')->superuser = array(
+ Piwik_Config::getInstance()->superuser = array(
'login'=>'superusertest',
'password'=>'passwordsuperusertest',
'email'=>'superuser@example.com'
);
- }
+ }
private function _flatten($sitesAccess)
{
@@ -65,7 +76,7 @@ class Test_Piwik_UsersManager extends Test_Database
function test_all_superUserIncluded()
{
- Zend_Registry::get('config')->superuser = array(
+ Piwik_Config::getInstance()->superuser = array(
'login'=>'superusertest',
'password'=>'passwordsuperusertest',
'email'=>'superuser@example.com'
diff --git a/tests/TestRunner.php b/tests/TestRunner.php
index 8ea0a885c1..4671e1aad9 100755
--- a/tests/TestRunner.php
+++ b/tests/TestRunner.php
@@ -20,7 +20,7 @@ class TestRunner
require_once(SIMPLE_TEST . 'reporter.php');
flush();
Piwik::createConfigObject();
- Zend_Registry::get('config')->disableSavingConfigurationFileUpdates();
+ Piwik_Config::getInstance()->setTestEnvironment();
Piwik::setMaxExecutionTime(300);
}
@@ -42,7 +42,7 @@ class TestRunner
public function getTestDatabaseName()
{
- return Zend_Registry::get('config')->database_tests->dbname;
+ return Piwik_Config::getInstance()->database_tests['dbname'];
}
public function requireBrowser()
@@ -131,8 +131,7 @@ class TestRunner
{
try {
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
- Piwik_Tracker_Config::getInstance()->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
Piwik::createDatabaseObject();
Piwik::disconnectDatabase();
return true;
diff --git a/tests/config_test.php b/tests/config_test.php
index ebc7fe1ceb..4a5d411468 100644
--- a/tests/config_test.php
+++ b/tests/config_test.php
@@ -48,8 +48,6 @@ require_once PIWIK_INCLUDE_PATH .'/core/Loader.php';
require_once PIWIK_INCLUDE_PATH .'/libs/Zend/Exception.php';
require_once PIWIK_INCLUDE_PATH .'/core/ErrorHandler.php';
require_once PIWIK_INCLUDE_PATH .'/libs/Zend/Registry.php';
-require_once PIWIK_INCLUDE_PATH .'/libs/Zend/Config/Ini.php';
-require_once PIWIK_INCLUDE_PATH .'/libs/Zend/Config.php';
require_once PIWIK_INCLUDE_PATH .'/libs/Zend/Db.php';
require_once PIWIK_INCLUDE_PATH .'/libs/Zend/Db/Table.php';
require_once PIWIK_INCLUDE_PATH .'/core/FrontController.php';
diff --git a/tests/core/API/DocumentationGenerator.test.php b/tests/core/API/DocumentationGenerator.test.php
index 3f32f03ada..bb449ae870 100644
--- a/tests/core/API/DocumentationGenerator.test.php
+++ b/tests/core/API/DocumentationGenerator.test.php
@@ -20,7 +20,7 @@ class Test_Piwik_API_DocumentationGenerator extends UnitTestCase
function test_callableApiMethods_doNotFail()
{
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
Piwik::createLogObject();
Piwik::createAccessObject();
Piwik::createDatabaseObject();
@@ -28,7 +28,7 @@ class Test_Piwik_API_DocumentationGenerator extends UnitTestCase
Piwik_Translate::getInstance()->loadEnglishTranslation();
$pluginsManager = Piwik_PluginsManager::getInstance();
- $pluginsManager->loadPlugins( Zend_Registry::get('config')->Plugins->Plugins->toArray() );
+ $pluginsManager->loadPlugins( Piwik_Config::getInstance()->Plugins['Plugins'] );
Piwik_SitesManager_API::getInstance()->addSite("name","http://example.org");
diff --git a/tests/core/ArchiveProcessing.test.php b/tests/core/ArchiveProcessing.test.php
index 5ff86a67e0..7e18296395 100644
--- a/tests/core/ArchiveProcessing.test.php
+++ b/tests/core/ArchiveProcessing.test.php
@@ -241,7 +241,7 @@ class Test_Piwik_ArchiveProcessing extends Test_Database
$didWeUseBulk = Piwik::tableInsertBatch($table, array('idsite', 'url'), $data);
if(version_compare(PHP_VERSION, '5.2.9') < 0 ||
version_compare(PHP_VERSION, '5.3.7') >= 0 ||
- Zend_Registry::get('config')->database->adapter != 'PDO_MYSQL')
+ Piwik_Config::getInstance()->database['adapter'] != 'PDO_MYSQL')
{
$this->assertTrue($didWeUseBulk, "The test didn't LOAD DATA INFILE but fallbacked to plain INSERT, but we must unit test this function!");
}
@@ -287,7 +287,7 @@ class Test_Piwik_ArchiveProcessing extends Test_Database
$didWeUseBulk = Piwik::tableInsertBatch($table, array('idarchive', 'name', 'idsite', 'date1', 'date2', 'period', 'ts_archived', 'value'), $data);
if(version_compare(PHP_VERSION, '5.2.9') < 0 ||
version_compare(PHP_VERSION, '5.3.7') >= 0 ||
- Zend_Registry::get('config')->database->adapter != 'PDO_MYSQL')
+ Piwik_Config::getInstance()->database['adapter'] != 'PDO_MYSQL')
{
$this->assertTrue($didWeUseBulk, "The test didn't LOAD DATA INFILE but fallbacked to plain INSERT, but we must unit test this function!");
}
diff --git a/tests/core/Config.test.php b/tests/core/Config.test.php
index 3dfa40de23..2f19ea6659 100644
--- a/tests/core/Config.test.php
+++ b/tests/core/Config.test.php
@@ -6,49 +6,79 @@ if(!defined('PIWIK_CONFIG_TEST_INCLUDED'))
class Test_Piwik_Config extends UnitTestCase
{
- public function testUserConfigOverwritesSectionGlobalConfigValue()
- {
- $userFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/config.ini.php';
- $globalFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/global.ini.php';
-
- $config = new Piwik_Config($userFile, $globalFile);
- $config->init();
- $this->assertEqual($config->Category->key1, "value_overwritten");
- $this->assertEqual($config->Category->key2, "value2");
- $this->assertEqual($config->GeneralSection->login, 'tes"t');
- $this->assertEqual($config->CategoryOnlyInGlobalFile->key3, "value3");
- $this->assertEqual($config->CategoryOnlyInGlobalFile->key4, "value4");
-
- $expectedArray = array('plugin"1', 'plugin2', 'plugin3');
- $array = $config->TestArray->toArray();
- $this->assertEqual($array['installed'], $expectedArray);
-
- $expectedArray = array('value1', 'value2');
- $array = $config->TestArrayOnlyInGlobalFile->toArray();
- $this->assertEqual($array['my_array'], $expectedArray);
- }
-
- public function testWritingConfigWithSpecialCharacters()
- {
- $userFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/config.written.ini.php';
- $globalFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/global.ini.php';
-
- $config = new Piwik_Config($userFile, $globalFile);
- $config->init();
- $stringWritten = '&6^ geagea\'\'\'";;&';
- $config->Category = array('test' => $stringWritten);
- $this->assertEqual($config->Category->test, $stringWritten);
- unset($config);
-
- $config = new Piwik_Config($userFile, $globalFile);
- $config->init();
- $this->assertEqual($config->Category->test, $stringWritten);
- $config->Category = array(
- 'test' => $config->Category->test,
- 'test2' => $stringWritten);
- $this->assertEqual($config->Category->test, $stringWritten);
- $this->assertEqual($config->Category->test2, $stringWritten);
- }
-
-}
+ public function testUserConfigOverwritesSectionGlobalConfigValue()
+ {
+ $userFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/config.ini.php';
+ $globalFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/global.ini.php';
+
+ $config = Piwik_Config::getInstance();
+ $config->setTestEnvironment($userFile, $globalFile);
+ $config->init();
+
+ $this->assertEqual($config->Category['key1'], "value_overwritten");
+ $this->assertEqual($config->Category['key2'], "value2");
+ $this->assertEqual($config->GeneralSection['login'], 'tes"t');
+ $this->assertEqual($config->CategoryOnlyInGlobalFile['key3'], "value3");
+ $this->assertEqual($config->CategoryOnlyInGlobalFile['key4'], "value4");
+
+ $expectedArray = array('plugin"1', 'plugin2', 'plugin3');
+ $array = $config->TestArray;
+ $this->assertEqual($array['installed'], $expectedArray);
+
+ $expectedArray = array('value1', 'value2');
+ $array = $config->TestArrayOnlyInGlobalFile;
+ $this->assertEqual($array['my_array'], $expectedArray);
+ }
+
+ public function testWritingConfigWithSpecialCharacters()
+ {
+ $userFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/config.written.ini.php';
+ $globalFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/global.ini.php';
+
+ $config = Piwik_Config::getInstance();
+ $config->setTestEnvironment($userFile, $globalFile);
+ $config->init();
+
+ $stringWritten = '&6^ geagea\'\'\'";;&';
+ $config->Category = array('test' => $stringWritten);
+ $this->assertEqual($config->Category['test'], $stringWritten);
+ unset($config);
+ $config = Piwik_Config::getInstance();
+ $config->setTestEnvironment($userFile, $globalFile);
+ $config->init();
+
+ $this->assertEqual($config->Category['test'], $stringWritten);
+ $config->Category = array(
+ 'test' => $config->Category['test'],
+ 'test2' => $stringWritten,
+ );
+ $this->assertEqual($config->Category['test'], $stringWritten);
+ $this->assertEqual($config->Category['test2'], $stringWritten);
+ }
+
+ public function test_UserConfigOverwritesGlobalConfig()
+ {
+ $userFile = PIWIK_PATH_TEST_TO_ROOT . '/tests/resources/Config/config.ini.php';
+ $globalFile = PIWIK_PATH_TEST_TO_ROOT . '/tests/resources/Config/global.ini.php';
+
+ $config = Piwik_Config::getInstance();
+ $config->setTestEnvironment($userFile, $globalFile);
+
+ $this->assertEqual($config->Category['key1'], "value_overwritten");
+ $this->assertEqual($config->Category['key2'], "value2");
+ $this->assertEqual($config->GeneralSection['login'], "tes\"t");
+ $this->assertEqual($config->CategoryOnlyInGlobalFile['key3'], "value3");
+ $this->assertEqual($config->CategoryOnlyInGlobalFile['key4'], "value4");
+
+ $expectedArray = array('plugin"1', 'plugin2', 'plugin3');
+ $array = $config->TestArray;
+ $this->assertEqual($array['installed'], $expectedArray);
+
+ $expectedArray = array('value1', 'value2');
+ $array = $config->TestArrayOnlyInGlobalFile;
+ $this->assertEqual($array['my_array'], $expectedArray);
+
+ Piwik_Config::getInstance()->clear();
+ }
+}
diff --git a/tests/core/Config/Writer.test.php b/tests/core/Config/Writer.test.php
new file mode 100644
index 0000000000..d7efecf19d
--- /dev/null
+++ b/tests/core/Config/Writer.test.php
@@ -0,0 +1,107 @@
+<?php
+if(!defined('PIWIK_CONFIG_TEST_INCLUDED'))
+{
+ require_once dirname(__FILE__)."/../../../tests/config_test.php";
+}
+
+class Test_Piwik_Config_Writer extends UnitTestCase
+{
+ public function test_getInstance()
+ {
+ $this->assertEqual(get_class(Piwik_Config_Writer::getInstance()), 'Piwik_Config_Writer');
+ }
+
+ public function test_compareElements()
+ {
+ $tests = array(
+ 'string = string' => array(
+ 'a', 'a', 0,
+ ),
+ 'string > string' => array(
+ 'b', 'a', 1,
+ ),
+ 'string < string' => array(
+ 'a', 'b', -1,
+ ),
+ 'string vs array' => array(
+ 'a', array('a'), -1,
+ ),
+ 'array vs string' => array(
+ array('a'), 'a', 1,
+ ),
+ 'array = array' => array(
+ array('a'), array('a'), 0,
+ ),
+ 'array > array' => array(
+ array('b'), array('a'), 1,
+ ),
+ 'array < array' => array(
+ array('a'), array('b'), -1,
+ ),
+ );
+
+ foreach ($tests as $description => $test)
+ {
+ list($a, $b, $expected) = $test;
+
+ $result = Piwik_Config_Writer::compareElements($a, $b);
+ $this->assertEqual($result, $expected, $description);
+ }
+ }
+
+ public function test_array_unmerge()
+ {
+ $tests = array(
+ 'description of test' => array(
+ array(),
+ array(),
+ ),
+ 'override with empty' => array(
+ array('login' => 'root', 'password' => 'b33r'),
+ array('password' => ''),
+ ),
+ 'override with non-empty' => array(
+ array('login' => 'root', 'password' => ''),
+ array('password' => 'b33r'),
+ ),
+ 'add element' => array(
+ array('login' => 'root', 'password' => ''),
+ array('auth' => 'Login'),
+ ),
+ 'override with empty array' => array(
+ array('headers' => ''),
+ array('headers' => array()),
+ ),
+ 'override with array' => array(
+ array('headers' => ''),
+ array('headers' => array('Content-Length', 'Content-Type')),
+ ),
+ 'override an array' => array(
+ array('headers' => array()),
+ array('headers' => array('Content-Length', 'Content-Type')),
+ ),
+ 'override similar arrays' => array(
+ array('headers' => array('Content-Length', 'Set-Cookie')),
+ array('headers' => array('Content-Length', 'Content-Type')),
+ ),
+ 'override dyslexic arrays' => array(
+ array('headers' => array('Content-Type', 'Content-Length')),
+ array('headers' => array('Content-Length', 'Content-Type')),
+ ),
+ );
+
+ $configWriter = Piwik_Config_Writer::getInstance();
+
+ foreach ($tests as $description => $test)
+ {
+ list($a, $b) = $test;
+
+ $combined = array_merge($a, $b);
+
+ $diff = $configWriter->array_unmerge($a, $combined);
+
+ // expect $b == $diff
+ $this->assertEqual(serialize($b), serialize($diff), $description);
+ }
+ }
+}
diff --git a/tests/core/DataTable/Array.test.php b/tests/core/DataTable/Array.test.php
index cd918bea94..4f2e0f0bec 100755
--- a/tests/core/DataTable/Array.test.php
+++ b/tests/core/DataTable/Array.test.php
@@ -13,7 +13,7 @@ class Test_Piwik_DataTable_Array extends UnitTestCase
{
parent::setUp();
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
Piwik_DataTable_Manager::getInstance()->deleteAll();
}
diff --git a/tests/core/DataTable/Renderer.test.php b/tests/core/DataTable/Renderer.test.php
index 7431e739c1..ab2382259e 100644
--- a/tests/core/DataTable/Renderer.test.php
+++ b/tests/core/DataTable/Renderer.test.php
@@ -18,7 +18,7 @@ class Test_Piwik_DataTable_Renderer extends UnitTestCase
{
parent::setUp();
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
Piwik_DataTable_Manager::getInstance()->deleteAll();
}
diff --git a/tests/core/Database.test.php b/tests/core/Database.test.php
index 59000177da..6b7bb677cb 100644
--- a/tests/core/Database.test.php
+++ b/tests/core/Database.test.php
@@ -21,8 +21,7 @@ abstract class Test_Database_Base extends UnitTestCase
parent::__construct( $title );
try {
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
- Piwik_Tracker_Config::getInstance()->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
Piwik::createDatabaseObject();
Piwik::createLogObject();
diff --git a/tests/core/Http.test.php b/tests/core/Http.test.php
index 325f4d279c..b5a2ad5581 100644
--- a/tests/core/Http.test.php
+++ b/tests/core/Http.test.php
@@ -9,7 +9,7 @@ class Test_Piwik_Http extends UnitTestCase
public function test_fetchRemoteFile()
{
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
$methods = array(
'curl',
diff --git a/tests/core/IP.test.php b/tests/core/IP.test.php
index dd8c656941..72599ea3a9 100644
--- a/tests/core/IP.test.php
+++ b/tests/core/IP.test.php
@@ -531,7 +531,7 @@ class Test_Piwik_IP extends UnitTestCase
function test_getIpFromHeader()
{
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
$saved = $this->saveGlobals(array('REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR'));
$tests = array(
@@ -549,8 +549,8 @@ class Test_Piwik_IP extends UnitTestCase
{
$_SERVER['REMOTE_ADDR'] = $test[0];
$_SERVER['HTTP_X_FORWARDED_FOR'] = $test[1];
- Zend_Registry::get('config')->General->proxy_client_headers = array($test[2]);
- Zend_Registry::get('config')->General->proxy_ips = array($test[3]);
+ Piwik_Config::getInstance()->General['proxy_client_headers'] = array($test[2]);
+ Piwik_Config::getInstance()->General['proxy_ips'] = array($test[3]);
$this->assertEqual( Piwik_IP::getIpFromHeader(), $test[4], $description );
}
@@ -560,7 +560,7 @@ class Test_Piwik_IP extends UnitTestCase
function test_getNonProxyIpFromHeader()
{
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
$saved = $this->saveGlobals(array('REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR'));
$ips = array(
diff --git a/tests/core/Nonce.test.php b/tests/core/Nonce.test.php
index 67391598e5..c701d0ea78 100644
--- a/tests/core/Nonce.test.php
+++ b/tests/core/Nonce.test.php
@@ -23,7 +23,7 @@ class Test_Piwik_Nonce extends UnitTestCase
public function test_getAcceptableOrigins()
{
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
$tests = array(
// HTTP_HOST => expected
diff --git a/tests/core/PHP_Related.test.php b/tests/core/PHP_Related.test.php
index 42351a8a07..46a2f3969f 100644
--- a/tests/core/PHP_Related.test.php
+++ b/tests/core/PHP_Related.test.php
@@ -78,7 +78,7 @@ class Test_PHP_Related extends UnitTestCase
{
ini_set('memory_limit','200M');
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
Piwik::createLogObject();
//test array[0] array[1] array[2]
//VS
diff --git a/tests/core/Piwik.test.php b/tests/core/Piwik.test.php
index 95d5a2b355..860d676bdf 100644
--- a/tests/core/Piwik.test.php
+++ b/tests/core/Piwik.test.php
@@ -69,7 +69,7 @@ class Test_Piwik extends UnitTestCase
public function test_checkValidLoginString()
{
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
$fail = array(
'',
diff --git a/tests/core/ReleaseCheckList.test.php b/tests/core/ReleaseCheckList.test.php
index 2171479614..9e24c391be 100644
--- a/tests/core/ReleaseCheckList.test.php
+++ b/tests/core/ReleaseCheckList.test.php
@@ -93,20 +93,20 @@ class Test_Piwik_ReleaseCheckList extends UnitTestCase
function test_ajaxLibraryVersions()
{
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
$jqueryJs = file_get_contents( PIWIK_DOCUMENT_ROOT . '/libs/jquery/jquery.js', false, NULL, 0, 512 );
$this->assertTrue( preg_match('/jQuery (?:JavaScript Library )?v?([0-9.]+)/', $jqueryJs, $matches) );
- $this->assertEqual( $matches[1], Zend_Registry::get('config')->General->jquery_version );
+ $this->assertEqual( $matches[1], Piwik_Config::getInstance()->General['jquery_version'] );
$jqueryuiJs = file_get_contents( PIWIK_DOCUMENT_ROOT . '/libs/jquery/jquery-ui.js', false, NULL, 0, 512 );
$this->assertTrue( preg_match('/jQuery UI ([0-9.]+)/', $jqueryuiJs, $matches) );
- $this->assertEqual( $matches[1], Zend_Registry::get('config')->General->jqueryui_version );
+ $this->assertEqual( $matches[1], Piwik_Config::getInstance()->General['jqueryui_version'] );
$swfobjectJs = file_get_contents( PIWIK_DOCUMENT_ROOT . '/libs/swfobject/swfobject.js', false, NULL, 0, 512 );
$this->assertTrue( preg_match('/SWFObject v([0-9.]+)/', $swfobjectJs, $matches) );
- $this->assertEqual( $matches[1], Zend_Registry::get('config')->General->swfobject_version );
+ $this->assertEqual( $matches[1], Piwik_Config::getInstance()->General['swfobject_version'] );
}
function test_svnEolStyle()
diff --git a/tests/core/Segment.test.php b/tests/core/Segment.test.php
index 498e40be53..4825cd4756 100644
--- a/tests/core/Segment.test.php
+++ b/tests/core/Segment.test.php
@@ -11,7 +11,7 @@ class Test_Piwik_Segment extends UnitTestCase
{
parent::setUp();
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
// setup the access layer (required in Segment contrustor testing if anonymous is allowed to use segments)
$pseudoMockAccess = new FakeAccess;
@@ -20,7 +20,7 @@ class Test_Piwik_Segment extends UnitTestCase
// Load and install plugins
$pluginsManager = Piwik_PluginsManager::getInstance();
- $pluginsManager->loadPlugins( Zend_Registry::get('config')->Plugins->Plugins->toArray() );
+ $pluginsManager->loadPlugins( Piwik_Config::getInstance()->Plugins['Plugins'] );
}
public function test_common()
diff --git a/tests/core/TablePartitioning.test.php b/tests/core/TablePartitioning.test.php
index 646253f12e..84e403976f 100644
--- a/tests/core/TablePartitioning.test.php
+++ b/tests/core/TablePartitioning.test.php
@@ -35,8 +35,8 @@ class Test_Piwik_TablePartitioning extends Test_Database
$p = new Piwik_TablePartitioning_Monthly($tableName);
$timestamp = strtotime("10 September 2000");
$suffixShouldBe = "_2000_09";
- $config = Zend_Registry::get('config');
- $prefixTables = $config->database->tables_prefix;
+ $config = Piwik_Config::getInstance();
+ $prefixTables = $config->database['tables_prefix'];
$tablename = $prefixTables.$tableName.$suffixShouldBe;
$p->setTimestamp( $timestamp );
@@ -56,8 +56,8 @@ class Test_Piwik_TablePartitioning extends Test_Database
$p = new Piwik_TablePartitioning_Monthly($tableName);
$timestamp = strtotime("10 September 2000");
$suffixShouldBe = "_2000_09";
- $config = Zend_Registry::get('config');
- $prefixTables = $config->database->tables_prefix;
+ $config = Piwik_Config::getInstance();
+ $prefixTables = $config->database['tables_prefix'];
$tablename = $prefixTables.$tableName.$suffixShouldBe;
$p->setTimestamp( $timestamp );
@@ -76,8 +76,8 @@ class Test_Piwik_TablePartitioning extends Test_Database
$p = new Piwik_TablePartitioning_Daily($tableName);
$timestamp = strtotime("10 September 2000");
$suffixShouldBe = "_2000_09_10";
- $config = Zend_Registry::get('config');
- $prefixTables = $config->database->tables_prefix;
+ $config = Piwik_Config::getInstance();
+ $prefixTables = $config->database['tables_prefix'];
$tablename = $prefixTables.$tableName.$suffixShouldBe;
$p->setTimestamp( $timestamp );
diff --git a/tests/core/Tracker/Action.test.php b/tests/core/Tracker/Action.test.php
index 08134aff70..4a45157e7f 100644
--- a/tests/core/Tracker/Action.test.php
+++ b/tests/core/Tracker/Action.test.php
@@ -5,7 +5,6 @@ if(!defined('PIWIK_CONFIG_TEST_INCLUDED'))
}
require_once 'Tracker/Action.php';
-require_once 'Tracker/Config.php';
require_once "Database.test.php";
class Test_Piwik_TrackerAction extends Test_Database
@@ -15,16 +14,14 @@ class Test_Piwik_TrackerAction extends Test_Database
parent::setUp();
$GLOBALS['PIWIK_TRACKER_MODE'] = true;
$userFile = PIWIK_PATH_TEST_TO_ROOT . '/tests/resources/Tracker/Action.config.ini.php';
- $config = Piwik_Tracker_Config::getInstance();
- $config->init($userFile);
- $config->setTestEnvironment();
+ $config = Piwik_Config::getInstance();
+ $config->setTestEnvironment($userFile);
}
function tearDown()
{
parent::tearDown();
$GLOBALS['PIWIK_TRACKER_MODE'] = false;
- Piwik_Tracker_Config::getInstance()->clear();
}
protected function setUpRootAccess()
diff --git a/tests/core/Tracker/Config.test.php b/tests/core/Tracker/Config.test.php
deleted file mode 100644
index 31a50c7283..0000000000
--- a/tests/core/Tracker/Config.test.php
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-if(!defined('PIWIK_CONFIG_TEST_INCLUDED'))
-{
- require_once dirname(__FILE__)."/../../../tests/config_test.php";
-}
-
-require_once 'Tracker/Config.php';
-
-class Test_Piwik_TrackerConfig extends UnitTestCase
-{
- public function test_UserConfigOverwritesGlobalConfig()
- {
- $userFile = PIWIK_PATH_TEST_TO_ROOT . '/tests/resources/Config/config.ini.php';
- $globalFile = PIWIK_PATH_TEST_TO_ROOT . '/tests/resources/Config/global.ini.php';
-
- Piwik_Tracker_Config::getInstance()->setTestEnvironment();
- $config = Piwik_Tracker_Config::getInstance();
- $config->init($userFile, $globalFile);
-
- $this->assertEqual($config->Category['key1'], "value_overwritten");
- $this->assertEqual($config->Category['key2'], "value2");
- $this->assertEqual($config->GeneralSection['login'], "tes\"t");
- $this->assertEqual($config->CategoryOnlyInGlobalFile['key3'], "value3");
- $this->assertEqual($config->CategoryOnlyInGlobalFile['key4'], "value4");
-
- $expectedArray = array('plugin"1', 'plugin2', 'plugin3');
- $array = $config->TestArray;
- $this->assertEqual($array['installed'], $expectedArray);
-
- $expectedArray = array('value1', 'value2');
- $array = $config->TestArrayOnlyInGlobalFile;
- $this->assertEqual($array['my_array'], $expectedArray);
-
- Piwik_Tracker_Config::getInstance()->clear();
- }
-}
-
diff --git a/tests/core/Url.test.php b/tests/core/Url.test.php
index 109c351ca5..bc9aae3393 100644
--- a/tests/core/Url.test.php
+++ b/tests/core/Url.test.php
@@ -14,7 +14,7 @@ class Test_Piwik_Url extends UnitTestCase
public function test_allMethods()
{
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
$this->assertEqual(Piwik_Url::getCurrentQueryStringWithParametersModified(array()),Piwik_Url::getCurrentQueryString() );
$this->assertEqual(Piwik_Url::getCurrentUrl(), Piwik_Url::getCurrentUrlWithoutQueryString());
@@ -80,7 +80,7 @@ class Test_Piwik_Url extends UnitTestCase
{
$GLOBALS['PIWIK_TRACKER_MODE'] = false;
Piwik::createConfigObject();
- Zend_Registry::get('config')->setTestEnvironment();
+ Piwik_Config::getInstance()->setTestEnvironment();
$saved = $this->saveGlobals(array('HTTP_HOST', 'HTTP_X_FORWARDED_HOST'));
$tests = array(
@@ -107,8 +107,8 @@ class Test_Piwik_Url extends UnitTestCase
{
$_SERVER['HTTP_HOST'] = $test[0];
$_SERVER['HTTP_X_FORWARDED_HOST'] = $test[1];
- Zend_Registry::get('config')->General->proxy_host_headers = array( $test[2] );
- Zend_Registry::get('config')->General->proxy_ips = array( $test[3] );
+ Piwik_Config::getInstance()->General['proxy_host_headers'] = array( $test[2] );
+ Piwik_Config::getInstance()->General['proxy_ips'] = array( $test[3] );
$this->assertEqual( Piwik_Url::getCurrentHost(), $test[4], $description );
}
diff --git a/tests/integration/Integration.php b/tests/integration/Integration.php
index b191eaf847..3c2db866a4 100644
--- a/tests/integration/Integration.php
+++ b/tests/integration/Integration.php
@@ -11,15 +11,15 @@ Mock::generate('Piwik_Auth');
/**
* Base class for Integration tests. Runs integration / acceptance tests
- *
- * The tests call the Piwik tracker with known sets of data, expected errors,
- * and can _test the output of the tracker beacon, as well as calling
+ *
+ * The tests call the Piwik tracker with known sets of data, expected errors,
+ * and can _test the output of the tracker beacon, as well as calling
* all API functions and compare their XML output with the 'expected output'.
- *
- * If an algorithm changes in the Tracker or in the Archiving, tests can easily be run to check that
- * the output changes as expected (eg. More accurate browser detection, adding a new metric in the
+ *
+ * If an algorithm changes in the Tracker or in the Archiving, tests can easily be run to check that
+ * the output changes as expected (eg. More accurate browser detection, adding a new metric in the
* API results, etc.
- *
+ *
* @see Ideas for improvements http://dev.piwik.org/trac/ticket/1465
*/
abstract class Test_Integration extends Test_Database_Base
@@ -43,14 +43,14 @@ abstract class Test_Integration extends Test_Database_Base
* set to this, controller actions will not be tested.
*/
const NO_WIDGET_TESTING = 'none';
-
+
/**
* Widget testing level constant. If Test_Integration::$widgetTestingLevel is
* set to this, controller actions will be checked for non-fatal errors, but
* the output will be ignored.
*/
const CHECK_WIDGET_ERRORS = 'check_errors';
-
+
/**
* Widget testing level constant. If Test_Integration::$widgetTestingLevel is
* set to this, controller actions will be run & their output will be checked with
@@ -68,7 +68,7 @@ abstract class Test_Integration extends Test_Database_Base
* set to this, API methods will not be tested.
*/
const NO_API_TESTING = 'none';
-
+
/**
* API testing level constant. If Test_Integration::$apiTestingLevel is
* set to this, API methods will be run & their output will be checked with
@@ -89,60 +89,60 @@ abstract class Test_Integration extends Test_Database_Base
* Load english translations to ensure API response have english text
* @see tests/core/Test_Database#setUp()
*/
- function setUp()
+ function setUp()
{
parent::setUp();
$_GET = $_REQUEST = array();
$_SERVER['HTTP_REFERER'] = '';
- // Make sure translations are loaded to check messages in English
- Piwik_Translate::getInstance()->loadEnglishTranslation();
-
- // List of Modules, or Module.Method that should not be called as part of the XML output compare
- // Usually these modules either return random changing data, or are already tested in specific unit tests.
+ // Make sure translations are loaded to check messages in English
+ Piwik_Translate::getInstance()->loadEnglishTranslation();
+
+ // List of Modules, or Module.Method that should not be called as part of the XML output compare
+ // Usually these modules either return random changing data, or are already tested in specific unit tests.
$this->setApiNotToCall(self::$defaultApiNotToCall);
$this->setApiToCall( array());
if (self::$widgetTestingLevel != self::NO_WIDGET_TESTING)
{
Piwik::setUserIsSuperUser();
-
+
// create users for controller testing
$usersApi = Piwik_UsersManager_API::getInstance();
$usersApi->addUser('anonymous', self::DEFAULT_USER_PASSWORD, 'anonymous@anonymous.com');
$usersApi->addUser('test_view', self::DEFAULT_USER_PASSWORD, 'view@view.com');
$usersApi->addUser('test_admin', self::DEFAULT_USER_PASSWORD, 'admin@admin.com');
-
+
// disable shuffling of tag cloud visualization so output is consistent
Piwik_Visualization_Cloud::$debugDisableShuffle = true;
}
}
-
- function tearDown()
+
+ function tearDown()
{
parent::tearDown();
$_GET = $_REQUEST = array();
- Piwik_Translate::getInstance()->unloadEnglishTranslation();
-
- // re-enable tag cloud shuffling
- Piwik_Visualization_Cloud::$debugDisableShuffle = true;
+ Piwik_Translate::getInstance()->unloadEnglishTranslation();
+
+ // re-enable tag cloud shuffling
+ Piwik_Visualization_Cloud::$debugDisableShuffle = true;
}
-
+
protected $apiToCall = array();
protected $apiNotToCall = array();
-
+
/**
- * Forces the test to only call and fetch XML for the specified plugins,
+ * Forces the test to only call and fetch XML for the specified plugins,
* or exact API methods.
- *
+ *
* If not called, all default tests will be executed.
- *
+ *
* @param $apiToCall array( 'ExampleAPI', 'Plugin.getData' )
* @return void
*/
protected function setApiToCall( $apiToCall )
{
- if(func_num_args() != 1)
+ if(func_num_args() != 1)
{
throw new Exception('setApiToCall expects an array');
}
@@ -152,7 +152,7 @@ abstract class Test_Integration extends Test_Database_Base
}
$this->apiToCall = $apiToCall;
}
-
+
/**
* Sets a list of API methods to not call during the test
* @param $apiNotToCall eg. 'ExampleAPI.getPiwikVersion'
@@ -166,11 +166,10 @@ abstract class Test_Integration extends Test_Database_Base
}
$this->apiNotToCall = $apiNotToCall;
}
-
-
+
/**
* Returns a PiwikTracker object that you can then use to track pages or goals.
- *
+ *
* @param $idSite
* @param $dateTime
* @param $defaultInit If set to true, the tracker object will have default IP, user agent, time, resolution, etc.
@@ -178,50 +177,50 @@ abstract class Test_Integration extends Test_Database_Base
*/
protected function getTracker($idSite, $dateTime, $defaultInit = true )
{
- $t = new PiwikTracker( $idSite, $this->getTrackerUrl());
- $t->setForceVisitDateTime($dateTime);
-
- if($defaultInit)
- {
- $t->setIp('156.5.3.2');
-
- // Optional tracking
- $t->setUserAgent( "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)");
- $t->setBrowserLanguage('fr');
- $t->setLocalTime( '12:34:06' );
- $t->setResolution( 1024, 768 );
- $t->setBrowserHasCookies(true);
- $t->setPlugins($flash = true, $java = true, $director = false);
- }
- return $t;
+ $t = new PiwikTracker( $idSite, $this->getTrackerUrl());
+ $t->setForceVisitDateTime($dateTime);
+
+ if($defaultInit)
+ {
+ $t->setIp('156.5.3.2');
+
+ // Optional tracking
+ $t->setUserAgent( "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)");
+ $t->setBrowserLanguage('fr');
+ $t->setLocalTime( '12:34:06' );
+ $t->setResolution( 1024, 768 );
+ $t->setBrowserHasCookies(true);
+ $t->setPlugins($flash = true, $java = true, $director = false);
+ }
+ return $t;
}
-
+
/**
* Creates a website, then sets its creation date to a day earlier than specified dateTime
* Useful to create a website now, but force data to be archived back in the past.
- *
+ *
* @param $dateTime eg '2010-01-01 12:34:56'
* @return $idSite of website created
*/
protected function createWebsite( $dateTime, $ecommerce = 0, $siteName = 'Piwik test' )
{
- $idSite = Piwik_SitesManager_API::getInstance()->addSite(
- $siteName,
- "http://piwik.net/",
- $ecommerce,
- $ips = null,
- $excludedQueryParameters = null,
- $timezone = null,
- $currency = null
- );
-
- // Manually set the website creation date to a day earlier than the earliest day we record stats for
- Zend_Registry::get('db')->update(Piwik_Common::prefixTable("site"),
- array('ts_created' => Piwik_Date::factory($dateTime)->subDay(1)->getDatetime()),
- "idsite = $idSite"
- );
-
- // Clear the memory Website cache
+ $idSite = Piwik_SitesManager_API::getInstance()->addSite(
+ $siteName,
+ "http://piwik.net/",
+ $ecommerce,
+ $ips = null,
+ $excludedQueryParameters = null,
+ $timezone = null,
+ $currency = null
+ );
+
+ // Manually set the website creation date to a day earlier than the earliest day we record stats for
+ Zend_Registry::get('db')->update(Piwik_Common::prefixTable("site"),
+ array('ts_created' => Piwik_Date::factory($dateTime)->subDay(1)->getDatetime()),
+ "idsite = $idSite"
+ );
+
+ // Clear the memory Website cache
Piwik_Site::clearCache();
// add access to all test users if doing controller tests
@@ -235,28 +234,28 @@ abstract class Test_Integration extends Test_Database_Base
return $idSite;
}
-
+
/**
* Checks that the response is a GIF image as expected.
* @return Will fail the test if the response is not the expected GIF
*/
protected function checkResponse($response)
{
- $trans_gif_64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
- $expectedResponse = base64_decode($trans_gif_64);
+ $trans_gif_64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
+ $expectedResponse = base64_decode($trans_gif_64);
$this->assertEqual($expectedResponse, $response, "");
- if($response == $expectedResponse)
+ if($response == $expectedResponse)
{
$this->pass();
return;
}
echo "Expected GIF beacon, got: <br/>\n" . $response ."<br/>\n";
}
-
+
/**
- * Returns URL to the proxy script, used to ensure piwik.php
+ * Returns URL to the proxy script, used to ensure piwik.php
* uses the test environment, and allows variable overwriting
- *
+ *
* @return string
*/
protected function getTrackerUrl()
@@ -269,10 +268,10 @@ abstract class Test_Integration extends Test_Database_Base
{
$pathBeforeRoot = 'plugins';
}
- $piwikUrl = substr($piwikUrl, 0, strpos($piwikUrl, $pathBeforeRoot.'/')) . 'tests/integration/proxy-piwik.php';
+ $piwikUrl = substr($piwikUrl, 0, strpos($piwikUrl, $pathBeforeRoot.'/')) . 'tests/integration/proxy-piwik.php';
return $piwikUrl;
}
-
+
/**
* Initializes the test
* @param $title
@@ -287,16 +286,16 @@ abstract class Test_Integration extends Test_Database_Base
self::initializeControllerTesting();
}
- Piwik::createAccessObject();
- Piwik_PostEvent('FrontController.initAuthenticationObject');
-
- // We need to be SU to create websites for tests
- Piwik::setUserIsSuperUser();
+ Piwik::createAccessObject();
+ Piwik_PostEvent('FrontController.initAuthenticationObject');
+
+ // We need to be SU to create websites for tests
+ Piwik::setUserIsSuperUser();
- // Load and install plugins
- $pluginsManager = Piwik_PluginsManager::getInstance();
- $pluginsManager->loadPlugins( Zend_Registry::get('config')->Plugins->Plugins->toArray() );
- $pluginsManager->installLoadedPlugins();
+ // Load and install plugins
+ $pluginsManager = Piwik_PluginsManager::getInstance();
+ $pluginsManager->loadPlugins( Piwik_Config::getInstance()->Plugins['Plugins'] );
+ $pluginsManager->installLoadedPlugins();
}
/**
@@ -311,7 +310,7 @@ abstract class Test_Integration extends Test_Database_Base
Zend_Registry::set('timer', new Piwik_Timer);
$pluginsManager = Piwik_PluginsManager::getInstance();
- $pluginsToLoad = Zend_Registry::get('config')->Plugins->Plugins->toArray();
+ $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins'];
$pluginsManager->loadPlugins( $pluginsToLoad );
$initialized = true;
@@ -336,7 +335,7 @@ abstract class Test_Integration extends Test_Database_Base
public static function setWidgetTestingLevel($level)
{
if (!$level) return;
-
+
if ($level != Test_Integration::NO_WIDGET_TESTING &&
$level != Test_Integration::CHECK_WIDGET_ERRORS &&
$level != Test_Integration::COMPARE_WIDGET_OUTPUT)
@@ -347,7 +346,7 @@ abstract class Test_Integration extends Test_Database_Base
self::$widgetTestingLevel = $level;
}
-
+
public function setApiTestingLevel($level)
{
if (!$level) return;
@@ -358,22 +357,22 @@ abstract class Test_Integration extends Test_Database_Base
echo "<p>Invalid option for 'apiTestingLevel', ignoring.</p>";
return;
}
-
+
self::$apiTestingLevel = $level;
}
-
+
/**
* Given a list of default parameters to set, returns the URLs of APIs to call
* If any API was specified in setApiToCall() we ensure only these are tested.
* If any API is set as excluded (see list below) then it will be ignored.
- *
- * @param $parametersToSet
+ *
+ * @param $parametersToSet
* @param $formats Array of 'format' to fetch from API
* @param $periods Array of 'period' to query API
* @param $setDateLastN If set to true, the 'date' parameter will be rewritten to query instead a range of dates, rather than one period only.
* @param $language 2 letter language code, defaults to default piwik language
* @return array of API URLs query strings
- */
+ */
protected function generateUrlsApi( $parametersToSet, $formats, $periods, $setDateLastN = false, $language = false, $segment = false )
{
// Get the URLs to query against the API for all functions starting with get*
@@ -381,98 +380,98 @@ abstract class Test_Integration extends Test_Database_Base
$apiMetadata = new Piwik_API_DocumentationGenerator;
foreach(Piwik_API_Proxy::getInstance()->getMetadata() as $class => $info)
{
- $moduleName = Piwik_API_Proxy::getInstance()->getModuleNameFromClassName($class);
- foreach($info as $methodName => $infoMethod)
- {
- $apiId = $moduleName.'.'.$methodName;
-
- // If Api to test were set, we only test these
- if(!empty($this->apiToCall)
- && in_array($moduleName, $this->apiToCall) === false
- && in_array($apiId, $this->apiToCall) === false)
- {
- $skipped[] = $apiId;
- continue;
- }
- // Excluded modules from test
- elseif(
- (strpos($methodName, 'get') !== 0
- || in_array($moduleName, $this->apiNotToCall) === true
- || in_array($apiId, $this->apiNotToCall) === true
- || $methodName == 'getLogoUrl'
- || $methodName == 'getHeaderLogoUrl'
- )
- )
- {
- $skipped[] = $apiId;
- continue;
- }
-
- foreach($periods as $period)
- {
- $parametersToSet['period'] = $period;
-
+ $moduleName = Piwik_API_Proxy::getInstance()->getModuleNameFromClassName($class);
+ foreach($info as $methodName => $infoMethod)
+ {
+ $apiId = $moduleName.'.'.$methodName;
+
+ // If Api to test were set, we only test these
+ if(!empty($this->apiToCall)
+ && in_array($moduleName, $this->apiToCall) === false
+ && in_array($apiId, $this->apiToCall) === false)
+ {
+ $skipped[] = $apiId;
+ continue;
+ }
+ // Excluded modules from test
+ elseif(
+ (strpos($methodName, 'get') !== 0
+ || in_array($moduleName, $this->apiNotToCall) === true
+ || in_array($apiId, $this->apiNotToCall) === true
+ || $methodName == 'getLogoUrl'
+ || $methodName == 'getHeaderLogoUrl'
+ )
+ )
+ {
+ $skipped[] = $apiId;
+ continue;
+ }
+
+ foreach($periods as $period)
+ {
+ $parametersToSet['period'] = $period;
+
// If date must be a date range, we process this date range by adding 6 periods to it
- if($setDateLastN === true)
- {
- if(!isset($parametersToSet['dateRewriteBackup']))
- {
- $parametersToSet['dateRewriteBackup'] = $parametersToSet['date'];
- }
- $lastCount = 6;
- $firstDate = $parametersToSet['dateRewriteBackup'];
- $secondDate = date('Y-m-d', strtotime("+$lastCount " . $period . "s", strtotime($firstDate)));
- $parametersToSet['date'] = $firstDate . ',' . $secondDate;
- }
-
- // Set response language
- if($language !== false)
- {
- $parametersToSet['language'] = $language;
- }
- // Generate for each specified format
- foreach($formats as $format)
- {
- $parametersToSet['format'] = $format;
- $parametersToSet['hideIdSubDatable'] = 1;
- $parametersToSet['serialize'] = 1;
-
- $exampleUrl = $apiMetadata->getExampleUrl($class, $methodName, $parametersToSet);
- if($exampleUrl === false)
- {
- $skipped[] = $apiId;
- continue;
- }
-
- // Remove the first ? in the query string
- $exampleUrl = substr($exampleUrl, 1);
- $apiRequestId = $apiId;
- if(strpos($exampleUrl, 'period=') !== false)
- {
- $apiRequestId .= '_' . $period;
- }
-
- $apiRequestId .= '.' . $format;
-
- $requestUrls[$apiRequestId] = $exampleUrl;
- }
- }
- }
- }
-// var_dump($skipped);
-// var_dump($requestUrls);
-// exit;
- return $requestUrls;
+ if($setDateLastN === true)
+ {
+ if(!isset($parametersToSet['dateRewriteBackup']))
+ {
+ $parametersToSet['dateRewriteBackup'] = $parametersToSet['date'];
+ }
+ $lastCount = 6;
+ $firstDate = $parametersToSet['dateRewriteBackup'];
+ $secondDate = date('Y-m-d', strtotime("+$lastCount " . $period . "s", strtotime($firstDate)));
+ $parametersToSet['date'] = $firstDate . ',' . $secondDate;
+ }
+
+ // Set response language
+ if($language !== false)
+ {
+ $parametersToSet['language'] = $language;
+ }
+ // Generate for each specified format
+ foreach($formats as $format)
+ {
+ $parametersToSet['format'] = $format;
+ $parametersToSet['hideIdSubDatable'] = 1;
+ $parametersToSet['serialize'] = 1;
+
+ $exampleUrl = $apiMetadata->getExampleUrl($class, $methodName, $parametersToSet);
+ if($exampleUrl === false)
+ {
+ $skipped[] = $apiId;
+ continue;
+ }
+
+ // Remove the first ? in the query string
+ $exampleUrl = substr($exampleUrl, 1);
+ $apiRequestId = $apiId;
+ if(strpos($exampleUrl, 'period=') !== false)
+ {
+ $apiRequestId .= '_' . $period;
+ }
+
+ $apiRequestId .= '.' . $format;
+
+ $requestUrls[$apiRequestId] = $exampleUrl;
+ }
+ }
+ }
+ }
+// var_dump($skipped);
+// var_dump($requestUrls);
+// exit;
+ return $requestUrls;
}
-
+
/**
- * Will call all get* methods on authorized modules,
+ * Will call all get* methods on authorized modules,
* force the archiving,
* record output in XML files
* and compare with the expected outputs.
- *
+ *
* @param $testName Used to write the output in a file, used as filename prefix
- * @param $formats String or array of formats to fetch from API
+ * @param $formats String or array of formats to fetch from API
* @param $idSite Id site
* @param $dateTime Date time string of reports to request
* @param $periods String or array of strings of periods (day, week, month, year)
@@ -481,7 +480,7 @@ abstract class Test_Integration extends Test_Database_Base
* @param $segment Custom Segment to query the data for
* @param $visitorId Only used for Live! API testing
* @param $abandonedCarts Only used in Goals API testing
- *
+ *
* @return bool Passed or failed
*/
function callGetApiCompareOutput($testName, $formats = 'xml', $idSite = false, $dateTime = false, $periods = false,
@@ -494,9 +493,9 @@ abstract class Test_Integration extends Test_Database_Base
}
$pass = true;
-
+
list($pathProcessed, $pathExpected) = $this->getProcessedAndExpectedDirs();
-
+
if($periods === false)
{
$periods = 'day';
@@ -520,7 +519,7 @@ abstract class Test_Integration extends Test_Database_Base
'piwikUrl' => 'http://example.org/piwik/',
// Used in getKeywordsForPageUrl
'url' => 'http://example.org/store/purchase.htm',
-
+
// Used in Actions.getPageUrl, .getDownload, etc.
// tied to Main.test.php doTest_oneVisitorTwoVisits
// will need refactoring when these same API functions are tested in a new function
@@ -528,10 +527,10 @@ abstract class Test_Integration extends Test_Database_Base
'outlinkUrl' => urlencode('http://dev.piwik.org/svn'),
'pageUrl' => urlencode('http://example.org/index.htm?sessionid=this is also ignored by default'),
'pageName' => urlencode(' Checkout / Purchasing... '),
-
+
// do not show the millisec timer in response or tests would always fail as value is changing
- 'showTimer' => 0,
-
+ 'showTimer' => 0,
+
'language' => $language ? $language : 'en',
'abandonedCarts' => $abandonedCarts ? 1 : 0,
'idSites' => $idSite,
@@ -539,15 +538,15 @@ abstract class Test_Integration extends Test_Database_Base
$parametersToSet = array_merge($parametersToSet, $otherRequestParameters);
if(!empty($visitorId ))
{
- $parametersToSet['visitorId'] = $visitorId;
+ $parametersToSet['visitorId'] = $visitorId;
}
if(!empty($apiModule ))
{
- $parametersToSet['apiModule'] = $apiModule;
+ $parametersToSet['apiModule'] = $apiModule;
}
if(!empty($apiAction))
{
- $parametersToSet['apiAction'] = $apiAction;
+ $parametersToSet['apiAction'] = $apiAction;
}
if(!empty($segment))
{
@@ -557,118 +556,118 @@ abstract class Test_Integration extends Test_Database_Base
{
$parametersToSet['idGoal'] = $idGoal;
}
-
- Zend_Registry::get('config')->General->time_before_today_archive_considered_outdated = 10;
+
+ Piwik_Config::getInstance()->General['time_before_today_archive_considered_outdated'] = 10;
$requestUrls = $this->generateUrlsApi($parametersToSet, $formats, $periods, $setDateLastN, $language, $segment);
-
- foreach($requestUrls as $apiId => $requestUrl)
- {
-// echo "$requestUrl <br>";
+
+ foreach($requestUrls as $apiId => $requestUrl)
+ {
+// echo "$requestUrl <br>";
$isLiveMustDeleteDates = strpos($requestUrl, 'Live.getLastVisits') !== false;
- $request = new Piwik_API_Request($requestUrl);
+ $request = new Piwik_API_Request($requestUrl);
list($processedFilePath, $expectedFilePath) = $this->getProcessedAndExpectedPaths($testName, $apiId);
-
- // Cast as string is important. For example when calling
- // with format=original, objects or php arrays can be returned.
- // we also hide errors to prevent the 'headers already sent' in the ResponseBuilder (which sends Excel headers multiple times eg.)
- $response = (string)$request->process();
-
- if($isLiveMustDeleteDates)
- {
- $response = $this->removeAllLiveDatesFromXml($response);
- }
-
- file_put_contents( $processedFilePath, $response );
-
- $expected = $this->loadExpectedFile($expectedFilePath);
- if (empty($expected))
- {
- continue;
- }
+
+ // Cast as string is important. For example when calling
+ // with format=original, objects or php arrays can be returned.
+ // we also hide errors to prevent the 'headers already sent' in the ResponseBuilder (which sends Excel headers multiple times eg.)
+ $response = (string)$request->process();
+
+ if($isLiveMustDeleteDates)
+ {
+ $response = $this->removeAllLiveDatesFromXml($response);
+ }
+
+ file_put_contents( $processedFilePath, $response );
+
+ $expected = $this->loadExpectedFile($expectedFilePath);
+ if (empty($expected))
+ {
+ continue;
+ }
// When tests run on Windows EOL delimiters are not the same as UNIX default EOL used in the renderers
- $expected = str_replace("\r\n", "\n", $expected);
- $response = str_replace("\r\n", "\n", $response);
-
- // @todo This should not vary between systems AFAIK... "idsubdatatable can differ"
- $expected = $this->removeXmlElement($expected, 'idsubdatatable',$testNotSmallAfter = false);
- $response = $this->removeXmlElement($response, 'idsubdatatable',$testNotSmallAfter = false);
-
- $removeEndOfLines = false;
- if($isLiveMustDeleteDates)
- {
- $expected = $this->removeAllLiveDatesFromXml($expected);
- }
- // If date=lastN the <prettyDate> element will change each day, we remove XML element before comparison
- elseif(strpos($dateTime, 'last') !== false
- || strpos($dateTime, 'today') !== false
- || strpos($dateTime, 'now') !== false
- )
- {
- if(strpos($requestUrl, 'API.getProcessedReport') !== false)
- {
- $expected = $this->removePrettyDateFromXml($expected);
- $response = $this->removePrettyDateFromXml($response);
- }
- // avoid build failure when running just before midnight, generating visits in the future
- $expected = $this->removeXmlElement($expected, 'sum_daily_nb_uniq_visitors');
- $response = $this->removeXmlElement($response, 'sum_daily_nb_uniq_visitors');
- $expected = $this->removeXmlElement($expected, 'nb_visits_converted');
- $response = $this->removeXmlElement($response, 'nb_visits_converted');
- $expected = $this->removeXmlElement($expected, 'imageGraphUrl');
- $response = $this->removeXmlElement($response, 'imageGraphUrl');
- $removeEndOfLines =true;
- }
-
- // is there a better way to test for the current DB type in use?
- if(Zend_Registry::get('db') instanceof Piwik_Db_Adapter_Mysqli)
- {
- // Do not test for TRUNCATE(SUM()) returning .00 on mysqli since this is not working
- // http://bugs.php.net/bug.php?id=54508
- $expected = str_replace('.00</revenue>', '</revenue>', $expected);
- $response = str_replace('.00</revenue>', '</revenue>', $response);
- $expected = str_replace('.1</revenue>', '</revenue>', $expected);
- $expected = str_replace('.11</revenue>', '</revenue>', $expected);
- $response = str_replace('.11</revenue>', '</revenue>', $response);
- $response = str_replace('.1</revenue>', '</revenue>', $response);
- }
-
- // Hack so we dont file_put_contents (see below) the files with the end of lines removed (not readable)
- $responseToTest = $response;
- $expectedToTest = $expected;
- if($removeEndOfLines)
- {
- $responseToTest = str_replace("\n", "", $response);
- $expectedToTest = str_replace("\n", "", $expected);
- }
- $pass = $pass && $this->assertEqual(trim($responseToTest), trim($expectedToTest), "<br/>\nDifferences with expected in: $processedFilePath %s ");
- if(trim($response) != trim($expected))
- {
- var_dump('ERROR FOR ' . $apiId . ' -- FETCHED RESPONSE, then EXPECTED RESPONSE - '.$requestUrl);
- echo "\n";
- var_dump($response);
- echo "\n";
- var_dump($expected);
- echo "\n";
- }
- else
- {
- file_put_contents( $processedFilePath, $response );
- }
- }
- if($pass) {
- $this->pass();
- } else {
- $this->fail();
- }
- return $pass;
+ $expected = str_replace("\r\n", "\n", $expected);
+ $response = str_replace("\r\n", "\n", $response);
+
+ // @todo This should not vary between systems AFAIK... "idsubdatatable can differ"
+ $expected = $this->removeXmlElement($expected, 'idsubdatatable',$testNotSmallAfter = false);
+ $response = $this->removeXmlElement($response, 'idsubdatatable',$testNotSmallAfter = false);
+
+ $removeEndOfLines = false;
+ if($isLiveMustDeleteDates)
+ {
+ $expected = $this->removeAllLiveDatesFromXml($expected);
+ }
+ // If date=lastN the <prettyDate> element will change each day, we remove XML element before comparison
+ elseif(strpos($dateTime, 'last') !== false
+ || strpos($dateTime, 'today') !== false
+ || strpos($dateTime, 'now') !== false
+ )
+ {
+ if(strpos($requestUrl, 'API.getProcessedReport') !== false)
+ {
+ $expected = $this->removePrettyDateFromXml($expected);
+ $response = $this->removePrettyDateFromXml($response);
+ }
+ // avoid build failure when running just before midnight, generating visits in the future
+ $expected = $this->removeXmlElement($expected, 'sum_daily_nb_uniq_visitors');
+ $response = $this->removeXmlElement($response, 'sum_daily_nb_uniq_visitors');
+ $expected = $this->removeXmlElement($expected, 'nb_visits_converted');
+ $response = $this->removeXmlElement($response, 'nb_visits_converted');
+ $expected = $this->removeXmlElement($expected, 'imageGraphUrl');
+ $response = $this->removeXmlElement($response, 'imageGraphUrl');
+ $removeEndOfLines =true;
+ }
+
+ // is there a better way to test for the current DB type in use?
+ if(Zend_Registry::get('db') instanceof Piwik_Db_Adapter_Mysqli)
+ {
+ // Do not test for TRUNCATE(SUM()) returning .00 on mysqli since this is not working
+ // http://bugs.php.net/bug.php?id=54508
+ $expected = str_replace('.00</revenue>', '</revenue>', $expected);
+ $response = str_replace('.00</revenue>', '</revenue>', $response);
+ $expected = str_replace('.1</revenue>', '</revenue>', $expected);
+ $expected = str_replace('.11</revenue>', '</revenue>', $expected);
+ $response = str_replace('.11</revenue>', '</revenue>', $response);
+ $response = str_replace('.1</revenue>', '</revenue>', $response);
+ }
+
+ // Hack so we dont file_put_contents (see below) the files with the end of lines removed (not readable)
+ $responseToTest = $response;
+ $expectedToTest = $expected;
+ if($removeEndOfLines)
+ {
+ $responseToTest = str_replace("\n", "", $response);
+ $expectedToTest = str_replace("\n", "", $expected);
+ }
+ $pass = $pass && $this->assertEqual(trim($responseToTest), trim($expectedToTest), "<br/>\nDifferences with expected in: $processedFilePath %s ");
+ if(trim($response) != trim($expected))
+ {
+ var_dump('ERROR FOR ' . $apiId . ' -- FETCHED RESPONSE, then EXPECTED RESPONSE - '.$requestUrl);
+ echo "\n";
+ var_dump($response);
+ echo "\n";
+ var_dump($expected);
+ echo "\n";
+ }
+ else
+ {
+ file_put_contents( $processedFilePath, $response );
+ }
+ }
+ if($pass) {
+ $this->pass();
+ } else {
+ $this->fail();
+ }
+ return $pass;
}
-
+
/**
* Calls a set of controller actions & either checks the result against
* expected output or just checks if errors occurred when called.
- *
+ *
* The behavior of this function can be modified by setting
* Test_Integration::$widgetTestingLevel (or $testingLevelOverride):
* <ul>
@@ -678,7 +677,7 @@ abstract class Test_Integration extends Test_Database_Base
* <li>If set to <b>COMPARE_WIDGET_OUTPUT</b> controller actions are
* called & the output is checked against expected output.</li>
* </ul>
- *
+ *
* @param string $testName Unique name of this test group. Expected/processed
* file names use this as a prefix.
* @param array $actions Array of controller actions to call. Each element
@@ -702,7 +701,7 @@ abstract class Test_Integration extends Test_Database_Base
{
$testingLevelOverride = self::$widgetTestingLevel;
}
-
+
// process $userTypes argument
if (!$userTypes)
{
@@ -736,11 +735,11 @@ abstract class Test_Integration extends Test_Database_Base
{
$customParams = isset($actionParams[$controllerAction]) ? $actionParams[$controllerAction] : array();
list($controllerName, $actionName) = explode('.', $controllerAction);
-
+
foreach ($userTypes as $userType)
{
$this->setUserType($userType);
-
+
try
{
// set request parameters
@@ -753,7 +752,7 @@ abstract class Test_Integration extends Test_Database_Base
{
$_GET[$key] = $value;
}
-
+
$_GET['module'] = $controllerName;
$_GET['action'] = $actionName;
@@ -765,7 +764,7 @@ abstract class Test_Integration extends Test_Database_Base
// call controller action
$response = Piwik_FrontController::getInstance()->fetchDispatch();
-
+
list($processedFilePath, $expectedFilePath) = $this->getProcessedAndExpectedPaths(
$testName . '_' . $userType, $controllerAction, 'html');
@@ -802,9 +801,9 @@ abstract class Test_Integration extends Test_Database_Base
}
// normalize eol delimeters
- $expected = str_replace("\r\n", "\n", $expected);
+ $expected = str_replace("\r\n", "\n", $expected);
$response = str_replace("\r\n", "\n", $response);
-
+
// check against expected
$passed = $this->assertEqual(trim($expected), trim($response),
"<br/>\nDifferences with expected in: $processedFilePath %s ");
@@ -833,14 +832,14 @@ abstract class Test_Integration extends Test_Database_Base
{
$_GET[$key] = $value;
}
-
+
// set user type
$this->setUserType('superuser');
}
-
+
/**
* Sets the access privilegs of the current user to the specified user type.
- *
+ *
* @param $userType string Can be 'superuser', 'admin', 'view' or 'anonymous'.
*/
protected function setUserType( $userType )
@@ -860,21 +859,21 @@ abstract class Test_Integration extends Test_Database_Base
$login = 'test_' . $login;
}
}
-
+
$authResultObj = new Piwik_Auth_Result($code, $login, 'dummyTokenAuth');
$authObj = new MockPiwik_Auth();
$authObj->setReturnValue('getName', 'Login');
$authObj->setReturnValue('authenticate', $authResultObj);
-
+
Zend_Registry::get('access')->reloadAccess($authObj);
}
-
+
/**
* Set of messages for errors that occurred during the invocation of a
* controller action. If not empty, there was an error in the controller.
*/
private $errorsOccurredInTest = array();
-
+
/**
* A custom error handler used with <code>set_error_handler</code>. If
* an error occurs, a message describing it is saved in an array.
@@ -886,7 +885,7 @@ abstract class Test_Integration extends Test_Database_Base
$this->errorsOccurredInTest[] = "$errfile($errline): - $errstr";
}
}
-
+
/**
* Returns a list of all available widgets.
*/
@@ -896,7 +895,7 @@ abstract class Test_Integration extends Test_Database_Base
$actions = array();
$customParams = array();
-
+
foreach($widgetList as $widgetCategory => $widgets)
{
foreach($widgets as $widgetInfo)
@@ -904,7 +903,7 @@ abstract class Test_Integration extends Test_Database_Base
$module = $widgetInfo['parameters']['module'];
$moduleAction = $widgetInfo['parameters']['action'];
$wholeAction = "$module.$moduleAction";
-
+
// FIXME: can't test Referers.getKeywordsForPage since it tries to make a request to
// localhost w/ the wrong url. Piwik_Url::getCurrentUrlWithoutFileName
// returns /tests/integration/?... when used within a test.
@@ -912,7 +911,7 @@ abstract class Test_Integration extends Test_Database_Base
{
continue;
}
-
+
// rss widgets depends on feedburner URL. don't test the widget just in case
// feedburner is down.
if ($module == "ExampleRssWidget"
@@ -923,15 +922,15 @@ abstract class Test_Integration extends Test_Database_Base
unset($widgetInfo['parameters']['module']);
unset($widgetInfo['parameters']['action']);
-
+
$actions[] = $wholeAction;
$customParams[$wholeAction] = $widgetInfo['parameters'];
}
}
-
+
return array($actions, $customParams);
}
-
+
protected function removeAllLiveDatesFromXml($input)
{
$toRemove = array(
@@ -953,21 +952,21 @@ abstract class Test_Integration extends Test_Database_Base
}
return $input;
}
-
+
protected function removePrettyDateFromXml($input)
{
- return $this->removeXmlElement($input, 'prettyDate');
+ return $this->removeXmlElement($input, 'prettyDate');
}
-
+
protected function removeXmlElement($input, $xmlElement, $testNotSmallAfter = true)
{
$input = preg_replace('/(<'.$xmlElement.'>.+?<\/'.$xmlElement.'>)/', '', $input);
- //check we didn't delete the whole string
+ //check we didn't delete the whole string
if($testNotSmallAfter)
{
$this->assertTrue(strlen($input) > 100);
}
- return $input;
+ return $input;
}
private function getProcessedAndExpectedDirs()
@@ -983,9 +982,9 @@ abstract class Test_Integration extends Test_Database_Base
{
$filename .= ".$format";
}
-
+
list($processedDir, $expectedDir) = $this->getProcessedAndExpectedDirs();
-
+
return array($processedDir . $filename, $expectedDir . $filename);
}
@@ -1016,7 +1015,7 @@ abstract class Test_Integration extends Test_Database_Base
Piwik_Translate::reset();
Piwik_Translate::getInstance()->reloadLanguage($langId);
}
-
+
$this->lastLanguage = $langId;
}
}
@@ -1031,7 +1030,7 @@ abstract class Test_Integration_Facade extends Test_Integration
/**
* Returns an array describing the API methods to call & compare with
* expected output.
- *
+ *
* The returned array must be of the following format:
* <code>
* array(
@@ -1042,7 +1041,7 @@ abstract class Test_Integration_Facade extends Test_Integration
* .
* )
* </code>
- *
+ *
* Valid test options:
* <ul>
* <li><b>testSuffix</b> The suffix added to the test name. Helps determine
@@ -1063,15 +1062,15 @@ abstract class Test_Integration_Facade extends Test_Integration
* <li><b>otherRequestParameters</b> An array of extra request parameters to use.</li>
* <li><b>disableArchiving</b> Disable archiving before running tests.</li>
* </ul>
- *
+ *
* All test options are optional, except 'idSite' & 'date'.
*/
abstract public function getApiToTest();
-
+
/**
* Returns an array describing the Controller actions to call & compare
* with expected output.
- *
+ *
* The returned array must be of the following format:
* <code>
* array(
@@ -1082,14 +1081,14 @@ abstract class Test_Integration_Facade extends Test_Integration
* .
* )
* </code>
- *
+ *
* Valid test options:
* <ul>
* <li><b>UNIMPLEMENTED</b></li>
* </ul>
*/
abstract public function getControllerActionsToTest();
-
+
/**
* Called before running any tests. Overriding classes must log any
* visits/conversions in this method.
@@ -1098,22 +1097,22 @@ abstract class Test_Integration_Facade extends Test_Integration
/**
* The main test case. Runs API & Controller tests.
- *
+ *
* This can be overriden to add more testing logic (or a new test case
* can be added).
*/
public function test_RunAllTests()
{
$this->trackVisits();
-
+
// From Piwik 1.5, we hide Goals.getConversions and other get* methods via @ignore, but we ensure that they still work
// This hack allows the API proxy to let us generate example URLs for the ignored functions
Piwik_API_Proxy::getInstance()->hideIgnoredFunctions = false;
-
+
$this->runApiTests();
$this->runControllerTests();
}
-
+
/**
* Gets the string prefix used in the name of the expected/processed output files.
*/
@@ -1129,7 +1128,7 @@ abstract class Test_Integration_Facade extends Test_Integration
{
$apiToTest = $this->getApiToTest();
$testName = 'test_' . $this->getOutputPrefix();
-
+
foreach ($apiToTest as $test)
{
list($api, $params) = $test;
@@ -1145,11 +1144,11 @@ abstract class Test_Integration_Facade extends Test_Integration
{
$api = array($api);
}
-
+
$this->setApiToCall($api);
$this->setApiNotToCall(array());
}
-
+
if (isset($params['disableArchiving']) && $params['disableArchiving'] === true)
{
Piwik_ArchiveProcessing::$forceDisableArchiving = true;
@@ -1163,9 +1162,9 @@ abstract class Test_Integration_Facade extends Test_Integration
{
$this->changeLanguage($params['language']);
}
-
+
$testSuffix = isset($params['testSuffix']) ? $params['testSuffix'] : '';
-
+
$this->callGetApiCompareOutput(
$testName . $testSuffix,
isset($params['format']) ? $params['format'] : 'xml',
@@ -1181,7 +1180,7 @@ abstract class Test_Integration_Facade extends Test_Integration
isset($params['apiModule']) ? $params['apiModule'] : false,
isset($params['apiAction']) ? $params['apiAction'] : false,
isset($params['otherRequestParameters']) ? $params['otherRequestParameters'] : array());
-
+
// change the language back to en
if ($this->lastLanguage != 'en')
{
@@ -1189,27 +1188,27 @@ abstract class Test_Integration_Facade extends Test_Integration
}
}
}
-
+
/**
* Runs controller tests.
*/
protected function runControllerTests()
{
static $nonRequestParameters = array('testingLevelOverride' => null, 'userTypes' => null);
-
+
$testGroups = $this->getControllerActionsToTest();
$testName = 'test_' . $this->getOutputPrefix();
foreach ($testGroups as $test)
{
list($actions, $params) = $test;
-
+
// deal w/ any language changing hacks
if (isset($params['language']))
{
$this->changeLanguage($params['language']);
}
-
+
// separate request parameters from function parameters
$requestParams = array();
foreach ($params as $key => $value)
@@ -1219,16 +1218,16 @@ abstract class Test_Integration_Facade extends Test_Integration
$requestParams[$key] = $value;
}
}
-
+
$testSuffix = isset($params['testSuffix']) ? $params['testSuffix'] : '';
-
+
$this->callWidgetsCompareOutput(
$testName . $testSuffix,
$actions,
$requestParams,
isset($params['userTypes']) ? $params['userTypes'] : false,
isset($params['testingLevelOverride']) ? $params['testingLevelOverride'] : false);
-
+
// change the language back to en
if ($this->lastLanguage != 'en')
{
diff --git a/tests/integration/proxy-piwik.php b/tests/integration/proxy-piwik.php
index 63772c191f..ade0603ffa 100644
--- a/tests/integration/proxy-piwik.php
+++ b/tests/integration/proxy-piwik.php
@@ -22,24 +22,24 @@ require_once PIWIK_INCLUDE_PATH .'/core/Loader.php';
// Note that this also provides security for Piwik installs containing tests files:
// this proxy will not record any data in the production database.
Piwik::createConfigObject();
-Zend_Registry::get('config')->setTestEnvironment();
-Piwik_Tracker_Config::getInstance()->setTestEnvironment();
+Piwik_Config::getInstance()->setTestEnvironment();
+Piwik_Config::getInstance()->PluginsInstalled['PluginsInstalled'] = array();
// Do not run scheduled tasks during tests
-Piwik_Tracker_Config::getInstance()->setTestValue('Tracker', 'scheduled_tasks_min_interval', 0);
+Piwik_Config::getInstance()->Tracker['scheduled_tasks_min_interval'] = 0;
// Tests can force the use of 3rd party cookie for ID visitor
if(Piwik_Common::getRequestVar('forceUseThirdPartyCookie', false) == 1)
{
- Piwik_Tracker_Config::getInstance()->setTestValue('Tracker', 'use_third_party_id_cookie', 1);
+ Piwik_Config::getInstance()->Tracker['use_third_party_id_cookie'] = 1;
}
// Tests can force the enabling of IP anonymization
if(Piwik_Common::getRequestVar('forceIpAnonymization', false) == 1)
{
- Piwik_Tracker_Config::getInstance()->setTestValue('Tracker', 'ip_address_mask_length', 2);
- $pluginsTracker = Piwik_Tracker_Config::getInstance()->Plugins_Tracker['Plugins_Tracker'];
+ Piwik_Config::getInstance()->Tracker['ip_address_mask_length'] = 2;
+ $pluginsTracker = Piwik_Config::getInstance()->Plugins_Tracker['Plugins_Tracker'];
$pluginsTracker[] = "AnonymizeIP";
- Piwik_Tracker_Config::getInstance()->setTestValue('Plugins_Tracker', array('Plugins_Tracker' => $pluginsTracker));
+ Piwik_Config::getInstance()->Plugins_Tracker = array('Plugins_Tracker' => $pluginsTracker);
}
// Custom IP to use for this visitor
$customIp = Piwik_Common::getRequestVar('cip', false);
diff --git a/tests/resources/Tracker/Action.config.ini.php b/tests/resources/Tracker/Action.config.ini.php
index 62bb57cc26..a63185e541 100644
--- a/tests/resources/Tracker/Action.config.ini.php
+++ b/tests/resources/Tracker/Action.config.ini.php
@@ -1,5 +1,5 @@
[Tracker]
action_url_category_delimiter = /
default_action_url = /
-campaign_var_name = campaign_param_name
-campaign_keyword_var_name = piwik_kwd
+campaign_var_name = campaign_param_name,piwik_campaign,utm_campaign
+campaign_keyword_var_name = piwik_kwd,utm_term