|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kaliop\eZMigrationBundle\Core\DefinitionParser; |
|
4
|
|
|
|
|
5
|
|
|
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition; |
|
6
|
|
|
use Kaliop\eZMigrationBundle\API\Value\MigrationStep; |
|
7
|
|
|
|
|
8
|
|
|
class AbstractDefinitionParser |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Parses a migration definition in the form of an array of steps |
|
12
|
|
|
* |
|
13
|
|
|
* @param array $data |
|
14
|
|
|
* @param MigrationDefinition $definition |
|
15
|
|
|
* @param string $format |
|
16
|
|
|
* @return MigrationDefinition |
|
17
|
|
|
*/ |
|
18
|
|
|
protected function parseMigrationDefinitionData($data, MigrationDefinition $definition, $format = 'Yaml') |
|
19
|
|
|
{ |
|
20
|
|
|
// basic validation |
|
21
|
|
|
|
|
22
|
|
|
/// @todo move to using the Validator component... |
|
23
|
|
|
|
|
24
|
|
|
$status = MigrationDefinition::STATUS_PARSED; |
|
25
|
|
|
|
|
26
|
|
|
if (!is_array($data)) { |
|
|
|
|
|
|
27
|
|
|
$status = MigrationDefinition::STATUS_INVALID; |
|
28
|
|
|
$message = "$format migration file '{$definition->path}' must contain an array as top element"; |
|
29
|
|
|
} else { |
|
30
|
|
|
foreach ($data as $i => $stepDef) { |
|
31
|
|
|
if (!isset($stepDef['type']) || !is_string($stepDef['type'])) { |
|
32
|
|
|
$status = MigrationDefinition::STATUS_INVALID; |
|
33
|
|
|
$message = "$format migration file '{$definition->path}' misses or has a non-string 'type' element in step $i"; |
|
34
|
|
|
break; |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
if ($status != MigrationDefinition::STATUS_PARSED) |
|
40
|
|
|
{ |
|
41
|
|
|
return new MigrationDefinition( |
|
42
|
|
|
$definition->name, |
|
43
|
|
|
$definition->path, |
|
44
|
|
|
$definition->rawDefinition, |
|
45
|
|
|
$status, |
|
46
|
|
|
array(), |
|
47
|
|
|
$message |
|
|
|
|
|
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$stepDefs = array(); |
|
52
|
|
|
foreach ($data as $stepDef) { |
|
53
|
|
|
$type = $stepDef['type']; |
|
54
|
|
|
unset($stepDef['type']); |
|
55
|
|
|
$stepDefs[] = new MigrationStep($type, $stepDef, array('path' => $definition->path)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return new MigrationDefinition( |
|
59
|
|
|
$definition->name, |
|
60
|
|
|
$definition->path, |
|
61
|
|
|
$definition->rawDefinition, |
|
62
|
|
|
MigrationDefinition::STATUS_PARSED, |
|
63
|
|
|
$stepDefs |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|