|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NerdsAndCompany\Schematic\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Craft; |
|
6
|
|
|
use craft\helpers\FileHelper; |
|
7
|
|
|
use NerdsAndCompany\Schematic\Models\Data; |
|
8
|
|
|
use NerdsAndCompany\Schematic\Schematic; |
|
9
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Schematic Export Controller. |
|
13
|
|
|
* |
|
14
|
|
|
* Sync Craft Setups. |
|
15
|
|
|
* |
|
16
|
|
|
* @author Nerds & Company |
|
17
|
|
|
* @copyright Copyright (c) 2015-2018, Nerds & Company |
|
18
|
|
|
* @license MIT |
|
19
|
|
|
* |
|
20
|
|
|
* @see http://www.nerds.company |
|
21
|
|
|
*/ |
|
22
|
|
|
class ExportController extends Base |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Exports the Craft datamodel. |
|
26
|
|
|
* |
|
27
|
|
|
* @param string $file file to write the schema to |
|
|
|
|
|
|
28
|
|
|
* @param array $exclude Data to not export |
|
|
|
|
|
|
29
|
|
|
* |
|
30
|
|
|
* @return int |
|
31
|
|
|
*/ |
|
32
|
|
|
public function actionIndex(): int |
|
33
|
|
|
{ |
|
34
|
|
|
$dataTypes = $this->getDataTypes(); |
|
35
|
|
|
|
|
36
|
|
|
$this->exportToYaml($this->file, $dataTypes); |
|
37
|
|
|
Schematic::info('Exported schema to '.$this->file); |
|
38
|
|
|
|
|
39
|
|
|
return 0; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Export to Yaml file. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $file |
|
46
|
|
|
* @param bool $autoCreate |
|
|
|
|
|
|
47
|
|
|
*/ |
|
48
|
|
|
public function exportToYaml($file, $dataTypes): void |
|
49
|
|
|
{ |
|
50
|
|
|
$this->disableLogging(); |
|
51
|
|
|
$result = []; |
|
52
|
|
|
foreach ($dataTypes as $dataTypeHandle) { |
|
53
|
|
|
$dataType = $this->module->getDataType($dataTypeHandle); |
|
54
|
|
|
if (null == $dataType) { |
|
55
|
|
|
continue; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$mapper = $dataType->getMapperHandle(); |
|
59
|
|
|
if (!$this->module->checkMapper($mapper)) { |
|
60
|
|
|
continue; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
Schematic::info('Exporting '.$dataTypeHandle); |
|
64
|
|
|
$records = $dataType->getRecords(); |
|
65
|
|
|
$result[$dataTypeHandle] = $this->module->$mapper->export($records); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
FileHelper::writeToFile($file, Data::toYaml($result)); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.