forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptUpdated.php
More file actions
94 lines (80 loc) · 2.6 KB
/
ScriptUpdated.php
File metadata and controls
94 lines (80 loc) · 2.6 KB
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
<?php
namespace ProcessMaker\Events;
use Illuminate\Foundation\Events\Dispatchable;
use ProcessMaker\Contracts\SecurityLogEventInterface;
use ProcessMaker\Helpers\ArrayHelper;
use ProcessMaker\Models\Script;
use ProcessMaker\Models\ScriptCategory;
use ProcessMaker\Traits\FormatSecurityLogChanges;
class ScriptUpdated implements SecurityLogEventInterface
{
use Dispatchable;
use FormatSecurityLogChanges;
private array $changes;
private array $original;
private Script $script;
public const REMOVE_KEYS = [
'script_category_id',
'tmp_script_category_id',
];
/**
* Create a new event instance.
*
* @param Script $script
* @param array $changes
* @param array $original
*/
public function __construct(Script $script, array $changes, array $original)
{
$this->script = $script;
$this->changes = $changes;
$this->original = $original;
// Get category name
$this->original['script_category'] = isset($original['tmp_script_category_id'])
? ScriptCategory::getNamesByIds($this->original['tmp_script_category_id']) : '';
$this->changes['script_category'] = isset($changes['tmp_script_category_id'])
? ScriptCategory::getNamesByIds($this->changes['tmp_script_category_id']) : '';
$this->changes = array_diff_key($this->changes, array_flip($this::REMOVE_KEYS));
$this->original = array_diff_key($this->original, array_flip($this::REMOVE_KEYS));
if (empty($this->changes['script_category'])) {
$this->original['script_category'] = '';
}
}
/**
* Get specific changes without format related to the event
*
* @return array
*/
public function getChanges(): array
{
return [
'script_id' => $this->script->id,
];
}
/**
* Get specific data related to the event
*
* @return array
*/
public function getData(): array
{
unset($this->changes['code']);
unset($this->original['code']);
$linkName = [
'label' => $this->script->getAttribute('title'),
'link' => route('scripts.index'),
];
return array_merge(
[
'name' => $linkName,
'script_name' => $this->script->getAttribute('title'),
'last_modified' => $this->script->getAttribute('updated_at'),
],
ArrayHelper::getArrayDifferencesWithFormat($this->changes, $this->original)
);
}
public function getEventName(): string
{
return 'ScriptUpdated';
}
}