-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Version315.php
80 lines (58 loc) · 2.04 KB
/
Version315.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
<?php
namespace App\Listeners\Update\V31;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Common\Widget;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
class Version315 extends Listener
{
const ALIAS = 'core';
const VERSION = '3.1.5';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
if ($this->skipThisUpdate($event)) {
return;
}
Log::channel('stdout')->info('Updating to 3.1.5 version...');
$this->updateWidgets();
Log::channel('stdout')->info('Done!');
}
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 (! empty($widget_settings->raw_width)) {
Log::channel('stdout')->info('Already new classs widget:' . $widget->id);
continue;
}
unset($widget_settings->raw_width);
if (Str::contains($widget_settings->width, 'lg:w-1/4')) {
$widget_settings->width = 25;
} elseif (Str::contains($widget_settings->width, 'lg:w-1/3')) {
$widget_settings->width = 33;
} elseif (Str::contains($widget_settings->width, 'lg:w-2/4')) {
$widget_settings->width = 50;
} else {
$widget_settings->width = 100;
}
$widget->settings = $widget_settings;
$widget->save();
Log::channel('stdout')->info('Widget updated:' . $widget->id);
}
Log::channel('stdout')->info('Widgets updated.');
}
}