This repository has been archived by the owner on Jan 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
SystemSeeder.php
86 lines (73 loc) · 2.84 KB
/
SystemSeeder.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
<?php
use DemocracyApps\GB\Services\JsonProcessor;
use DemocracyApps\GB\Sites\Component;
use DemocracyApps\GB\Sites\Layout;
use Illuminate\Database\Seeder;
class SystemSeeder extends Seeder
{
public function run()
{
$jp = new JsonProcessor();
// Read the layouts directory
$path = base_path()."/resources/definitions/layouts";
$lFiles = scandir($path);
foreach ($lFiles as $file) {
\Log::info("Importing layout from " . $file);
if (ends_with ($file, '.json')) {
echo "Importing layout from " . $file . PHP_EOL;
$s = file_get_contents("$path/$file");
$str = $jp->minifyJson($s);
$cfig = $jp->decodeJson($str, true);
if ( ! $cfig) {
throw new \Exception("Error parsing layout file " . $file);
}
$layout = new Layout();
if (array_key_exists('name', $cfig)) {
$layout->name = $cfig['name'];
}
else {
$layout->name = $file;
}
$layout->specification = $s;
if (array_key_exists('description', $cfig)) {
$layout->description = $cfig['description'];
}
$layout->owner = 1;
$layout->type = Layout::BOOTSTRAP;
$layout->public = true;
$layout->save();
}
}
// Read the components directory
$path = base_path()."/resources/definitions/components";
$lFiles = scandir($path);
foreach ($lFiles as $file) {
\Log::info("Importing component from " . $file);
if (ends_with ($file, '.json')) {
echo "Importing component from " . $file . PHP_EOL;
$s = file_get_contents("$path/$file");
$str = $jp->minifyJson($s);
$cfig = $jp->decodeJson($str, true);
if ( ! $cfig) {
throw new \Exception("Error parsing component file " . $file);
}
$c = new Component();
if (array_key_exists('name', $cfig)) {
$c->name = $cfig['name'];
}
else {
$c->name = $file;
}
if (array_key_exists('description', $cfig)) {
$c->description = $cfig['description'];
}
$c->owner = 1;
$c->type = Component::SYSTEM;
$c->setProperty('data', $cfig['data']);
if (array_key_exists('props', $cfig)) $c->setProperty('props', $cfig['props']);
if (array_key_exists('state', $cfig)) $c->setProperty('state', $cfig['state']);
$c->save();
}
}
}
}