Skip to content

Commit

Permalink
[console] Update getSubscribedEvents. (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas authored Jun 8, 2017
1 parent 4e7f576 commit a9c6f20
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions src/Extender.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use Composer\Installer\PackageEvent;
use Composer\Installer\PackageEvents;
use Composer\Script\Event;
use Composer\Script\ScriptEvents;
use Composer\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Finder\Finder;

// Explicitly require ExtenderManager here.
// When this package is uninstalled, ExtenderManager needs to be available any
Expand Down Expand Up @@ -44,18 +45,17 @@ public function activate(Composer $composer, IOInterface $io)
*/
public static function getSubscribedEvents()
{
return array(
PackageEvents::POST_PACKAGE_INSTALL => "processPackages",
PackageEvents::POST_PACKAGE_UPDATE => "processPackages",
PackageEvents::POST_PACKAGE_UNINSTALL => "processPackages",
);
return [
ScriptEvents::POST_INSTALL_CMD => "processPackages",
ScriptEvents::POST_UPDATE_CMD => "processPackages",
];
}

/**
* @param PackageEvent $event
* @param Event $event
* @throws \Exception
*/
public function processPackages(PackageEvent $event)
public function processPackages(Event $event)
{
$extenderManager = new ExtenderManager();

Expand All @@ -65,22 +65,22 @@ public function processPackages(PackageEvent $event)
$localRepository = $repositoryManager->getLocalRepository();

foreach ($localRepository->getPackages() as $package) {
if ($installationManager->isPackageInstalled($localRepository, $package)) {
if ($package->getType() === 'drupal-console-library') {
$extenderManager->addServicesFile($installationManager->getInstallPath($package) . '/console.services.yml');
$extenderManager->addConfigFile($installationManager->getInstallPath($package) . '/console.config.yml');
if ($installationManager->isPackageInstalled($localRepository, $package)) {
if ($package->getType() === 'drupal-console-library') {
$extenderManager->addServicesFile($installationManager->getInstallPath($package) . '/console.services.yml');
$extenderManager->addConfigFile($installationManager->getInstallPath($package) . '/console.config.yml');
}
}
}
}

if ($consolePackage = $localRepository->findPackage('drupal/console', '*')) {
if ($localRepository->hasPackage($consolePackage)) {
$directory = $installationManager->getInstallPath($consolePackage);
}
if ($localRepository->hasPackage($consolePackage)) {
$directory = $installationManager->getInstallPath($consolePackage);
}
}
if (empty($directory)) {
// cwd should be the project root. This is the same logic Symfony uses.
$directory = getcwd();
// cwd should be the project root. This is the same logic Symfony uses.
$directory = getcwd();
}

$configFile = $directory . '/extend.console.config.yml';
Expand Down Expand Up @@ -127,5 +127,27 @@ public function processPackages(PackageEvent $event)
);
$this->io->write('<info>Creating services cache file: </info>' . $servicesUninstallFile);
}

$this->removeCacheFiles();
}

protected function removeCacheFiles()
{
$finder = new Finder();
$finder->files()
->in(getcwd().'/console/cache/')
->ignoreUnreadableDirs();

foreach ($finder as $file) {
unlink($file->getPathName());
}

$finder->directories()
->in(getcwd().'/console/cache/')
->ignoreUnreadableDirs();

foreach ($finder as $directory) {
rmdir($directory);
}
}
}

0 comments on commit a9c6f20

Please sign in to comment.