55 */
66namespace Vaimo \ComposerPatches \Compatibility ;
77
8+ use Composer \Composer ;
9+ use Composer \Util \SyncHelper ;
10+ use React \Promise \Promise ;
11+ use Vaimo \ComposerPatches \Exceptions \OperationFailure ;
812use Vaimo \ComposerPatches \Patch \Definition as PatchDefinition ;
913use Composer \Repository \WritableRepositoryInterface ;
1014use Composer \DependencyResolver \Operation \InstallOperation ;
@@ -76,7 +80,8 @@ public function processReinstallOperation(
7680 WritableRepositoryInterface $ repository ,
7781 InstallationManager $ installationManager ,
7882 InstallOperation $ installOperation ,
79- UninstallOperation $ uninstallOperation
83+ UninstallOperation $ uninstallOperation ,
84+ Composer $ composer
8085 ) {
8186 if (version_compare (\Composer \Composer::VERSION , '2.0 ' , '< ' )) {
8287 return $ installationManager ->install ($ repository , $ installOperation );
@@ -85,12 +90,18 @@ public function processReinstallOperation(
8590 $ package = $ installOperation ->getPackage ();
8691 $ installer = $ installationManager ->getInstaller ($ package ->getType ());
8792
88- $ installationManager ->uninstall ($ repository , $ uninstallOperation );
93+ $ promise = $ installationManager ->uninstall ($ repository , $ uninstallOperation );
94+ if (!$ promise instanceof Promise) {
95+ throw new OperationFailure ("Uninstallation of {$ package ->getName ()} failed " );
96+ }
8997
90- return $ installer
91- ->download ($ package )
92- ->then (function () use ($ installationManager , $ installOperation , $ repository ) {
93- $ installationManager ->install ($ repository , $ installOperation );
94- });
98+ return $ promise ->then (static function () use ($ composer , $ installer , $ package ) {
99+ return SyncHelper::downloadAndInstallPackageSync (
100+ $ composer ->getLoop (),
101+ $ composer ->getDownloadManager (),
102+ $ installer ->getInstallPath ($ package ),
103+ $ package
104+ );
105+ });
95106 }
96107}
0 commit comments