diff options
author | sgiehl <stefan@piwik.org> | 2014-11-22 00:36:14 +0300 |
---|---|---|
committer | sgiehl <stefan@piwik.org> | 2014-11-22 00:36:14 +0300 |
commit | 26188f9bdaa257a7608d0de2cfbde420dcf917dd (patch) | |
tree | 6974896befbf5735ae1bfe053e41bad9208c8c53 | |
parent | 802eb983fba10ed3698be0d2028620964029c8d9 (diff) |
added update sql to update existing dashboards to use new widgets (if they are not already placed on it)
-rw-r--r-- | core/Updates/2.10.0-b1.php | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/core/Updates/2.10.0-b1.php b/core/Updates/2.10.0-b1.php index f35f1fd7aa..1464962984 100644 --- a/core/Updates/2.10.0-b1.php +++ b/core/Updates/2.10.0-b1.php @@ -47,6 +47,7 @@ class Updates_2_10_0_b1 extends Updates { $sqls = 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', @@ -61,6 +62,63 @@ class Updates_2_10_0_b1 extends Updates $sqls["UPDATE " . Common::prefixTable('report') . " SET reports = REPLACE(reports, '".$old."', '".$new."')"] = false; } + // 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'), + ); + + $allDashboards = Db::get()->fetchAll(sprintf("SELECT * FROM %s", Common::prefixTable('user_dashboard'))); + + foreach($allDashboards AS $dashboard) { + + $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; + + $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; } @@ -151,8 +209,8 @@ class Updates_2_10_0_b1 extends Updates // if start date of blob is before calculated date us old usersettings archive instead of already existing DevicesDetection archive if (strtotime($blob['date1']) < self::getFirstDayOfArchivedDeviceDetectorData()) { - Db::get()->query(sprintf("DELETE FROM %s WHERE id_archive = ? AND name = ?", $table), array($blob['id_archive'], 'DevicesDetection_browserVersions')); - Db::get()->query(sprintf("UPDATE %s SET name = ? WHERE id_archive = ? AND name = ?", $table), array('DevicesDetection_browserVersions', $blob['id_archive'], 'UserSettings_browser')); + Db::get()->query(sprintf("DELETE FROM %s WHERE idarchive = ? AND name = ?", $table), array($blob['idarchive'], 'DevicesDetection_browserVersions')); + Db::get()->query(sprintf("UPDATE %s SET name = ? WHERE idarchive = ? AND name = ?", $table), array('DevicesDetection_browserVersions', $blob['idarchive'], 'UserSettings_browser')); } } @@ -176,8 +234,8 @@ class Updates_2_10_0_b1 extends Updates // if start date of blob is before calculated date us old usersettings archive instead of already existing DevicesDetection archive if (strtotime($blob['date1']) < self::getFirstDayOfArchivedDeviceDetectorData()) { - Db::get()->query(sprintf("DELETE FROM %s WHERE id_archive = ? AND name = ?", $table), array($blob['id_archive'], 'DevicesDetection_osVersions')); - Db::get()->query(sprintf("UPDATE %s SET name = ? WHERE id_archive = ? AND name = ?", $table), array('DevicesDetection_osVersions', $blob['id_archive'], 'UserSettings_os')); + Db::get()->query(sprintf("DELETE FROM %s WHERE idarchive = ? AND name = ?", $table), array($blob['idarchive'], 'DevicesDetection_osVersions')); + Db::get()->query(sprintf("UPDATE %s SET name = ? WHERE idarchive = ? AND name = ?", $table), array('DevicesDetection_osVersions', $blob['idarchive'], 'UserSettings_os')); } } |