-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSchemaCommandController.php
More file actions
121 lines (103 loc) · 3.99 KB
/
SchemaCommandController.php
File metadata and controls
121 lines (103 loc) · 3.99 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
namespace Flowpack\SchemaOrg\NodeTypes\Command;
/* *
* This script belongs to the Neos Flow package "Flowpack.SchemaOrg.NodeTypes". *
* */
use Flowpack\SchemaOrg\NodeTypes\Domain\Model\NodeType;
use Flowpack\SchemaOrg\NodeTypes\Service\ConfigurationService;
use Flowpack\SchemaOrg\NodeTypes\Service\NodeTypeBuilder;
use Flowpack\SchemaOrg\NodeTypes\Service\SchemaParserService;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController;
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
use Neos\ContentRepository\Exception\NodeTypeNotFoundException;
/**
* Schema.org Schema Extraction CLI
*/
class SchemaCommandController extends CommandController
{
/**
* @Flow\Inject
* @var SchemaParserService
*/
protected $schemaParserService;
/**
* @Flow\Inject
* @var NodeTypeManager
*/
protected $nodeTypeManager;
/**
* @Flow\Inject
* @var NodeTypeBuilder
*/
protected $nodeTypeBuilder;
/**
* @Flow\Inject
* @var ConfigurationService
*/
protected $configurationService;
/**
* @Flow\InjectConfiguration("schemas.jsonFilename")
* @var string
*/
protected $jsonSchema;
/**
* @Flow\InjectConfiguration(path="fallbackNodeType",package="Neos.ContentRepository")
* @var string
*/
protected $fallbackNodeTypeName;
/**
* Extract Schema.org to build NodeTypes configuration
*
* @param string $name The name of the file
* @param string $packageKey The package key
* @param string $type The Type from schema.org
*/
public function extractCommand($name = null, $packageKey = null, $type = null)
{
try {
$name = $name ?: 'Default';
$this->configurationService->setPackageKey($packageKey);
$this->outputLine();
$this->outputFormatted('# Extracting schema.org ...');
$this->schemaParserService->setAllSchemaJsonFilename($this->jsonSchema);
if ($type !== null) {
$nodeTypes = $this->schemaParserService->parseByTypes(explode(',', $type));
} else {
$nodeTypes = $this->schemaParserService->parseAll();
}
$filename = 'NodeTypes.SchemaOrg.' . $name . '.yaml';
$this->nodeTypeBuilder
->setFilename($filename)
->unlinkExistingFile();
$success = $error = 0;
foreach ($nodeTypes as $nodeType) {
/** @var NodeType $nodeType */
$this->outputLine('+ <b>' . $nodeType->getName() . '</b>');
try {
$existingNodeType = $this->nodeTypeManager->getNodeType($nodeType->getName());
if ($existingNodeType->getName() === $this->fallbackNodeTypeName) {
throw new NodeTypeNotFoundException();
}
$this->outputFormatted(' - <b>NodeType "%s" skipped</b>, update is not supported ...', [$existingNodeType->getName()]);
++$error;
} catch (NodeTypeNotFoundException $exception) {
$filename = $this->nodeTypeBuilder->dump($nodeType);
++$success;
}
}
$this->outputLine();
if ($success > 0) {
$this->outputFormatted('The following file contain your new NodeType: ' . $filename);
} else {
$this->outputFormatted('Nothing to do ...');
}
$this->outputLine();
$this->outputFormatted('We are on Github, Pull request welcome or open an issue if you have trouble ...');
} catch (\InvalidArgumentException $exception) {
$this->outputLine();
$this->outputFormatted($exception->getMessage());
$this->sendAndExit(1);
}
}
}