forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImporter.php
More file actions
62 lines (50 loc) · 1.72 KB
/
Importer.php
File metadata and controls
62 lines (50 loc) · 1.72 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
<?php
namespace ProcessMaker\ImportExport;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class Importer
{
public $options;
public $payload;
public $manifest;
public function __construct(array $payload, Options $options)
{
$this->payload = $payload;
$this->options = $options;
$this->manifest = $this->loadManifest();
}
public function previewImport()
{
return $this->manifest->toArray(true);
}
public function loadManifest()
{
return Manifest::fromArray($this->payload['export'], $this->options);
}
public function doImport($existingAssetInDatabase = null)
{
DB::transaction(function () use ($existingAssetInDatabase) {
// First, we save the model so we have IDs set for all assets
Schema::disableForeignKeyConstraints();
foreach ($this->manifest->all() as $exporter) {
if ($exporter->mode !== 'discard') {
if ($exporter->disableEventsWhenImporting) {
$exporter->model->saveQuietly();
} else {
$exporter->model->save();
}
$exporter->log('newId', $exporter->model->id);
}
}
Schema::enableForeignKeyConstraints();
// Now, run the import method in each Exporter class
foreach ($this->manifest->all() as $exporter) {
if ($exporter->mode !== 'discard') {
$exporter->runImport($existingAssetInDatabase);
}
}
$this->manifest->runAfterImport();
});
return $this->manifest->all();
}
}