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
|
132 |
|
protected function parseMigrationDefinitionData($data, MigrationDefinition $definition, $format = 'Yaml') |
19
|
|
|
{ |
20
|
|
|
// basic validation |
21
|
|
|
|
22
|
|
|
/// @todo move to using the Validator component... |
23
|
|
|
|
24
|
132 |
|
$status = MigrationDefinition::STATUS_PARSED; |
25
|
|
|
|
26
|
132 |
|
if (!is_array($data)) { |
|
|
|
|
27
|
1 |
|
$status = MigrationDefinition::STATUS_INVALID; |
28
|
1 |
|
$message = "$format migration file '{$definition->path}' must contain an array as top element"; |
29
|
|
|
} else { |
30
|
131 |
|
foreach ($data as $i => $stepDef) { |
31
|
128 |
|
if (!isset($stepDef['type']) || !is_string($stepDef['type'])) { |
32
|
2 |
|
$status = MigrationDefinition::STATUS_INVALID; |
33
|
2 |
|
$message = "$format migration file '{$definition->path}' misses or has a non-string 'type' element in step $i"; |
34
|
2 |
|
break; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
132 |
|
if ($status != MigrationDefinition::STATUS_PARSED) |
40
|
|
|
{ |
41
|
3 |
|
return new MigrationDefinition( |
42
|
3 |
|
$definition->name, |
43
|
3 |
|
$definition->path, |
44
|
3 |
|
$definition->rawDefinition, |
45
|
|
|
$status, |
46
|
3 |
|
array(), |
47
|
|
|
$message |
|
|
|
|
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
129 |
|
$stepDefs = array(); |
52
|
129 |
|
foreach ($data as $stepDef) { |
53
|
126 |
|
$type = $stepDef['type']; |
54
|
126 |
|
unset($stepDef['type']); |
55
|
126 |
|
$stepDefs[] = new MigrationStep($type, $stepDef, array('path' => $definition->path)); |
56
|
|
|
} |
57
|
|
|
|
58
|
129 |
|
return new MigrationDefinition( |
59
|
129 |
|
$definition->name, |
60
|
129 |
|
$definition->path, |
61
|
129 |
|
$definition->rawDefinition, |
62
|
129 |
|
MigrationDefinition::STATUS_PARSED, |
63
|
|
|
$stepDefs |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|