Skip to content

Commit

Permalink
add reportwidgets, system_settings and system_files migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin committed Apr 24, 2021
1 parent 5019b02 commit 07d4d8c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
56 changes: 56 additions & 0 deletions updates/v2.0.0/convert_data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php namespace Winter\GoogleAnalytics\Updates;

use Db;
use Backend\Models\UserPreference;
use Winter\Storm\Database\Updates\Migration;

class ConvertData extends Migration
{
public function up()
{
Db::table('system_files')
->where('attachment_type', 'RainLab\GoogleAnalytics\Models\Settings')
->update(['attachment_type' => 'Winter\GoogleAnalytics\Models\Settings']);

Db::table('system_settings')
->where('item', 'rainlab_googleanalytics_settings')
->update(['item' => 'winter_googleanalytics_settings']);

$records = UserPreference::where('namespace', 'backend')->where('group', 'reportwidgets')->get();

foreach ($records as $record) {
$data = $record->value;
foreach ($data as $widget => &$widgetDetails) {
if (starts_with($widgetDetails['class'], 'RainLab\\GoogleAnalytics')) {
$widgetDetails['class'] = str_replace('RainLab\\', 'Winter\\', $widgetDetails['class']);
}
}
$record->value = $data;
$record->save();
}
}

public function down()
{
Db::table('system_files')
->where('attachment_type', 'Winter\GoogleAnalytics\Models\Settings')
->update(['attachment_type' => 'RainLab\GoogleAnalytics\Models\Settings']);

Db::table('system_settings')
->where('item', 'winter_googleanalytics_settings')
->update(['item' => 'rainlab_googleanalytics_settings']);

$records = UserPreference::where('namespace', 'backend')->where('group', 'reportwidgets')->get();

foreach ($records as $record) {
$data = $record->value;
foreach ($data as $widget => &$widgetDetails) {
if (starts_with($widgetDetails['class'], 'Winter\\GoogleAnalytics')) {
$widgetDetails['class'] = str_replace('Winter\\', 'RainLab\\', $widgetDetails['class']);
}
}
$record->value = $data;
$record->save();
}
}
}
4 changes: 3 additions & 1 deletion updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
"1.2.5": "Fixed issues with PHP 7.4 compatibility."
"1.3.0": "!!! Upgraded tracker code to Universal Analytics (gtag.js)"
"1.3.1": "!!! Package renamed to rainlab/googleanalytics-plugin"
"2.0.0": "Rebrand to Winter.GoogleAnalytics"
"2.0.0":
- "Rebrand to Winter.GoogleAnalytics"
- v2.0.0/convert_data.php

0 comments on commit 07d4d8c

Please sign in to comment.