replaceDashboardWidgets() public static method

It uses the given widget definitions to find the old and to create the new widgets Each widget is defined with an array containing the following information array ( 'module' => string 'action' => string 'params' => array() ) if $newWidget does not contain a widget definition at the current position, the old widget will simply be removed
public static replaceDashboardWidgets ( $dashboardLayout, array $oldWidgets, array $newWidgets )
$oldWidgets array array containing widget definitions
$newWidgets array array containing widget definitions
Beispiel #1
0
 public function getMigrations(Updater $updater)
 {
     $migrations = array('# ATTENTION: This update script will execute some more SQL queries than that below as it is necessary to rebuilt some archives #' => false);
     // update scheduled reports to use new plugin
     $reportsToReplace = array('UserSettings_getBrowserVersion' => 'DevicesDetection_getBrowserVersions', 'UserSettings_getBrowser' => 'DevicesDetection_getBrowsers', 'UserSettings_getOSFamily' => 'DevicesDetection_getOsFamilies', 'UserSettings_getOS' => 'DevicesDetection_getOsVersions', 'UserSettings_getMobileVsDesktop' => 'DevicesDetection_getType', 'UserSettings_getBrowserType' => 'DevicesDetection_getBrowserEngines', 'UserSettings_getWideScreen' => 'UserSettings_getScreenType');
     $reportTable = Common::prefixTable('report');
     foreach ($reportsToReplace as $old => $new) {
         $migrations[] = $this->migration->db->sql("UPDATE {$reportTable} SET reports = REPLACE(reports, '" . $old . "', '" . $new . "')");
     }
     // update dashboard to use new widgets
     $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')));
     $dashboardTable = Common::prefixTable('user_dashboard');
     $dashboardQuery = "UPDATE {$dashboardTable} SET layout = ? WHERE iddashboard = ?";
     foreach ($allDashboards as $dashboard) {
         $dashboardLayout = json_decode($dashboard['layout']);
         $dashboardLayout = DashboardModel::replaceDashboardWidgets($dashboardLayout, $oldWidgets, $newWidgets);
         $newLayout = json_encode($dashboardLayout);
         if ($newLayout != $dashboard['layout']) {
             $migrations[] = $this->migration->db->boundSql($dashboardQuery, array($newLayout, $dashboard['iddashboard']));
         }
     }
     return $migrations;
 }
 public static function getSql()
 {
     $sqls = array();
     // update dashboard to use new ecommerce widgets, they were moved from goals plugin to ecommerce
     $oldWidgets = array(array('module' => 'Goals', 'action' => 'getEcommerceLog', 'params' => array()), array('module' => 'Goals', 'action' => 'widgetGoalReport', 'params' => array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER)));
     $newWidgets = array(array('module' => 'Ecommerce', 'action' => 'getEcommerceLog', 'params' => array()), array('module' => 'Ecommerce', 'action' => 'widgetGoalReport', 'params' => array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER)));
     $allDashboards = Db::get()->fetchAll(sprintf("SELECT * FROM %s", Common::prefixTable('user_dashboard')));
     foreach ($allDashboards as $dashboard) {
         $dashboardLayout = json_decode($dashboard['layout']);
         $dashboardLayout = DashboardModel::replaceDashboardWidgets($dashboardLayout, $oldWidgets, $newWidgets);
         $newLayout = json_encode($dashboardLayout);
         if ($newLayout != $dashboard['layout']) {
             $sqls["UPDATE " . Common::prefixTable('user_dashboard') . " SET layout = '" . addslashes($newLayout) . "' WHERE iddashboard = " . $dashboard['iddashboard']] = false;
         }
     }
     return $sqls;
 }
Beispiel #3
0
 public function getMigrations(Updater $updater)
 {
     $migrations = array();
     // update dashboard to use new ecommerce widgets, they were moved from goals plugin to ecommerce
     $oldWidgets = array(array('module' => 'Goals', 'action' => 'getEcommerceLog', 'params' => array()), array('module' => 'Goals', 'action' => 'widgetGoalReport', 'params' => array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER)));
     $newWidgets = array(array('module' => 'Ecommerce', 'action' => 'getEcommerceLog', 'params' => array()), array('module' => 'Ecommerce', 'action' => 'widgetGoalReport', 'params' => array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER)));
     $allDashboards = Db::get()->fetchAll(sprintf("SELECT * FROM %s", Common::prefixTable('user_dashboard')));
     $sql = "UPDATE " . Common::prefixTable('user_dashboard') . " SET layout = ? WHERE iddashboard = ?";
     foreach ($allDashboards as $dashboard) {
         $dashboardLayout = json_decode($dashboard['layout']);
         $dashboardLayout = DashboardModel::replaceDashboardWidgets($dashboardLayout, $oldWidgets, $newWidgets);
         $newLayout = json_encode($dashboardLayout);
         if ($newLayout != $dashboard['layout']) {
             $migrations[] = $this->migration->db->boundSql($sql, array($newLayout, $dashboard['iddashboard']));
         }
     }
     $migrations[] = $this->migration->plugin->activate('Ecommerce');
     return $migrations;
 }
