-
Notifications
You must be signed in to change notification settings - Fork 10
/
ProcessRockMigrations.module.php
164 lines (145 loc) · 5.13 KB
/
ProcessRockMigrations.module.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
namespace ProcessWire;
/**
* @author Bernhard Baumrock, 11.02.2024
* @license Licensed under MIT
* @link https://www.baumrock.com
*/
class ProcessRockMigrations extends Process
{
public static function getModuleInfo()
{
return [
'title' => 'RockMigrations GUI',
'version' => json_decode(file_get_contents(__DIR__ . "/package.json"))->version,
'requires' => [
'RockMigrations',
],
'icon' => 'magic',
'permission' => 'superuser',
'page' => [
'name' => 'rockmigrations',
'parent' => 'setup',
'title' => 'RockMigrations',
],
// saved for later :)
// 'nav' => [
// [
// 'url' => 'once/',
// 'label' => 'Once',
// 'icon' => 'calendar',
// ]
// ]
];
}
public function execute()
{
$this->wire->session->redirect("./once/");
}
public function executeOnce()
{
$this->headline('Migrations "once" History');
$this->browserTitle('Migrations "once" History');
/** @var InputfieldForm $form */
$form = $this->wire->modules->get('InputfieldForm');
$rm = rockmigrations();
$table = "<table class='uk-table uk-table-small uk-table-striped'>";
$table .= "<tr>
<th>Executed</th>
<th>Key</th>
<th>Actions</th>
</tr>";
// bd($rm->getOnceHistory());
foreach ($rm->getOnceHistory() as $key => $item) {
$data = new WireData();
if (is_array($item)) $data->setArray($item);
$hash = base64_encode($key);
$key = substr($key, 8);
$time = (int)$data->time;
$table .= "<tr>
<td class='uk-text-nowrap'>"
. date('Y-m-d', $time)
. " <small>" . date('H:i:s', $time) . "</small>"
. "<div class='uk-text-muted'><small>" . wireRelativeTimeStr($time, true) . "</small></div>"
. "</td>
<td class='uk-width-expand'>
{$key}
<div class='uk-text-small uk-text-muted' style='margin-top:3px;'>{$data->file}</div>
</td>
<td class='uk-text-center'>
<a
class='uk-button uk-button-small uk-button-default'
href='../once-clear-item?hash=$hash'
><i class='fa fa-trash-o'></i></a>
</td>
</tr>";
}
$table .= "<tr><td colspan=3 class='uk-text-center'>
<a href='../once-clear-all' class='uk-button uk-button-small uk-button-default'><i class='fa fa-trash-o'></i> Clear All</a>
</td></tr>";
$table .= "</table>";
$form->add([
'type' => 'markup',
'label' => 'Table',
'value' => "<div class='uk-overflow-auto'>$table</div>",
]);
return $form->render();
}
public function executeOnceClearAll()
{
// Check if confirmation has been given
if ($this->wire->input->get->confirm == 1) {
$this->wire->cache->delete("rm:once|*");
$this->wire->session->redirect("./once/");
}
$this->headline('Clear all once-caches');
$this->browserTitle('Clear all once-caches');
/** @var InputfieldForm $form */
$form = $this->wire->modules->get('InputfieldForm');
$form->action = "?confirm=1";
$form->add([
'type' => 'markup',
'label' => 'Are you sure?',
'value' => "If the caches are deleted, migrations wrapped in the once() callback with previously used keys will be executed again upon the next modules refresh, as the system will have lost the record of their initial execution. This could lead to unintended consequences or duplicate actions if those migrations were intended to run only once.",
'icon' => 'question-circle-o',
]);
// Add a submit button if confirmation has not been given
$form->add([
'type' => 'submit',
'value' => 'Delete all caches',
'icon' => 'trash',
]);
return $form->render();
}
public function executeOnceClearItem()
{
$hash = $this->wire->input->get('hash', 'string');
if (!$hash) $this->wire->session->redirect('./once/');
$key = base64_decode($hash);
// Check if confirmation has been given
if ($this->wire->input->get->confirm == 1) {
// $data = $this->wire->cache->get($key);
$this->wire->cache->delete($key);
// $this->wire->cache->save("$key (deleted @ " . date("Y-m-d H:i:s") . ")", $data);
$this->wire->session->redirect("./once/");
}
$this->headline('Clear once-cache');
$this->browserTitle('Clear once-cache');
/** @var InputfieldForm $form */
$form = $this->wire->modules->get('InputfieldForm');
$form->action = "?hash=$hash&confirm=1";
$form->add([
'type' => 'markup',
'label' => "Are you sure?",
'value' => "If the cache is deleted, migrations wrapped in the once() callback with the given key will be executed again upon the next modules refresh, as the system will have lost the record of their initial execution. This could lead to unintended consequences or duplicate actions if those migrations were intended to run only once.",
'icon' => 'question-circle-o',
]);
// Add a submit button if confirmation has not been given
$form->add([
'type' => 'submit',
'value' => "Delete cache for $key",
'icon' => 'trash',
]);
return $form->render();
}
}