diff --git a/src/App/Command/Composer/UpdateCommand.php b/src/App/Command/Composer/UpdateCommand.php index ef341d2d..18842092 100644 --- a/src/App/Command/Composer/UpdateCommand.php +++ b/src/App/Command/Composer/UpdateCommand.php @@ -55,11 +55,6 @@ protected function beforeProcessingPackages(InputInterface $input): void } } - protected function afterProcessingPackages(): void - { - $this->packageService->createSymbolicLinks($this->getPackageList(), $this->getIO()); - } - protected function processPackage(Package $package): void { $io = $this->getIO(); @@ -83,6 +78,8 @@ protected function processPackage(Package $package): void $io ); + $this->packageService->createSymbolicLinks($package, $this->getPackageList(), $this->getIO()); + if (!$io->isVerbose()) { $io ->important() diff --git a/src/App/Command/InstallCommand.php b/src/App/Command/InstallCommand.php index d9964285..5edcac77 100644 --- a/src/App/Command/InstallCommand.php +++ b/src/App/Command/InstallCommand.php @@ -48,7 +48,9 @@ protected function beforeProcessingPackages(InputInterface $input): void protected function afterProcessingPackages(): void { - $this->packageService->createSymbolicLinks($this->getPackageList(), $this->getIO()); + foreach ($this->getTargetPackages() as $targetPackage) { + $this->packageService->createSymbolicLinks($targetPackage, $this->getPackageList(), $this->getIO()); + } } protected function processPackage(Package $package): void diff --git a/src/App/Command/UpdateCommand.php b/src/App/Command/UpdateCommand.php index 22dd58a1..211bb18e 100644 --- a/src/App/Command/UpdateCommand.php +++ b/src/App/Command/UpdateCommand.php @@ -57,11 +57,6 @@ protected function beforeProcessingPackages(InputInterface $input): void } } - protected function afterProcessingPackages(): void - { - $this->packageService->createSymbolicLinks($this->getPackageList(), $this->getIO()); - } - protected function processPackage(Package $package): void { $io = $this->getIO(); @@ -87,6 +82,8 @@ protected function processPackage(Package $package): void $io ); + $this->packageService->createSymbolicLinks($package, $this->getPackageList(), $this->getIO()); + if (!$io->isVerbose()) { $io ->important() diff --git a/src/App/PackageService.php b/src/App/PackageService.php index b7918b58..64a7bae3 100644 --- a/src/App/PackageService.php +++ b/src/App/PackageService.php @@ -4,6 +4,7 @@ namespace Yiisoft\YiiDevTool\App; +use RuntimeException; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Process\Process; use Yiisoft\Files\FileHelper; @@ -11,6 +12,7 @@ use Yiisoft\YiiDevTool\App\Component\Package\Package; use Yiisoft\YiiDevTool\App\Component\Package\PackageErrorList; use Yiisoft\YiiDevTool\App\Component\Package\PackageList; +use Yiisoft\YiiDevTool\Infrastructure\Composer\ComposerPackage; final class PackageService { @@ -89,16 +91,19 @@ public function gitClone( $errorList->set($package, $output, 'cloning package repository'); } - public function createSymbolicLinks(PackageList $packageList, OutputManager $io): void + public function createSymbolicLinks(Package $package, PackageList $packageList, OutputManager $io): void { $io ->important() - ->info('Re-linking vendor directories...'); + ->info('Re-linking vendor directories for package: ' . $package->getName()); $installedPackages = $packageList->getInstalledAndEnabledPackages(); - foreach ($installedPackages as $package) { - $io->info("Package {$package->getId()} linking..."); + try { $this->linkPackages($package, $installedPackages); + } catch (RuntimeException $e) { + $io + ->important() + ->error("Linking error package {$package->getName()}: " . $e->getMessage()); } $io->done(); @@ -117,11 +122,21 @@ public function removeSymbolicLinks(Package $package, PackageList $packageList, $installedPackages = $packageList->getInstalledPackages(); foreach ($installedPackages as $installedPackage) { - $packagePath = "{$vendorDirectory}/{$installedPackage->getName()}"; - - if (is_dir($packagePath) && is_link($packagePath)) { - $io->info("Removing symlink {$packagePath}"); - FileHelper::unlink($packagePath); + try { + $composerPackage = new ComposerPackage($installedPackage->getName(), $installedPackage->getPath()); + $upstreamNamePackage = $composerPackage + ->getComposerConfig() + ->getSection('name'); + $packagePath = "{$vendorDirectory}/{$upstreamNamePackage}"; + + if (is_dir($packagePath) && is_link($packagePath)) { + $io->info("Removing symlink {$packagePath}"); + FileHelper::unlink($packagePath); + } + } catch (RuntimeException $e) { + $io + ->important() + ->error("Error while removing package links {$installedPackage->getName()}: " . $e->getMessage()); } } @@ -144,7 +159,11 @@ private function linkPackages(Package $package, array $installedPackages): void continue; } - $installedPackagePath = "{$vendorDirectory}/{$installedPackage->getName()}"; + $composerPackage = new ComposerPackage($installedPackage->getName(), $installedPackage->getPath()); + $upstreamNamePackage = $composerPackage + ->getComposerConfig() + ->getSection('name'); + $installedPackagePath = "{$vendorDirectory}/{$upstreamNamePackage}"; if (is_dir($installedPackagePath)) { $fs->remove($installedPackagePath);