From 555260cc8a3b4009bccff670729328384e74b1fd Mon Sep 17 00:00:00 2001 From: Anton Shevchuk Date: Mon, 23 Oct 2017 18:38:52 +0300 Subject: [PATCH 1/3] Small fixes --- src/Installers/Plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Installers/Plugin.php b/src/Installers/Plugin.php index d43fa89..c78e961 100644 --- a/src/Installers/Plugin.php +++ b/src/Installers/Plugin.php @@ -227,8 +227,8 @@ protected function copyExtras($files) /** * It recursively copies the files and directories * - * @param $source - * @param $target + * @param string $source + * @param string $target * * @return void * @throws \InvalidArgumentException From c841e05ef48caacdc1e229bf30a33914ee8201f9 Mon Sep 17 00:00:00 2001 From: Anton Shevchuk Date: Tue, 24 Oct 2017 13:13:30 +0300 Subject: [PATCH 2/3] Fixed installation --- src/Installers/Plugin.php | 67 +++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/src/Installers/Plugin.php b/src/Installers/Plugin.php index c78e961..b2d1fd3 100644 --- a/src/Installers/Plugin.php +++ b/src/Installers/Plugin.php @@ -12,10 +12,14 @@ namespace Bluz\Composer\Installers; use Composer\Composer; +use Composer\DependencyResolver\Operation\InstallOperation; +use Composer\DependencyResolver\Operation\UninstallOperation; +use Composer\DependencyResolver\Operation\UpdateOperation; use Composer\EventDispatcher\EventSubscriberInterface; use Composer\Installer\PackageEvent; use Composer\Installer\PackageEvents; use Composer\IO\IOInterface; +use Composer\Package\PackageInterface; use Composer\Plugin\PluginInterface; use Composer\Script\Event; use Composer\Script\ScriptEvents; @@ -49,6 +53,11 @@ class Plugin implements PluginInterface, EventSubscriberInterface */ protected $vendorPath; + /** + * @var string + */ + protected $packagePath; + /** * @var string */ @@ -102,6 +111,21 @@ public static function getSubscribedEvents(): array ]; } + /** + * extractPackage + * + * @param PackageEvent $event + * + * @return PackageInterface + */ + protected function extractPackage(PackageEvent $event) + { + if ($event->getOperation() instanceof UpdateOperation) { + return $event->getOperation()->getTargetPackage(); + } + return $event->getOperation()->getPackage(); + } + /** * Copy extra files from compose.json of project * @@ -132,8 +156,12 @@ public function copyProjectExtraFiles(Event $event) */ public function copyModuleFiles(PackageEvent $event) { - if (file_exists($this->installer->getVendorPath()) - && $event->getOperation()->getPackage()->getType() === 'bluz-module') { + $package = $this->extractPackage($event); + $this->packagePath = $this->vendorPath .DS. $package->getName(); + if ($package->getType() === 'bluz-module' && file_exists($this->packagePath)) { + if ($package->getExtra() && isset($package->getExtra()['copy-files'])) { + $this->copyExtras($package->getExtra()['copy-files']); + } $this->copyModule(); } } @@ -146,8 +174,12 @@ public function copyModuleFiles(PackageEvent $event) */ public function removeModuleFiles(PackageEvent $event) { - if (file_exists($this->installer->getVendorPath()) - && $event->getOperation()->getPackage()->getType() === 'bluz-module') { + $package = $this->extractPackage($event); + $this->packagePath = $this->vendorPath .DS. $package->getName(); + if ($package->getType() === 'bluz-module' && file_exists($this->packagePath)) { + if ($package->getExtra() && isset($package->getExtra()['copy-files'])) { + $this->removeExtras($package->getExtra()['copy-files']); + } $this->removeModule(); } } @@ -165,21 +197,6 @@ protected function getFilesystem() return $this->filesystem; } - /** - * getExtra - * - * @return array - */ - protected function getExtraFiles() : array - { - $moduleJson = json_decode(file_get_contents($this->installer->getVendorPath() . DS . 'composer.json'), true); - - if (isset($moduleJson, $moduleJson['extra'], $moduleJson['extra']['copy-files'])) { - return $moduleJson['extra']['copy-files']; - } - return []; - } - /** * Copy Module files * @@ -188,11 +205,9 @@ protected function getExtraFiles() : array */ protected function copyModule() { - $this->copyExtras($this->getExtraFiles()); - foreach (self::DIRECTORIES as $directory) { $this->copy( - $this->installer->getVendorPath() . DS . $directory . DS, + $this->packagePath . DS . $directory . DS, PATH_ROOT . DS . $directory . DS ); } @@ -200,7 +215,7 @@ protected function copyModule() $this->installer->getIo()->write( sprintf( ' - Copied %s module to application', - basename($this->installer->getVendorPath()) + basename($this->packagePath) ), true ); @@ -312,8 +327,6 @@ protected function copy($source, $target) */ protected function removeModule() { - $this->removeExtras($this->getExtraFiles()); - foreach (self::DIRECTORIES as $directory) { $this->remove($directory); } @@ -321,7 +334,7 @@ protected function removeModule() $this->installer->getIo()->write( sprintf( ' - Removed %s module from application', - basename($this->installer->getVendorPath()) + basename($this->packagePath) ), true ); @@ -351,7 +364,7 @@ protected function removeExtras($files) */ protected function remove($directory) { - $sourcePath = $this->installer->getVendorPath() . DS . $directory; + $sourcePath = $this->packagePath . DS . $directory; if (!is_dir($sourcePath)) { return; From 683575f8f1c6ea4f5f040eb06931f5929ff200dc Mon Sep 17 00:00:00 2001 From: Anton Shevchuk Date: Tue, 24 Oct 2017 13:16:48 +0300 Subject: [PATCH 3/3] Removed unused `use` --- src/Installers/Plugin.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Installers/Plugin.php b/src/Installers/Plugin.php index b2d1fd3..07b483c 100644 --- a/src/Installers/Plugin.php +++ b/src/Installers/Plugin.php @@ -12,8 +12,6 @@ namespace Bluz\Composer\Installers; use Composer\Composer; -use Composer\DependencyResolver\Operation\InstallOperation; -use Composer\DependencyResolver\Operation\UninstallOperation; use Composer\DependencyResolver\Operation\UpdateOperation; use Composer\EventDispatcher\EventSubscriberInterface; use Composer\Installer\PackageEvent;