forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExporter.php
More file actions
90 lines (73 loc) · 2.46 KB
/
Exporter.php
File metadata and controls
90 lines (73 loc) · 2.46 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
<?php
namespace ProcessMaker\ImportExport;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use ProcessMaker\ImportExport\Exporters\ProcessExporter;
use ProcessMaker\ImportExport\Exporters\ScreenExporter;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\Screen;
class Exporter
{
private $manifest;
private $options;
private $rootExporter;
public function __construct(
public bool $skipHidden = false,
public bool $ignoreExplicitDiscard = false)
{
}
public function export(Model $model, string $exporterClass, Options $options = null)
{
$this->options = $options ?: new Options([]);
$this->manifest = new Manifest();
$this->rootExporter = new $exporterClass($model, $this->manifest, $this->options, $this->ignoreExplicitDiscard);
$this->manifest->push($model->uuid, $this->rootExporter);
$this->rootExporter->runExport();
return $this->rootExporter;
}
public function exportScreen(Screen $screen)
{
return $this->export($screen, ScreenExporter::class);
}
public function exportProcess(Process $process)
{
return $this->export($process, ProcessExporter::class);
}
public function payload(): array
{
$this->manifest->runAfterExport();
$export = $this->manifest->toArray($this->skipHidden);
$payload = [
'type' => $this->rootExporter->getExportType(),
'version' => '2',
'root' => $this->rootExporter->uuid(),
'name' => $this->rootExporter->getName($this->rootExporter->model),
'export' => $export,
// 'discarded' => $discarded,
];
return $payload;
}
public function encrypt($password, $payload)
{
return (new ExportEncrypted($password))->call($payload);
}
public function exportInfo(array $manifest): string
{
$exported = collect($manifest['export'])
->groupBy(function ($item) {
return $item['type'];
})
->map(function ($group) {
$item = $group[0];
return [
'name' => $item['type_human'],
'name_plural' => $item['type_human_plural'],
'ids' => $group->pluck('attributes.id'),
];
});
return json_encode([
'exported' => $exported,
'name' => $manifest['name'],
]);
}
}