-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Version303.php
107 lines (77 loc) · 2.77 KB
/
Version303.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace App\Listeners\Update\V30;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Common\Widget;
use App\Models\Common\Company;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
class Version303 extends Listener
{
const ALIAS = 'core';
const VERSION = '3.0.3';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
if ($this->skipThisUpdate($event)) {
return;
}
Log::channel('stdout')->info('Starting the Akaunting 3.0.3 update...');
$this->updateCompanies();
Log::channel('stdout')->info('Akaunting 3.0.3 update finished.');
}
public function updateCompanies()
{
Log::channel('stdout')->info('Updating companies...');
$company_id = company_id();
$companies = Company::cursor();
foreach ($companies as $company) {
Log::channel('stdout')->info('Updating company:' . $company->id);
$company->makeCurrent();
$this->updateWidgets();
Log::channel('stdout')->info('Company updated:' . $company->id);
}
company($company_id)->makeCurrent();
Log::channel('stdout')->info('Companies updated.');
}
public function updateWidgets()
{
Log::channel('stdout')->info('Updating widgets...');
$widgets = Widget::cursor();
foreach ($widgets as $widget) {
Log::channel('stdout')->info('Updating widget:' . $widget->id);
$widget_settings = $widget->settings;
if (empty($widget_settings->width)) {
Log::channel('stdout')->info('Skip widget:' . $widget->id);
continue;
}
if (Str::contains($widget_settings->width, 'w-full')) {
Log::channel('stdout')->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-6';
break;
case 'col-md-12':
$widget_settings->width = 'w-full px-6';
break;
}
$widget->settings = $widget_settings;
$widget->save();
Log::channel('stdout')->info('Widget updated:' . $widget->id);
}
Log::channel('stdout')->info('Widgets updated.');
}
}