-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathImportScreen.php
More file actions
114 lines (97 loc) · 3.28 KB
/
ImportScreen.php
File metadata and controls
114 lines (97 loc) · 3.28 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace ProcessMaker\Jobs;
use ProcessMaker\Managers\ExportManager;
use ProcessMaker\Models\Screen;
use ProcessMaker\Models\Script;
class ImportScreen extends ImportProcess
{
/**
* Parse files with version 1
*
* @return array
*/
private function parseFileV1()
{
$this->file->screens = [$this->file->screens];
return $this->parseFileV2();
}
private function findWatcherScripts($screens)
{
foreach ($screens as $screen) {
if (isset($screen->watchers) && is_array($screen->watchers)) {
foreach ($screen->watchers as $watcher) {
if (is_array($watcher)) {
if (isset($watcher['script_id']) && is_array($watcher['script'])) {
$watcher['script']['id'] = explode('-', $watcher['script']['id'])[1];
$this->file->scripts[] = (object) $watcher['script'];
}
}
}
}
}
}
/**
* Parse files with version 2
*
* @return array
*/
private function parseFileV2()
{
$new = [Screen::class => []];
$this->prepareStatus('screens', count($this->file->screens));
foreach ($this->file->screens as $screen) {
$newScreen = $this->saveScreen($screen);
$this->status['screens']['id'] = $newScreen->id;
$new[Screen::class][$screen->id] = $newScreen;
//determine if the screen has watchers
if (property_exists($screen, 'watchers')) {
$names = [];
if ($screen->watchers) {
foreach ($screen->watchers as $watcher) {
$names[] = $watcher->name;
}
$this->status['screens']['info'] = __('Please assign a run script user to: ') . implode(', ', $names);
}
}
}
$this->finishStatus('screens');
if (!isset($this->file->scripts)) {
$this->findWatcherScripts($new[Screen::class]);
}
if (isset($this->file->scripts)) {
$this->prepareStatus('scripts', count($this->file->screens));
foreach ($this->file->scripts as $script) {
$newScript = $this->saveScript($script);
$this->status['scripts']['id'] = $newScript->id;
$new[Script::class][$script->id] = $newScript;
}
$this->finishStatus('scripts');
}
$manager = app(ExportManager::class);
$manager->updateReferences($new);
return $this->status;
}
/**
* Execute the job.
*
* @return bool
*/
public function handle()
{
//First, decode the file
$this->decodeFile();
//Then, process it based on version number
if ($this->file->type === 'screen_package') {
if ($method = $this->getParser()) {
$this->status = [];
$this->status['screens'] = [
'label' => __('Screens'),
'success' => false,
'message' => __('Starting'), ];
return $this->{$method}();
}
}
//Return false by default
return false;
}
}