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
path: root/core
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 /core
parent3a8aa4a5198b4f0b917ff72fbd32d14896c8fd67 (diff)
added development flag which allows us to not cache static cache and to make some more checks when developers develop plugins
Diffstat (limited to 'core')
-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
8 files changed, 150 insertions, 6 deletions
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();