diff options
author | sgiehl <stefan@piwik.org> | 2014-11-22 22:39:27 +0300 |
---|---|---|
committer | sgiehl <stefan@piwik.org> | 2014-11-22 22:39:27 +0300 |
commit | 776584c2ab945bf5496f502f0e53c63e1a70a004 (patch) | |
tree | 7ff652356b5e7520b6627c273ec9d02e8cc213cf /core | |
parent | 26188f9bdaa257a7608d0de2cfbde420dcf917dd (diff) |
moved logic for replacing a dashboard widget to dashboard model
Diffstat (limited to 'core')
-rw-r--r-- | core/Updates/2.10.0-b1.php | 61 | ||||
-rw-r--r-- | core/WidgetsList.php | 33 |
2 files changed, 44 insertions, 50 deletions
diff --git a/core/Updates/2.10.0-b1.php b/core/Updates/2.10.0-b1.php index 1464962984..0cc0629826 100644 --- a/core/Updates/2.10.0-b1.php +++ b/core/Updates/2.10.0-b1.php @@ -16,6 +16,7 @@ use Piwik\Db; use Piwik\Updater; use Piwik\Updates; use DeviceDetector\Parser\Client\Browser AS BrowserParser; +use Piwik\Plugins\Dashboard\Model AS DashboardModel; /** * This Update script will update all browser and os archives of UserSettings and DevicesDetection plugin @@ -63,14 +64,24 @@ class Updates_2_10_0_b1 extends Updates } // update dashboard to use new widgets - $widgetsToReplace = array( - 'widgetUserSettingsgetBrowserVersion' => array('module' => 'DevicesDetection', 'action' => 'getBrowserVersions'), - 'widgetUserSettingsgetBrowser' => array('module' => 'DevicesDetection', 'action' => 'getBrowsers'), - 'widgetUserSettingsgetOSFamily' => array('module' => 'DevicesDetection', 'action' => 'getOsFamilies'), - 'widgetUserSettingsgetOS' => array('module' => 'DevicesDetection', 'action' => 'getOsVersions'), - 'widgetUserSettingsgetMobileVsDesktop' => array('module' => 'DevicesDetection', 'action' => 'getType'), - 'widgetUserSettingsgetBrowserType' => array('module' => 'DevicesDetection', 'action' => 'getBrowserEngines'), - 'widgetUserSettingsgetWideScreen' => array('module' => 'UserSettings', 'action' => 'getScreenType'), + $oldWidgets = array( + array('module' => 'UserSettings', 'action' => 'getBrowserVersion', 'params' => array()), + array('module' => 'UserSettings', 'action' => 'getBrowser', 'params' => array()), + array('module' => 'UserSettings', 'action' => 'getOSFamily', 'params' => array()), + array('module' => 'UserSettings', 'action' => 'getOS', 'params' => array()), + array('module' => 'UserSettings', 'action' => 'getMobileVsDesktop', 'params' => array()), + array('module' => 'UserSettings', 'action' => 'getBrowserType', 'params' => array()), + array('module' => 'UserSettings', 'action' => 'getWideScreen', 'params' => array()), + ); + + $newWidgets = array( + array('module' => 'DevicesDetection', 'action' => 'getBrowserVersions', 'params' => array()), + array('module' => 'DevicesDetection', 'action' => 'getBrowsers', 'params' => array()), + array('module' => 'DevicesDetection', 'action' => 'getOsFamilies', 'params' => array()), + array('module' => 'DevicesDetection', 'action' => 'getOsVersions', 'params' => array()), + array('module' => 'DevicesDetection', 'action' => 'getType', 'params' => array()), + array('module' => 'DevicesDetection', 'action' => 'getBrowserEngines', 'params' => array()), + array('module' => 'UserSettings', 'action' => 'getScreenType', 'params' => array()), ); $allDashboards = Db::get()->fetchAll(sprintf("SELECT * FROM %s", Common::prefixTable('user_dashboard'))); @@ -79,39 +90,7 @@ class Updates_2_10_0_b1 extends Updates $dashboardLayout = json_decode($dashboard['layout']); - $newColumns = array(); - - foreach ($dashboardLayout->columns as $id => $column) { - - $newColumn = array(); - - foreach ($column as $widget) { - - foreach ($widgetsToReplace AS $oldWidgetId => $newParameters) { - - if ($widget->uniqueId == $oldWidgetId) { - - $newWidgetId = 'widget'.$newParameters['module'].$newParameters['action']; - - // is new widget already is on dashboard just remove the old one - if (strpos($dashboard['layout'], $newWidgetId) !== false) { - continue 2; - } - - $widget->uniqueId = $newWidgetId; - $widget->parameters->module = $newParameters['module']; - $widget->parameters->action = $newParameters['action']; - } - } - - - $newColumn[] = $widget; - } - - $newColumns[] = $newColumn; - } - - $dashboardLayout->columns = $newColumns; + $dashboardLayout = DashboardModel::replaceDashboardWidgets($dashboardLayout, $oldWidgets, $newWidgets); $newLayout = json_encode($dashboardLayout); if ($newLayout != $dashboard['layout']) { diff --git a/core/WidgetsList.php b/core/WidgetsList.php index e67f6b1b77..943dfceb68 100644 --- a/core/WidgetsList.php +++ b/core/WidgetsList.php @@ -159,18 +159,15 @@ class WidgetsList extends Singleton } /** - * Adds a report to the list of dashboard widgets. + * Returns the unique id of an widget with the given parameters * - * @param string $widgetCategory The widget category. This can be a translation token. - * @param string $widgetName The name of the widget. This can be a translation token. - * @param string $controllerName The report's controller name (same as the plugin name). - * @param string $controllerAction The report's controller action method name. - * @param array $customParameters Extra query parameters that should be sent while getting - * this report. + * @param $controllerName + * @param $controllerAction + * @param array $customParameters + * @return string */ - public static function add($widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters = array()) + public static function getWidgetUniqueId($controllerName, $controllerAction, $customParameters = array()) { - $widgetName = Piwik::translate($widgetName); $widgetUniqueId = 'widget' . $controllerName . $controllerAction; foreach ($customParameters as $name => $value) { @@ -182,6 +179,24 @@ class WidgetsList extends Singleton $widgetUniqueId .= $name . $value; } + return $widgetUniqueId; + } + + /** + * Adds a report to the list of dashboard widgets. + * + * @param string $widgetCategory The widget category. This can be a translation token. + * @param string $widgetName The name of the widget. This can be a translation token. + * @param string $controllerName The report's controller name (same as the plugin name). + * @param string $controllerAction The report's controller action method name. + * @param array $customParameters Extra query parameters that should be sent while getting + * this report. + */ + public static function add($widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters = array()) + { + $widgetName = Piwik::translate($widgetName); + $widgetUniqueId = self::getWidgetUniqueId($controllerName, $controllerAction, $customParameters); + if (!array_key_exists($widgetCategory, self::$widgets)) { self::$widgets[$widgetCategory] = array(); } |