1 | <?php |
||
17 | class DeployManager |
||
18 | { |
||
19 | |||
20 | const SORT_PRIORITY_KEY = 'magento-deploy-sort-priority'; |
||
21 | |||
22 | /** |
||
23 | * @var Entry[] |
||
24 | */ |
||
25 | protected $packages = array(); |
||
26 | |||
27 | /** |
||
28 | * @var IOInterface |
||
29 | */ |
||
30 | protected $io; |
||
31 | |||
32 | /** |
||
33 | * an array with package names as key and priorities as value |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $sortPriority = array(); |
||
38 | |||
39 | /** |
||
40 | * @var EventManager |
||
41 | */ |
||
42 | protected $eventManager; |
||
43 | |||
44 | /** |
||
45 | * @param EventManager $eventManager |
||
46 | */ |
||
47 | 6 | public function __construct(EventManager $eventManager) |
|
51 | |||
52 | /** |
||
53 | * @param Entry $package |
||
54 | */ |
||
55 | 1 | public function addPackage(Entry $package) |
|
59 | |||
60 | /** |
||
61 | * @param $priorities |
||
62 | */ |
||
63 | 5 | public function setSortPriority($priorities) |
|
67 | |||
68 | /** |
||
69 | * uses the sortPriority Array to sort the packages. |
||
70 | * Highest priority first. |
||
71 | * Copy gets per default higher priority then others |
||
72 | */ |
||
73 | 1 | protected function sortPackages() |
|
74 | { |
||
75 | 1 | $sortPriority = $this->sortPriority; |
|
76 | $getPriorityValue = function (Entry $object) use ($sortPriority) { |
||
77 | 1 | $result = 100; |
|
78 | 1 | if (isset($sortPriority[$object->getPackageName()])) { |
|
79 | $result = $sortPriority[$object->getPackageName()]; |
||
80 | 1 | } elseif ($object->getDeployStrategy() instanceof Copy) { |
|
81 | $result = 101; |
||
82 | } |
||
83 | 1 | return $result; |
|
84 | 1 | }; |
|
85 | 1 | usort( |
|
86 | 1 | $this->packages, |
|
87 | 1 | function ($a, $b) use ($getPriorityValue) { |
|
88 | /** @var Entry $a */ |
||
89 | /** @var Entry $b */ |
||
90 | 1 | $aVal = $getPriorityValue($a); |
|
91 | 1 | $bVal = $getPriorityValue($b); |
|
92 | 1 | if ($aVal == $bVal) { |
|
93 | 1 | return 0; |
|
94 | } |
||
95 | return ($aVal > $bVal) ? -1 : 1; |
||
96 | 1 | } |
|
97 | ); |
||
98 | 1 | } |
|
99 | |||
100 | /** |
||
101 | * Deploy all the queued packages |
||
102 | */ |
||
103 | 1 | public function doDeploy() |
|
104 | { |
||
105 | 1 | $this->sortPackages(); |
|
106 | /** @var Entry $package */ |
||
107 | 1 | foreach ($this->packages as $package) { |
|
108 | 1 | $this->eventManager->dispatch(new PackageDeployEvent('pre-package-deploy', $package)); |
|
109 | 1 | $package->getDeployStrategy()->deploy(); |
|
110 | 1 | $this->eventManager->dispatch(new PackageDeployEvent('post-package-deploy', $package)); |
|
111 | } |
||
112 | 1 | } |
|
113 | |||
114 | /** |
||
115 | * @return Deploy\Manager\Entry[] |
||
116 | */ |
||
117 | public function getEntries() |
||
121 | } |
||
122 |