Beispiel #4
0
 private function getDashboardMigrations($allDashboards, $allGoals)
 {
     $sqls = array();
     // update dashboard to use new widgets
     $oldWidgets = array(array('module' => 'VisitTime', 'action' => 'getVisitInformationPerServerTime', 'params' => array()), array('module' => 'VisitTime', 'action' => 'getVisitInformationPerLocalTime', 'params' => array()), array('module' => 'VisitTime', 'action' => 'getByDayOfWeek', 'params' => array()), array('module' => 'VisitsSummary', 'action' => 'getEvolutionGraph', 'params' => array('columns' => array('nb_visits'))), array('module' => 'VisitsSummary', 'action' => 'getSparklines', 'params' => array()), array('module' => 'VisitsSummary', 'action' => 'index', 'params' => array()), array('module' => 'Live', 'action' => 'getVisitorLog', 'params' => array('small' => 1)), array('module' => 'VisitorInterest', 'action' => 'getNumberOfVisitsPerVisitDuration', 'params' => array()), array('module' => 'VisitorInterest', 'action' => 'getNumberOfVisitsPerPage', 'params' => array()), array('module' => 'VisitFrequency', 'action' => 'getSparklines', 'params' => array()), array('module' => 'VisitFrequency', 'action' => 'getEvolutionGraph', 'params' => array('columns' => array('nb_visits_returning'))), array('module' => 'DevicesDetection', 'action' => 'getBrowserEngines', 'params' => array()), array('module' => 'Referrers', 'action' => 'getReferrerType', 'params' => array()), array('module' => 'Referrers', 'action' => 'getAll', 'params' => array()), array('module' => 'Referrers', 'action' => 'getSocials', 'params' => array()), array('module' => 'Goals', 'action' => 'widgetGoalsOverview', 'params' => array()), array('module' => 'Goals', 'action' => 'getItemsSku', 'params' => array()), array('module' => 'Goals', 'action' => 'getItemsName', 'params' => array()), array('module' => 'Goals', 'action' => 'getItemsCategory', 'params' => array()), array('module' => 'Ecommerce', 'action' => 'widgetGoalReport', 'params' => array('idGoal' => 'ecommerceOrder')));
     foreach ($allGoals as $goal) {
         $oldWidgets[] = array('module' => 'Goals', 'action' => 'widgetGoalReport', 'params' => array('idGoal' => (int) $goal['idgoal']));
     }
     $newWidgets = array(array('module' => 'VisitTime', 'action' => 'getVisitInformationPerServerTime', 'params' => array()), array('module' => 'VisitTime', 'action' => 'getVisitInformationPerLocalTime', 'params' => array()), array('module' => 'VisitTime', 'action' => 'getByDayOfWeek', 'params' => array()), array('module' => 'VisitsSummary', 'action' => 'getEvolutionGraph', 'params' => array('forceView' => '1', 'viewDataTable' => 'graphEvolution')), array('module' => 'VisitsSummary', 'action' => 'get', 'params' => array('forceView' => '1', 'viewDataTable' => 'sparklines')), array('module' => 'CoreHome', 'action' => 'renderWidgetContainer', 'uniqueId' => 'widgetVisitOverviewWithGraph', 'params' => array('containerId' => 'VisitOverviewWithGraph')), array('module' => 'Live', 'action' => 'getLastVisitsDetails', 'params' => array('forceView' => '1', 'viewDataTable' => 'VisitorLog', 'small' => '1')), array('module' => 'VisitorInterest', 'action' => 'getNumberOfVisitsPerVisitDuration', 'params' => array()), array('module' => 'VisitorInterest', 'action' => 'getNumberOfVisitsPerPage', 'params' => array()), array('module' => 'VisitFrequency', 'action' => 'get', 'params' => array('forceView' => '1', 'viewDataTable' => 'sparklines')), array('module' => 'VisitFrequency', 'action' => 'getEvolutionGraph', 'params' => array('forceView' => 1, 'viewDataTable' => 'graphEvolution')), array('module' => 'DevicesDetection', 'action' => 'getBrowserEngines', 'params' => array()), array('module' => 'Referrers', 'action' => 'getReferrerType', 'params' => array()), array('module' => 'Referrers', 'action' => 'getAll', 'params' => array()), array('module' => 'Referrers', 'action' => 'getSocials', 'params' => array()), array('module' => 'CoreHome', 'action' => 'renderWidgetContainer', 'uniqueId' => 'widgetGoalsOverview', 'params' => array('containerId' => 'GoalsOverview')), array('module' => 'Goals', 'action' => 'getItemsSku', 'params' => array()), array('module' => 'Goals', 'action' => 'getItemsName', 'params' => array()), array('module' => 'Goals', 'action' => 'getItemsCategory', 'params' => array()), array('module' => 'CoreHome', 'action' => 'renderWidgetContainer', 'uniqueId' => 'widgetEcommerceOverview', 'params' => array('containerId' => 'EcommerceOverview')));
     foreach ($allGoals as $goal) {
         $newWidgets[] = array('module' => 'CoreHome', 'action' => 'renderWidgetContainer', 'uniqueId' => 'widgetGoal_' . (int) $goal['idgoal'], 'params' => array('containerId' => 'Goal_' . (int) $goal['idgoal']));
     }
     $table = Common::prefixTable('user_dashboard');
     $sql = sprintf('UPDATE %s SET layout = ? WHERE iddashboard = ?', $table);
     foreach ($allDashboards as $dashboard) {
         $dashboardLayout = json_decode($dashboard['layout']);
         $dashboardLayout = Dashboard\Model::replaceDashboardWidgets($dashboardLayout, $oldWidgets, $newWidgets);
         $newLayout = json_encode($dashboardLayout);
         if ($newLayout != $dashboard['layout']) {
             $sqls[] = $this->migration->db->boundSql($sql, array($newLayout, $dashboard['iddashboard']));
         }
     }
     return $sqls;
 }