|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kaliop\eZMigrationBundle\Core\Executor; |
|
4
|
|
|
|
|
5
|
|
|
use Kaliop\eZMigrationBundle\API\Exception\InvalidStepDefinitionException; |
|
6
|
|
|
use Kaliop\eZMigrationBundle\API\Value\MigrationStep; |
|
7
|
|
|
use Kaliop\eZMigrationBundle\API\ExecutorInterface; |
|
8
|
|
|
|
|
9
|
|
|
abstract class AbstractExecutor implements ExecutorInterface |
|
10
|
|
|
{ |
|
11
|
|
|
protected $supportedStepTypes = array(); |
|
12
|
96 |
|
|
|
13
|
|
|
public function supportedTypes() |
|
14
|
96 |
|
{ |
|
15
|
|
|
return $this->supportedStepTypes; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* IT IS MANDATORY TO OVERRIDE THIS IN SUBCLASSES |
|
20
|
|
|
* @param MigrationStep $step |
|
21
|
|
|
* @return mixed |
|
22
|
|
|
* @throws InvalidStepDefinitionException |
|
23
|
47 |
|
*/ |
|
24
|
|
|
public function execute(MigrationStep $step) |
|
25
|
47 |
|
{ |
|
26
|
|
|
if (!in_array($step->type, $this->supportedStepTypes)) { |
|
27
|
|
|
throw new InvalidStepDefinitionException("Something is wrong! Executor can not work on step of type '{$step->type}'"); |
|
28
|
47 |
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Allows to have refs defined using two syntax variants: |
|
33
|
|
|
* - { identifier: xxx, attribute: yyy, overwrite: bool } |
|
34
|
|
|
* or |
|
35
|
|
|
* identifier: attribute |
|
36
|
|
|
* @param $key |
|
37
|
|
|
* @param $value |
|
38
|
|
|
* @return array |
|
39
|
|
|
* @throws InvalidStepDefinitionException |
|
40
|
|
|
* |
|
41
|
|
|
* @todo move to a referenceSetter trait ? |
|
42
|
|
|
* @todo should we resolve references in ref identifiers, attributes and overwrite? Inception! :-D |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function parseReferenceDefinition($key, $value) |
|
45
|
|
|
{ |
|
46
|
|
|
if (is_string($key) && is_string($value)) { |
|
47
|
|
|
return array('identifier' => $key, 'attribute' => $value); |
|
48
|
|
|
} |
|
49
|
|
|
if (!is_array($value) || !isset($value['identifier']) || ! isset($value['attribute'])) { |
|
50
|
|
|
throw new InvalidStepDefinitionException("Invalid reference definition for reference number $key"); |
|
51
|
|
|
} |
|
52
|
|
|
return $value; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|