diff --git a/composer.json b/composer.json index 4f75610c8..6c90f2950 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Command/ExtensionsConfigureCommand.php b/src/Command/ExtensionsConfigureCommand.php index 10cec8312..a22eb397b 100644 --- a/src/Command/ExtensionsConfigureCommand.php +++ b/src/Command/ExtensionsConfigureCommand.php @@ -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')) { @@ -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());