1 | <?php |
||
21 | class ImportController extends Base |
||
22 | { |
||
23 | public $force = false; |
||
24 | |||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | * |
||
28 | * @return array |
||
29 | */ |
||
30 | public function options($actionID): array |
||
31 | { |
||
32 | return array_merge(parent::options($actionID), ['force']); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Imports the Craft datamodel. |
||
37 | * |
||
38 | * @return int |
||
39 | */ |
||
40 | public function actionIndex(): int |
||
41 | { |
||
42 | if (!file_exists($this->path)) { |
||
43 | Schematic::error('Directory not found: ' . $this->path); |
||
44 | |||
45 | return 1; |
||
46 | } |
||
47 | |||
48 | $dataTypes = $this->getDataTypes(); |
||
49 | $this->importFromYaml($dataTypes); |
||
50 | Schematic::info('Loaded schema from '.$this->path); |
||
51 | |||
52 | return 0; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Import from Yaml file. |
||
57 | * |
||
58 | * @param array $dataTypes The data types to import |
||
59 | * @throws \Exception |
||
60 | */ |
||
61 | private function importFromYaml(array $dataTypes) |
||
62 | { |
||
63 | $this->disableLogging(); |
||
64 | |||
65 | <<<<<<< Updated upstream |
||
|
|||
66 | $yamlOverride = null; |
||
67 | if (file_exists($this->overrideFile)) { |
||
68 | $yamlOverride = file_get_contents($this->overrideFile); |
||
69 | } |
||
70 | |||
71 | // Grab all yaml files in the schema directory. |
||
72 | $schemaFiles = preg_grep('~\.(yml)$~', scandir($this->path)); |
||
73 | |||
74 | // Read contents of each file and add it to the definitions. |
||
75 | foreach ($schemaFiles as $fileName) { |
||
76 | $schemaStructure = explode('.', $this->fromSafeFileName($fileName)); |
||
77 | $dataTypeHandle = $schemaStructure[0]; |
||
78 | $recordName = $schemaStructure[1]; |
||
79 | |||
80 | $contents = file_get_contents($this->path . $fileName); |
||
81 | |||
82 | $definitions[$dataTypeHandle][$recordName] = Data::fromYaml($contents, $yamlOverride); |
||
83 | } |
||
84 | ======= |
||
85 | // Parse data in the overrideFile if available. |
||
86 | $overrideData = Data::parseYamlFile($this->overrideFile); |
||
87 | |||
88 | // Grab all yaml files in the schema directory. |
||
89 | $schemaFiles = preg_grep('~\.(yml)$~', scandir($this->path)); |
||
90 | |||
91 | // Read contents of each file and add it to the definitions. |
||
92 | foreach ($schemaFiles as $fileName) { |
||
93 | $schemaStructure = explode('.', $this->fromSafeFileName($fileName)); |
||
94 | $dataTypeHandle = $schemaStructure[0]; |
||
95 | $recordName = $schemaStructure[1]; |
||
96 | |||
97 | $definition = Data::fromYaml(file_get_contents($this->path . $fileName)); |
||
136 |