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:
authorThomas Steur <thomas.steur@googlemail.com>2014-07-02 06:23:42 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-07-02 06:23:42 +0400
commit5ce45d1a948bd965f63c333d8f2ed0f76f74cc92 (patch)
tree79d9d6d1f9e3dd2675c69442b0cff9ed8d5321e5
parent3a8aa4a5198b4f0b917ff72fbd32d14896c8fd67 (diff)
added development flag which allows us to not cache static cache and to make some more checks when developers develop plugins
-rw-r--r--config/global.ini.php17
-rw-r--r--core/AssetManager.php2
-rw-r--r--core/AssetManager/UIAssetFetcher/JScriptUIAssetFetcher.php2
-rw-r--r--core/Cache/StaticCache.php7
-rw-r--r--core/Config.php1
-rw-r--r--core/Development.php85
-rw-r--r--core/Plugin/Widgets.php37
-rw-r--r--core/Tracker/Visit.php2
-rw-r--r--core/Updates/2.5.0-b1.php20
-rw-r--r--plugins/ExamplePlugin/javascripts/plugin.js2
-rw-r--r--tests/PHPUnit/Core/AssetManager/configs/merged-assets-disabled.ini.php2
-rw-r--r--tests/PHPUnit/Core/AssetManager/configs/merged-assets-enabled.ini.php2
12 files changed, 166 insertions, 13 deletions
diff --git a/config/global.ini.php b/config/global.ini.php
index b5b21294bc..c3c68c1de0 100644
--- a/config/global.ini.php
+++ b/config/global.ini.php
@@ -77,10 +77,6 @@ enable_sql_profiler = 0
; this is useful for Piwik developers as an easy way to create data in their local Piwik
enable_measure_piwik_usage_in_idsite = 0
-; if set to 1, javascript files will be included individually and neither merged nor minified.
-; this option must be set to 1 when adding, removing or modifying javascript files
-disable_merged_assets = 0
-
; If set to 1, all requests to piwik.php will be forced to be 'new visitors'
tracker_always_new_visitor = 0
@@ -92,7 +88,20 @@ allow_upgrades_to_beta = 0
; will be loaded when executing tests.
enable_load_standalone_plugins_during_tests = 0
+[Development]
+
+; Enables the development mode where we avoid most caching to make sure code changes will be directly applied as
+; some caches are only invalidated after an update otherwise. When enabled it'll also performs some validation checks.
+; For instance if you register a method in a widget we will verify whether the method actually exists and is public.
+; If not, we will show you a helpful warning to make it easy to find simple typos etc.
+enabled = 0
+
+; if set to 1, javascript files will be included individually and neither merged nor minified.
+; this option must be set to 1 when adding, removing or modifying javascript files
+disable_merged_assets = 0
+
[General]
+
; the following settings control whether Unique Visitors will be processed for different period types.
; year and range periods are disabled by default, to ensure optimal performance for high traffic Piwik instances
; if you set it to 1 and want the Unique Visitors to be re-processed for reports in the past, drop all piwik_archive_* tables
diff --git a/core/AssetManager.php b/core/AssetManager.php
index 4bf29afef0..1badba4d9e 100644
--- a/core/AssetManager.php
+++ b/core/AssetManager.php
@@ -273,7 +273,7 @@ class AssetManager extends Singleton
*/
public function isMergedAssetsDisabled()
{
- return Config::getInstance()->Debug['disable_merged_assets'];
+ return Config::getInstance()->Development['disable_merged_assets'];
}
/**
diff --git a/core/AssetManager/UIAssetFetcher/JScriptUIAssetFetcher.php b/core/AssetManager/UIAssetFetcher/JScriptUIAssetFetcher.php
index d63134c08f..a5ab3d096d 100644
--- a/core/AssetManager/UIAssetFetcher/JScriptUIAssetFetcher.php
+++ b/core/AssetManager/UIAssetFetcher/JScriptUIAssetFetcher.php
@@ -31,7 +31,7 @@ class JScriptUIAssetFetcher extends UIAssetFetcher
* plugin's root directory.
*
* _Note: While you are developing your plugin you should enable the config setting
- * `[Debug] disable_merged_assets` so JavaScript files will be reloaded immediately
+ * `[Development] disable_merged_assets` so JavaScript files will be reloaded immediately
* after every change._
*
* **Example**
diff --git a/core/Cache/StaticCache.php b/core/Cache/StaticCache.php
index fe887d48fe..6d1c7ed830 100644
--- a/core/Cache/StaticCache.php
+++ b/core/Cache/StaticCache.php
@@ -8,8 +8,7 @@
*/
namespace Piwik\Cache;
-use Piwik\Piwik;
-use Piwik\SettingsServer;
+use Piwik\Development;
use Piwik\Tracker;
use Piwik\Translate;
@@ -66,6 +65,10 @@ class StaticCache
public static function loadTrackerCache()
{
+ if (Development::isEnabled()) {
+ return;
+ }
+
$cache = \Piwik\Tracker\Cache::getCacheGeneral();
if (array_key_exists('staticCache', $cache)) {
self::$staticCache = $cache['staticCache'];
diff --git a/core/Config.php b/core/Config.php
index 1f91d554f0..80c1d71c94 100644
--- a/core/Config.php
+++ b/core/Config.php
@@ -143,6 +143,7 @@ class Config extends Singleton
$this->configCache['Tracker'] = $this->configGlobal['Tracker'];
$this->configCache['Deletelogs'] = $this->configGlobal['Deletelogs'];
$this->configCache['Deletereports'] = $this->configGlobal['Deletereports'];
+ $this->configCache['Development'] = $this->configGlobal['Development'];
}
// for unit tests, we set that no plugin is installed. This will force
diff --git a/core/Development.php b/core/Development.php
new file mode 100644
index 0000000000..880b55ea83
--- /dev/null
+++ b/core/Development.php
@@ -0,0 +1,85 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+
+namespace Piwik;
+
+use \Exception;
+
+/**
+ * Development related checks and tools
+ */
+class Development
+{
+ private static $isEnabled = null;
+
+ /**
+ * Returns `true` if segmentation is allowed for this user, `false` if otherwise.
+ *
+ * @return bool
+ * @api
+ */
+ public static function isEnabled()
+ {
+ if (is_null(self::$isEnabled)) {
+ self::$isEnabled = (bool) Config::getInstance()->General['development_mode'];
+ }
+
+ return self::$isEnabled;
+ }
+
+ public static function methodExists($classOrInstance, $method)
+ {
+ if (is_string($classOrInstance)) {
+ return class_exists($classOrInstance) && method_exists($classOrInstance, $method);
+ }
+
+ return method_exists($classOrInstance, $method);
+ }
+
+ public static function formatMethodCall($classOrInstance, $method)
+ {
+ if (is_object($classOrInstance)) {
+ $classOrInstance = get_class($classOrInstance);
+ }
+
+ return $classOrInstance . '::' . $method . '()';
+ }
+
+ public static function checkMethodIsCallable($classOrInstance, $method, $prefixMessageIfError)
+ {
+ if (!self::isEnabled()) {
+ return;
+ }
+
+ if (!self::methodExists($classOrInstance, $method)) {
+ self::error($prefixMessageIfError . ' "' . self::formatMethodCall($classOrInstance, $method) . '" does not exist. Please make sure to define such a method.');
+ }
+
+ if (!self::isCallableMethod($classOrInstance, $method)) {
+ self::error($prefixMessageIfError . ' "' . self::formatMethodCall($classOrInstance, $method) . '" is not callable. Please make sure to method is public');
+
+ }
+ }
+
+ public static function isCallableMethod($classOrInstance, $method)
+ {
+ if (!self::methodExists($classOrInstance, $method)) {
+ return false;
+ }
+
+ $reflection = new \ReflectionMethod($classOrInstance, $method);
+ return $reflection->isPublic();
+ }
+
+ public static function error($message)
+ {
+ $message .= ' (This error is only triggered in development mode. Your plugin still works when development mode is disabled but will lead in an error at some point. We highly recommend to fix this issue!)';
+ throw new Exception($message);
+ }
+}
diff --git a/core/Plugin/Widgets.php b/core/Plugin/Widgets.php
index db69c6e794..0895b9ca01 100644
--- a/core/Plugin/Widgets.php
+++ b/core/Plugin/Widgets.php
@@ -8,6 +8,7 @@
*/
namespace Piwik\Plugin;
+use Piwik\Development;
use Piwik\Plugin\Manager as PluginManager;
use Piwik\WidgetsList;
@@ -57,6 +58,8 @@ class Widgets
protected function addWidgetWithCustomCategory($category, $name, $method, $parameters = array())
{
+ $this->checkIsValidWidget($name, $method);
+
$this->widgets[] = array('category' => $category,
'name' => $name,
'params' => $parameters,
@@ -130,4 +133,38 @@ class Widgets
return $widgetContainer;
}
+
+ private function checkIsValidWidget($name, $method)
+ {
+ if (!Development::isEnabled()) {
+ return;
+ }
+
+ if (empty($name)) {
+ Development::error('No name is defined for added widget having method "' . $method . '" in ' . get_class($this));
+ }
+
+ if (Development::isCallableMethod($this, $method)) {
+ return;
+ }
+
+ $controllerClass = '\\Piwik\\Plugins\\' . $this->module . '\\Controller';
+
+ if (!Development::methodExists($this, $method) &&
+ !Development::methodExists($controllerClass, $method)) {
+ Development::error('The added method "' . $method . '" neither exists in "' . get_class($this) . '" nor "' . $controllerClass . '". Make sure to define such a method.');
+ }
+
+ $definedInClass = get_class($this);
+
+ if (Development::methodExists($controllerClass, $method)) {
+ if (Development::isCallableMethod($controllerClass, $method)) {
+ return;
+ }
+
+ $definedInClass = $controllerClass;
+ }
+
+ Development::error('The method "' . $method . '" is not callable on "' . $definedInClass . '". Make sure the method is public.');
+ }
}
diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php
index a75f80635a..0efc6e8a03 100644
--- a/core/Tracker/Visit.php
+++ b/core/Tracker/Visit.php
@@ -81,8 +81,6 @@ class Visit implements VisitInterface
*/
public function handle()
{
- Log::warning('handle');
-
// the IP is needed by isExcluded() and GoalManager->recordGoals()
$this->visitorInfo['location_ip'] = $this->request->getIp();
diff --git a/core/Updates/2.5.0-b1.php b/core/Updates/2.5.0-b1.php
index e300cd8a0a..2cd297f7db 100644
--- a/core/Updates/2.5.0-b1.php
+++ b/core/Updates/2.5.0-b1.php
@@ -8,6 +8,7 @@
*/
namespace Piwik\Updates;
+use Piwik\Config;
use Piwik\Plugin\Dimension\ActionDimension;
use Piwik\Plugin\Dimension\ConversionDimension;
use Piwik\Plugin\Dimension\VisitDimension;
@@ -18,6 +19,25 @@ class Updates_2_5_0_b1 extends Updates
{
public static function update()
{
+ self::updateConfig();
+ self::markDimensionsAsInstalled();
+ }
+
+ private static function updateConfig()
+ {
+ $config = Config::getInstance();
+ $debug = $config->Debug;
+
+ if (array_key_exists('disable_merged_assets', $debug)) {
+ $development = $config->Development;
+ $development['disable_merged_assets'] = $debug['disable_merged_assets'];
+ $config->Development = $development;
+ $config->forceSave();
+ }
+ }
+
+ private static function markDimensionsAsInstalled()
+ {
foreach (VisitDimension::getAllDimensions() as $dimension) {
if ($dimension->getColumnName()) {
$component = 'log_visit.' . $dimension->getColumnName();
diff --git a/plugins/ExamplePlugin/javascripts/plugin.js b/plugins/ExamplePlugin/javascripts/plugin.js
index 7c082d4826..1a0d0dee7a 100644
--- a/plugins/ExamplePlugin/javascripts/plugin.js
+++ b/plugins/ExamplePlugin/javascripts/plugin.js
@@ -10,7 +10,7 @@ $(document).ready(function () {
* Please note that this JavaScript file will be loaded only if you
* enable the following setting in your config:
*
- * [Debug]
+ * [Development]
* disable_merged_assets = 1
*/
diff --git a/tests/PHPUnit/Core/AssetManager/configs/merged-assets-disabled.ini.php b/tests/PHPUnit/Core/AssetManager/configs/merged-assets-disabled.ini.php
index 00887b8c52..610d020da1 100644
--- a/tests/PHPUnit/Core/AssetManager/configs/merged-assets-disabled.ini.php
+++ b/tests/PHPUnit/Core/AssetManager/configs/merged-assets-disabled.ini.php
@@ -1,2 +1,2 @@
-[Debug]
+[Development]
disable_merged_assets = 1
diff --git a/tests/PHPUnit/Core/AssetManager/configs/merged-assets-enabled.ini.php b/tests/PHPUnit/Core/AssetManager/configs/merged-assets-enabled.ini.php
index df10787203..69a1facd8a 100644
--- a/tests/PHPUnit/Core/AssetManager/configs/merged-assets-enabled.ini.php
+++ b/tests/PHPUnit/Core/AssetManager/configs/merged-assets-enabled.ini.php
@@ -1,2 +1,2 @@
-[Debug]
+[Development]
disable_merged_assets = 0