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:
authormattab <matthieu.aubry@gmail.com>2014-12-18 03:26:48 +0300
committermattab <matthieu.aubry@gmail.com>2014-12-18 03:26:48 +0300
commit04b462f31fa2a9b9552ea9b1d6bdc55b6ed2adf8 (patch)
tree93240aef9b5f4985bc30c132db563cf71ccded98 /core
parentd31e90e3b7f61dc64f449f4d9925c14897f611e6 (diff)
Fixes #6865 Introducing new event to let plugin define deprecated module and action
Diffstat (limited to 'core')
-rw-r--r--core/API/Request.php38
-rw-r--r--core/FrontController.php2
2 files changed, 28 insertions, 12 deletions
diff --git a/core/API/Request.php b/core/API/Request.php
index 23677e45fb..2d97ba6f41 100644
--- a/core/API/Request.php
+++ b/core/API/Request.php
@@ -135,6 +135,7 @@ class Request
{
$this->request = self::getRequestArrayFromString($request, $defaultRequest);
$this->sanitizeRequest();
+ $this->renameModuleAndActionInRequest();
}
/**
@@ -142,19 +143,23 @@ class Request
* we rewrite to correct renamed plugin: Referrers
*
* @param $module
- * @return string
+ * @param $action
+ * @return array( $module, $action )
* @ignore
*/
- public static function renameModule($module)
+ public static function getRenamedModuleAndAction($module, $action)
{
- $moduleToRedirect = array(
- 'Referers' => 'Referrers',
- 'PDFReports' => 'ScheduledReports',
- );
- if (isset($moduleToRedirect[$module])) {
- return $moduleToRedirect[$module];
- }
- return $module;
+ /**
+ * This event is posted in the Request dispatcher and can be used
+ * to overwrite the Module and Action to dispatch.
+ * This is useful when some Controller methods or API methods have been renamed or moved to another plugin.
+ *
+ * @param $module string
+ * @param $action string
+ */
+ Piwik::postEvent('Request.getRenamedModuleAndAction', array(&$module, &$action));
+
+ return array($module, $action);
}
/**
@@ -213,7 +218,7 @@ class Request
list($module, $method) = $this->extractModuleAndMethod($moduleMethod);
- $module = $this->renameModule($module);
+ list($module, $method) = $this->getRenamedModuleAndAction($module, $method);
if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated($module)) {
throw new PluginDeactivatedException($module);
@@ -412,4 +417,15 @@ class Request
}
return $segmentRaw;
}
+
+ private function renameModuleAndActionInRequest()
+ {
+ if (empty($this->request['apiModule'])) {
+ return;
+ }
+ if (empty($this->request['apiAction'])) {
+ $this->request['apiAction'] = null;
+ }
+ list($this->request['apiModule'], $this->request['apiAction']) = $this->getRenamedModuleAndAction($this->request['apiModule'], $this->request['apiAction']);
+ }
}
diff --git a/core/FrontController.php b/core/FrontController.php
index dbaf75e22c..f4ff833352 100644
--- a/core/FrontController.php
+++ b/core/FrontController.php
@@ -480,7 +480,7 @@ class FrontController extends Singleton
throw new Exception("Invalid module name '$module'");
}
- $module = Request::renameModule($module);
+ list($module, $action) = Request::getRenamedModuleAndAction($module, $action);
if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated($module)) {
throw new PluginDeactivatedException($module);