From 43dba3823264090d0e5d6e03d94870bc41ebdc7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Thu, 23 Jun 2022 15:33:35 +0300 Subject: [PATCH] closed #2478 Fixed: Upgrading dashboard widget old with class ( #32gvmup ) --- app/Listeners/Update/V30/Version303.php | 107 ++++++++++++++++++++++++ app/Providers/Event.php | 1 + 2 files changed, 108 insertions(+) create mode 100644 app/Listeners/Update/V30/Version303.php diff --git a/app/Listeners/Update/V30/Version303.php b/app/Listeners/Update/V30/Version303.php new file mode 100644 index 000000000..a2edb582f --- /dev/null +++ b/app/Listeners/Update/V30/Version303.php @@ -0,0 +1,107 @@ +skipThisUpdate($event)) { + return; + } + + Log::channel('stderr')->info('Starting the Akaunting 3.0.3 update...'); + + $this->updateCompanies(); + + Log::channel('stderr')->info('Akaunting 3.0.3 update finished.'); + } + + public function updateCompanies() + { + Log::channel('stderr')->info('Updating companies...'); + + $company_id = company_id(); + + $companies = Company::cursor(); + + foreach ($companies as $company) { + Log::channel('stderr')->info('Updating company:' . $company->id); + + $company->makeCurrent(); + + $this->updateWidgets(); + + Log::channel('stderr')->info('Company updated:' . $company->id); + } + + company($company_id)->makeCurrent(); + + Log::channel('stderr')->info('Companies updated.'); + } + + public function updateWidgets() + { + Log::channel('stderr')->info('Updating widgets...'); + + $widgets = Widget::cursor(); + + foreach ($widgets as $widget) { + Log::channel('stderr')->info('Updating widget:' . $widget->id); + + $widget_settings = $widget->settings; + + if (empty($widget_settings->width)) { + Log::channel('stderr')->info('Skip widget:' . $widget->id); + + continue; + } + + if (Str::contains($widget_settings->width, 'w-full')) { + Log::channel('stderr')->info('Already new classs widget:' . $widget->id); + + continue; + } + + switch ($widget_settings->width) { + case 'col-md-3': + $widget_settings->width = 'w-full lg:w-1/4 px-6'; + break; + case 'col-md-4': + $widget_settings->width = 'w-full lg:w-1/3 px-6'; + break; + case 'col-md-6': + $widget_settings->width = 'w-full lg:w-2/4 px-12'; + break; + case 'col-md-12': + $widget_settings->width = 'w-full px-12'; + break; + } + + $widget->settings = $widget_settings; + + $widget->save(); + + Log::channel('stderr')->info('Widget updated:' . $widget->id); + } + + Log::channel('stderr')->info('Widgets updated.'); + } +} diff --git a/app/Providers/Event.php b/app/Providers/Event.php index 832bae905..0e9351031 100644 --- a/app/Providers/Event.php +++ b/app/Providers/Event.php @@ -16,6 +16,7 @@ class Event extends Provider 'App\Listeners\Update\CreateModuleUpdatedHistory', 'App\Listeners\Module\UpdateExtraModules', 'App\Listeners\Update\V30\Version300', + 'App\Listeners\Update\V30\Version303', ], 'Illuminate\Auth\Events\Login' => [ 'App\Listeners\Auth\Login',