From 64c7aa1b9e1d69c8d791afc4a1ef421b6b1bac6c Mon Sep 17 00:00:00 2001 From: mattab <matthieu.aubry@gmail.com> Date: Tue, 15 Oct 2013 17:32:32 +1300 Subject: [PATCH] Making sure at least WARNING messages are written on screen --- config/global.ini.php | 2 +- core/IP.php | 7 ++++++- core/Plugin/Controller.php | 5 +++-- core/Plugin/Manager.php | 20 ++++++++++++++++++++ core/Tracker.php | 3 ++- core/Url.php | 8 +++++++- index.php | 1 - tests/PHPUnit/IntegrationTestCase.php | 8 +------- tests/PHPUnit/proxy/index.php | 4 ++++ 9 files changed, 44 insertions(+), 14 deletions(-) diff --git a/config/global.ini.php b/config/global.ini.php index cd7ec40906..4b71c6fd77 100644 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -470,7 +470,7 @@ password = ; Proxy password: optional; if specified, username is mandatory [log] ; possible values for log: screen, database, file -log_writers[] = file +log_writers[] = screen ; log level, everything logged w/ this level or one of greater severity ; will be logged. everything else will be ignored. possible values are: diff --git a/core/IP.php b/core/IP.php index 6e8e1d13e6..0b3d152ee7 100644 --- a/core/IP.php +++ b/core/IP.php @@ -368,10 +368,15 @@ class IP */ public static function getNonProxyIpFromHeader($default, $proxyHeaders) { - $proxyIps = @Config::getInstance()->General['proxy_ips']; + $proxyIps = array(); + $config = Config::getInstance()->General; + if(isset($config['proxy_ips'])) { + $proxyIps = $config['proxy_ips']; + } if (!is_array($proxyIps)) { $proxyIps = array(); } + $proxyIps[] = $default; // examine proxy headers diff --git a/core/Plugin/Controller.php b/core/Plugin/Controller.php index a8125e47de..f16d4c694b 100644 --- a/core/Plugin/Controller.php +++ b/core/Plugin/Controller.php @@ -456,8 +456,9 @@ abstract class Controller $view->logoSVG = \Piwik\Plugins\API\API::getInstance()->getSVGLogoUrl(); $view->hasSVGLogo = \Piwik\Plugins\API\API::getInstance()->hasSVGLogo(); - $view->enableFrames = PiwikConfig::getInstance()->General['enable_framed_pages'] - || @PiwikConfig::getInstance()->General['enable_framed_logins']; + $general = PiwikConfig::getInstance()->General; + $view->enableFrames = $general['enable_framed_pages'] + || (isset($general['enable_framed_logins']) && $general['enable_framed_logins']); if (!$view->enableFrames) { $view->setXFrameOptions('sameorigin'); } diff --git a/core/Plugin/Manager.php b/core/Plugin/Manager.php index 0bf348460a..0591dd0ff8 100644 --- a/core/Plugin/Manager.php +++ b/core/Plugin/Manager.php @@ -563,6 +563,26 @@ class Manager extends Singleton } + /** + * Returns the name of all plugins found in this Piwik instance + * (including those not enabled) + * + * Used in tests + * + * @return array + */ + public static function getAllPluginsNames() + { + $pluginsToLoad = array_merge( + PiwikConfig::getInstance()->Plugins['Plugins'], + self::getInstance()->readPluginsDirectory(), + self::getInstance()->getCorePluginsDisabledByDefault() + ); + $pluginsToLoad = array_values(array_unique($pluginsToLoad)); + return $pluginsToLoad; + } + + /** * Loads the plugin filename and instantiates the plugin with the given name, eg. UserCountry * Do NOT give the class name ie. UserCountry, but give the plugin name ie. UserCountry diff --git a/core/Tracker.php b/core/Tracker.php index f4618ee3b3..8ea8d2b669 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -806,7 +806,8 @@ class Tracker self::setPluginsNotToLoad($pluginsDisabled); // we load 'DevicesDetection' in tests only (disabled by default) - self::setPluginsToLoad(array('DevicesDetection')); + $allPluginsFound = \Piwik\Plugin\Manager::getInstance()->getAllPluginsNames(); + self::setPluginsToLoad( $allPluginsFound ); } /** diff --git a/core/Url.php b/core/Url.php index 6a4f4a4ad7..ff38faff9c 100644 --- a/core/Url.php +++ b/core/Url.php @@ -289,7 +289,13 @@ class Url */ static public function getCurrentHost($default = 'unknown', $checkTrustedHost = true) { - $hostHeaders = @Config::getInstance()->General['proxy_host_headers']; + $hostHeaders = array(); + + $config = Config::getInstance()->General; + if(isset($config['proxy_host_headers'])) { + $hostHeaders = $config['proxy_host_headers']; + } + if (!is_array($hostHeaders)) { $hostHeaders = array(); } diff --git a/index.php b/index.php index ba74026dce..c669fe7f6a 100644 --- a/index.php +++ b/index.php @@ -50,7 +50,6 @@ if (!defined('PIWIK_ENABLE_ERROR_HANDLER') || PIWIK_ENABLE_ERROR_HANDLER) { ExceptionHandler::setUp(); } - if (!defined('PIWIK_ENABLE_DISPATCH') || PIWIK_ENABLE_DISPATCH) { $controller = FrontController::getInstance(); $controller->init(); diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php index 3157367bc4..f590a6a9e2 100755 --- a/tests/PHPUnit/IntegrationTestCase.php +++ b/tests/PHPUnit/IntegrationTestCase.php @@ -101,13 +101,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase public static function loadAllPlugins() { $pluginsManager = \Piwik\Plugin\Manager::getInstance(); - - $pluginsToLoad = array_merge( - Config::getInstance()->Plugins['Plugins'], - $pluginsManager->readPluginsDirectory(), - $pluginsManager->getCorePluginsDisabledByDefault() - ); - $pluginsToLoad = array_values(array_unique($pluginsToLoad)); + $pluginsToLoad = $pluginsManager->getAllPluginsNames(); $pluginsManager->loadPlugins($pluginsToLoad); } diff --git a/tests/PHPUnit/proxy/index.php b/tests/PHPUnit/proxy/index.php index 59dbab1ec5..c0c0c6166d 100644 --- a/tests/PHPUnit/proxy/index.php +++ b/tests/PHPUnit/proxy/index.php @@ -22,6 +22,10 @@ define('PIWIK_ENABLE_DISPATCH', false); include PIWIK_INCLUDE_PATH . '/index.php'; $controller = \Piwik\FrontController::getInstance(); + +// Load all plugins that are found so UI tests are really testing real world use case +\Piwik\Config::getInstance()->Plugins['Plugins'] = \Piwik\Plugin\Manager::getInstance()->getAllPluginsNames(); + $controller->init(); $controller->dispatch(); -- GitLab