diff --git a/core/Config.php b/core/Config.php index 3dc081d80e96a2b2605d1e923db7406eb8bea598..726a13d56f029f75f6139cf3ae372324d21c305d 100644 --- a/core/Config.php +++ b/core/Config.php @@ -296,7 +296,7 @@ class Config extends Singleton public function init() { $this->initialized = true; - $reportError = !empty($GLOBALS['PIWIK_TRACKER_MODE']); + $reportError = SettingsServer::isTrackerApiRequest(); // read defaults from global.ini.php if (!is_readable($this->pathGlobal) && $reportError) { diff --git a/core/Db.php b/core/Db.php index 4b4ec86cd68e60387b39100a7fc62d1eafb2d159..f099d0140957aa01e6d09c10302641e46de691a6 100644 --- a/core/Db.php +++ b/core/Db.php @@ -42,7 +42,7 @@ class Db */ public static function get() { - if (!empty($GLOBALS['PIWIK_TRACKER_MODE'])) { + if (SettingsServer::isTrackerApiRequest()) { return Tracker::getDatabase(); } diff --git a/core/FrontController.php b/core/FrontController.php index 53227f886a30d48f42d30fa8a0d22264bf4858c6..0efcfa1a993b70393e1fbf6902587b251c00a035 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -168,7 +168,7 @@ class FrontController extends Singleton { try { if (class_exists('Piwik\\Profiler') - && empty($GLOBALS['PIWIK_TRACKER_MODE'])) { + && !SettingsServer::isTrackerApiRequest()) { // in tracker mode Piwik\Tracker\Db\Pdo\Mysql does currently not implement profiling Profiler::displayDbProfileReport(); Profiler::printQueryCount(); diff --git a/core/Plugin/Settings.php b/core/Plugin/Settings.php index 1200d9eb6ae55e20025ab8a528c2c57eea872bfa..20a5a305991f7c285a905a9a50e9f2e547a1ea06 100644 --- a/core/Plugin/Settings.php +++ b/core/Plugin/Settings.php @@ -12,6 +12,7 @@ use Piwik\Option; use Piwik\Piwik; use Piwik\Settings\Setting; use Piwik\Settings\StorageInterface; +use Piwik\SettingsServer; /** * Base class of all plugin settings providers. Plugins that define their own configuration settings @@ -325,6 +326,11 @@ abstract class Settings implements StorageInterface */ private function checkHasEnoughPermission(Setting $setting) { + // When the request is a Tracker request, allow plugins to read/write settings + if(SettingsServer::isTrackerApiRequest()) { + return; + } + if (!$setting->canBeDisplayedForCurrentUser()) { $errorMsg = Piwik::translate('CoreAdminHome_PluginSettingChangeNotAllowed', array($setting->getName(), $this->pluginName)); throw new \Exception($errorMsg); diff --git a/core/Profiler.php b/core/Profiler.php index 122e61f4b44faac15192aea4c2a8d6a3d1ef98ed..ae9c5e8b766a2d467ca51a9a9a5c817beebdb962 100644 --- a/core/Profiler.php +++ b/core/Profiler.php @@ -186,7 +186,7 @@ class Profiler */ public static function setupProfilerXHProf($mainRun = false) { - if(!empty($GLOBALS['PIWIK_TRACKER_MODE'])) { + if(SettingsServer::isTrackerApiRequest()) { // do not profile Tracker return; } diff --git a/core/SettingsServer.php b/core/SettingsServer.php index d1d5142ec79940df2b86c0d9eaa10a96dd1eb9b7..7223d3e304ca83f1a4522d78db0c40dad49bcd8d 100644 --- a/core/SettingsServer.php +++ b/core/SettingsServer.php @@ -31,6 +31,18 @@ class SettingsServer && Piwik::hasUserSuperUserAccess(); } + + /** + * Returns true if the current request is a Tracker request. + * + * @return bool true if the current request is a Tracking API Request (ie. piwik.php) + */ + public static function isTrackerApiRequest() + { + return !empty($GLOBALS['PIWIK_TRACKER_MODE']); + } + + /** * Returns `true` if running on Microsoft IIS 7 (or above), `false` if otherwise. * diff --git a/core/Tracker.php b/core/Tracker.php index c67d2e91f17a6af8c7d38a0cd9026069dfd4fd9c..05deb9a2aa9e08f9dc0988a7d927221931f99d7e 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -369,7 +369,7 @@ class Tracker */ static public function initCorePiwikInTrackerMode() { - if (!empty($GLOBALS['PIWIK_TRACKER_MODE']) + if (SettingsServer::isTrackerApiRequest() && self::$initTrackerMode === false ) { self::$initTrackerMode = true; diff --git a/tests/PHPUnit/UI b/tests/PHPUnit/UI index 2608eccd787346f6b12ae57db89039bf769286d5..8c75aba42a588d30c9d9b8537a5297ac646d7274 160000 --- a/tests/PHPUnit/UI +++ b/tests/PHPUnit/UI @@ -1 +1 @@ -Subproject commit 2608eccd787346f6b12ae57db89039bf769286d5 +Subproject commit 8c75aba42a588d30c9d9b8537a5297ac646d7274