11<?php
22/**
3- *
4- *
5- *
6- *
3+ *
4+ *
5+ *
6+ *
77 */
88
99namespace MagentoHackathon \Composer \Magento ;
1313use MagentoHackathon \Composer \Magento \Deploy \Manager \Entry ;
1414use MagentoHackathon \Composer \Magento \Deploystrategy \Copy ;
1515
16- class DeployManager {
16+ class DeployManager
17+ {
1718
1819 /**
1920 * @var Entry[]
@@ -27,29 +28,44 @@ class DeployManager {
2728
2829 /**
2930 * an array with package names as key and priorities as value
30- *
31+ *
3132 * @var array
3233 */
3334 protected $ sortPriority = array ();
34-
35-
36- public function __construct ( IOInterface $ io )
35+
36+ /**
37+ * @var Installer
38+ */
39+ private $ installer ;
40+
41+ public function __construct (IOInterface $ io )
3742 {
3843 $ this ->io = $ io ;
3944 }
40-
41-
42- public function addPackage ( Entry $ package )
45+
46+
47+ public function addPackage (Entry $ package )
4348 {
4449 $ this ->packages [] = $ package ;
4550 }
46-
47- public function setSortPriority ( $ priorities )
51+
52+ public function setSortPriority ($ priorities )
4853 {
4954 $ this ->sortPriority = $ priorities ;
5055 }
5156
5257
58+ public function setInstaller (Installer $ installer )
59+ {
60+ $ this ->installer = $ installer ;
61+ }
62+
63+ public function getInstaller ()
64+ {
65+ return $ this ->installer ;
66+ }
67+
68+
5369 /**
5470 * uses the sortPriority Array to sort the packages.
5571 * Highest priority first.
@@ -58,18 +74,18 @@ public function setSortPriority( $priorities )
5874 protected function sortPackages ()
5975 {
6076 $ sortPriority = $ this ->sortPriority ;
61- $ getPriorityValue = function ( Entry $ object ) use ( $ sortPriority ) {
77+ $ getPriorityValue = function ( Entry $ object ) use ($ sortPriority) {
6278 $ result = 100 ;
63- if ( isset ($ sortPriority [$ object ->getPackageName ()]) ) {
79+ if ( isset ($ sortPriority [$ object ->getPackageName ()])) {
6480 $ result = $ sortPriority [$ object ->getPackageName ()];
65- }elseif ( $ object ->getDeployStrategy () instanceof Copy ) {
81+ } elseif ( $ object ->getDeployStrategy () instanceof Copy) {
6682 $ result = 101 ;
6783 }
6884 return $ result ;
6985 };
70- usort (
71- $ this ->packages ,
72- function ($ a , $ b )use ( $ getPriorityValue ) {
86+ usort (
87+ $ this ->packages ,
88+ function ($ a , $ b ) use ( $ getPriorityValue) {
7389 /** @var Entry $a */
7490 /** @var Entry $b */
7591 $ aVal = $ getPriorityValue ($ a );
@@ -81,18 +97,36 @@ function($a, $b)use( $getPriorityValue ){
8197 }
8298 );
8399 }
84-
85-
86- public function doDeploy ()
100+
101+
102+ public function doDeploy ($ installedLocalPackages = array () )
87103 {
88104 $ this ->sortPackages ();
105+ $ packageCount = count ($ this ->packages );
106+ $ installedLocalPackagesCount = count ($ installedLocalPackages );
107+ $ installedPackages = [];
108+
89109 /** @var Entry $package */
90- foreach ( $ this ->packages as $ package ) {
91- if ( $ this ->io ->isDebug () ) {
92- $ this ->io ->write ('start magento deploy for ' . $ package ->getPackageName () );
110+ foreach ( $ this ->packages as $ package) {
111+ if ( $ this ->io ->isDebug ()) {
112+ $ this ->io ->write ('start magento deploy for ' . $ package ->getPackageName ());
93113 }
94114 $ package ->getDeployStrategy ()->deploy ();
115+ $ installedPackages [$ package ->getPackageName ()] = $ package ->getPackageName ();
95116 }
96- }
117+ if (!empty ($ installedLocalPackages ) && $ packageCount !== $ installedLocalPackagesCount ) {
118+ $ packageTypes = PackageTypes::$ packageTypes ;
119+ foreach ($ installedLocalPackages as $ package ) {
120+ if (!isset ($ installedPackages [$ package ->getName ()]) && isset ($ packageTypes [$ package ->getType ()])) {
121+ if ($ this ->io ->isDebug ()) {
122+ $ this ->io ->write ('Updating missing packages ' . $ package ->getName ());
123+ }
124+ $ strategy = $ this ->getInstaller ()->getDeployStrategy ($ package );
125+ $ strategy ->setMappings ($ this ->getInstaller ()->getParser ($ package )->getMappings ());
126+ $ strategy ->deploy ();
127+ }
128+ }
97129
130+ }
131+ }
98132}
0 commit comments