Skip to content

Commit

Permalink
Merge pull request #1726 from bolt/bugfix/remove-services
Browse files Browse the repository at this point in the history
Remove services before `composer remove`
  • Loading branch information
bobdenotter committed Aug 18, 2020
2 parents d8f501d + e2d02f0 commit 9297dc2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@
"@auto-scripts",
"php bin/console bolt:info"
],
"pre-package-uninstall": [
"php bin/console extensions:configure --remove-services"
],
"post-update-cmd": [
"php bin/console extensions:configure",
"@auto-scripts",
Expand Down
26 changes: 25 additions & 1 deletion src/Command/ExtensionsConfigureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ protected function configure(): void
{
$this
->setDescription('Copy the config/config.yaml, config/services.yaml and config/routes.yaml files from extensions.')
->addOption('with-config', null, InputOption::VALUE_NONE, 'If set, Bolt will copy the default extension config.yaml file');
->addOption('with-config', null, InputOption::VALUE_NONE, 'If set, Bolt will copy the default extension config.yaml file')
->addOption('remove-services', null, InputOption::VALUE_NONE, 'If set, Bolt will remove the extension\'s services and routes files');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$extensions = $this->extensionRegistry->getExtensions();

if ($input->getOption('remove-services')) {
$this->deleteExtensionRoutesAndServices($extensions);

return 0;
}

$this->copyExtensionRoutesAndServices($extensions);

if ($input->getOption('with-config')) {
Expand Down Expand Up @@ -68,6 +75,23 @@ private function copyExtensionConfig(array $packages): void
}
}

private function deleteExtensionRoutesAndServices(array $packages): void
{
foreach ($packages as $package) {
$path = $this->getPackagePath($package);
$services = $this->getExtensionServicesPath($path);

if (is_file($services)) {
unlink($services);
}

$routes = $this->getExtensionRoutesPath($path);
if (is_file($routes)) {
unlink($routes);
}
}
}

private function copyExtensionRoutesAndServices(array $packages): void
{
$oldExtensionsRoutes = glob($this->getExtensionRoutesPath());
Expand Down

0 comments on commit 9297dc2

Please sign in to comment.