diff --git a/BackendCommands.php b/BackendCommands.php index 26822bb..f9eff19 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -2,10 +2,16 @@ namespace Drush\Commands\BurdaStyleGroup; +use Consolidation\AnnotatedCommand\AnnotationData; +use Drupal\Core\Site\Settings; use Consolidation\AnnotatedCommand\CommandData; use Drush\Commands\DrushCommands; +use Drush\Drush; use Drush\SiteAlias\SiteAliasManagerAwareInterface; use Drush\Sql\SqlBase; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; @@ -124,62 +130,50 @@ public function updateDatabase() } /** - * Runs populateConfigSyncDirectory() for backend:config-export. + * Add option to command. * - * As long as we have to handle environment specific config, this can not - * be a post command for the default drush config:import command. + * @hook option config:export * - * TODO: Revisit when we do not need the local environment config folder anymore. - * TODO: Then decide if we can make this a post command for config:*. - * - * @hook pre-command backend:config-export - * - * @param \Consolidation\AnnotatedCommand\CommandData $commandData + * @param \Symfony\Component\Console\Command\Command $command + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ - public function preConfigExportCommand(CommandData $commandData) + public function additionalConfigExportOption(Command $command, AnnotationData $annotationData) { - $this->populateConfigSyncDirectory(); + $command->addOption( + 'project-directory', + '', + InputOption::VALUE_NONE, + 'The base directory of the project. Defaults to composer root of project. Option added by burdastyle backend commands.' + ); } /** - * Export configuration of BurdaStyle backend site. - * - * TODO: Revisit when we do not need the local environment config folder anymore. - * TODO: Then decide if we can make this a post command for config:export. - * - * @command backend:config-export + * @hook init config:export * - * @aliases backend:cex - * - * @options-backend - * - * @usage drush @elle backend:config-export - * Exports the elle configuration. - * - * @bootstrap config + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ - public function configExport() + public function initConfigExportCommand(InputInterface $input, AnnotationData $annotationData) { - if ($this->environment !== 'prod') { - $this->logger()->error('Only production will be exported. Current environment is "%environment".', ['%environment' => $this->environment]); - - return; - } + $this->initCommands($input, $annotationData); + } - // export the config into the export folder. - $this->drush($this->selfRecord(), 'config:export', [], ['yes' => $this->input()->getOption('yes')]); + /** + * Runs populateConfigSyncDirectory() for config:export. + * + * @hook pre-command config:export + * + * @param \Consolidation\AnnotatedCommand\CommandData $commandData + */ + public function preConfigExportCommand(CommandData $commandData) + { + $this->populateConfigSyncDirectory(); } /** * Move files from sync folder to shared or override folders. * - * As long as we have to handle environment specific config, this can not - * be a post command for the default drush config:import command. - * - * TODO: Revisit when we do not need the local environment config folder anymore. - * TODO: Then decide if we can make this a post command for config:export. - * - * @hook post-command backend:config-export + * @hook post-command config:export * * @param $result * @param \Consolidation\AnnotatedCommand\CommandData $commandData @@ -189,7 +183,6 @@ public function postConfigExportCommand($result, CommandData $commandData) $exportedFiles = $this->getConfigFilesInDirectory($this->siteConfigSyncDirectory()); $overrideFiles = $this->getConfigFilesInDirectory($this->siteConfigOverrideDirectory()); $sharedFiles = $this->getConfigFilesInDirectory($this->configSharedDirectory()); - $localFiles = $this->getConfigFilesInDirectory($this->siteConfigEnvironmentDirectory('local')); $modifiedFiles = []; foreach ($exportedFiles as $fileName => $fullPath) { @@ -214,14 +207,6 @@ public function postConfigExportCommand($result, CommandData $commandData) } } - // Give information to the user, when we modified a configuration that also exists in local config. - // TODO: revisit, when local config folder has been removed. - foreach ($modifiedFiles as $fileName => $fullPath) { - if (isset($localFiles[$fileName])) { - $this->io()->block('Configuration file "'.$fileName.'" was changed and exists in local config folder. Please check, if local config has to be manually modified.', 'INFO', 'fg=yellow'); - } - } - // Remove files from override, that were not exported anymore. foreach ($overrideFiles as $fileName => $fullPath) { if (!isset($exportedFiles[$fileName])) { @@ -242,15 +227,9 @@ public function postConfigExportCommand($result, CommandData $commandData) } /** - * Runs populateConfigSyncDirectory() for backend:config-import. + * Runs populateConfigSyncDirectory() for config:import. * - * As long as we have to handle environment specific config, this can not - * be a post command for the default drush config:import command. - * - * TODO: Revisit when we do not need the local environment config folder anymore. - * TODO: Then decide if we can make this a post command for config:*. - * - * @hook pre-command backend:config-import + * @hook pre-command config:import * * @param \Consolidation\AnnotatedCommand\CommandData $commandData */ @@ -260,32 +239,35 @@ public function preConfigImportCommand(CommandData $commandData) } /** - * Import configuration of BurdaStyle backend site. - * - * This is simple wrapper to default the config:import command. it is only - * until we can get rid of the environment specific config directories - * (local and testing). + * Add option to command. * - * TODO: Revisit when we do not need local config folder anymore. Then we can - * TODO: delete this command and change the preConfigImportCommand to hook - * TODO: to the default config:import command. + * @hook option config:import * - * @command backend:config-import - * - * @aliases backend:cim - * - * @options-backend - * - * @usage drush @elle backend:config-import - * Exports the elle configuration. + * @param \Symfony\Component\Console\Command\Command $command + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData + */ + public function additionalConfigImportOption(Command $command, AnnotationData $annotationData) + { + $command->addOption( + 'project-directory', + '', + InputOption::VALUE_NONE, + 'The base directory of the project. Defaults to composer root of project. Option added by burdastyle backend commands.' + ); + } + + /** + * @hook init config:import * - * @bootstrap config + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ - public function configImport() + public function initConfigImportCommand(InputInterface $input, AnnotationData $annotationData) { - $this->drush($this->selfRecord(), 'config:import', [], ['yes' => $this->input()->getOption('yes')]); + $this->initCommands($input, $annotationData); } + /** * Prepare an update branch. Does code update, database update and config export. * @@ -323,7 +305,7 @@ public function prepareUpdateBranch() // Update database and export config for all sites. foreach ($aliases as $alias) { $this->process(['drush', $alias, 'backend:update-database'] + $this->getOptions(), $this->projectDirectory()); - $this->process(['drush', $alias, 'backend:config-export'] + $this->getOptions(), $this->projectDirectory()); + $this->process(['drush', $alias, 'config:export'] + $this->getOptions(), $this->projectDirectory()); } } @@ -350,6 +332,29 @@ public function createTestingDump() $this->process(['php', 'core/scripts/db-tools.php', 'dump-database-d8-mysql', '--database-url', $dbUrl], $this->drupalRootDirectory()); } + /** + * Enable modules that are excluded from config export. + * + * @command backend:enable-dev-modules + * + * @options-backend + * + * @bootstrap full + */ + public function enableDevModules() + { + $modules = Settings::get('config_exclude_modules', []); + + if (!count($modules)) { + $this->logger()->warning('No modules defined in $settings[\'config_exclude_modules\'].'); + + return; + } + + $process = $this->processManager()->drush($this->siteAliasManager()->getSelf(), 'pm:enable', $modules, Drush::redispatchOptions()); + $process->mustRun($process->showRealtime()); + } + /** * Gets a cleaned up array of $key=$value strings from the input options. * @@ -389,12 +394,6 @@ protected function populateConfigSyncDirectory(): void foreach ($overrideFiles as $fileName => $fullPath) { $this->filesystem->copy($fullPath, $syncDirectory.'/'.$fileName, true); } - if ($this->filesystem->exists($this->siteConfigEnvironmentDirectory($this->environment))) { - $environmentFiles = $this->getConfigFilesInDirectory($this->siteConfigEnvironmentDirectory($this->environment)); - foreach ($environmentFiles as $fileName => $fullPath) { - $this->filesystem->copy($fullPath, $syncDirectory.'/'.$fileName, true); - } - } } /** diff --git a/BackendCommandsTrait.php b/BackendCommandsTrait.php index d77f492..6d97b8f 100644 --- a/BackendCommandsTrait.php +++ b/BackendCommandsTrait.php @@ -36,11 +36,6 @@ trait BackendCommandsTrait */ private $projectDirectory; - /** - * @var string - */ - private $environment; - /** * @hook init * @@ -51,7 +46,6 @@ public function initCommands(InputInterface $input, AnnotationData $annotationDa { // Initialize project directory. $this->projectDirectory = $input->getOption('project-directory') ?: Drush::bootstrapManager()->getComposerRoot(); - $this->environment = $input->getOption('environment'); } /** @@ -59,13 +53,11 @@ public function initCommands(InputInterface $input, AnnotationData $annotationDa * * @hook option @options-backend * - * @option project-directory The base directory of the project. Defaults to composer root of project . - * @option environment Choose environment the installation is built for, i.e. which config folders are used. - * Possible values are "local", "testing" and "prod". (Defaults to "prod"). + * @option project-directory The base directory of the project. Defaults to composer root of project. * * @param array $options */ - public function optionsBackend($options = ['project-directory' => false, 'environment' => 'prod']) + public function optionsBackend($options = ['project-directory' => false]) { } @@ -114,18 +106,13 @@ protected function process($command, $cwd = null, array $env = null, $input = nu /** * The base project directory, where most commands will be executed from. + * Defaults to composer root of project- * - * @return \Consolidation\AnnotatedCommand\CommandError|string + * @return string */ protected function projectDirectory(): string { - if (isset($this->projectDirectory)) { - return $this->projectDirectory; - } - - $msg = dt('The project directory has not been set.'); - - return new CommandError($msg); + return $this->projectDirectory; } /** @@ -193,18 +180,6 @@ protected function siteConfigOverrideDirectory(): string return $this->siteConfigSyncDirectory().'/../override'; } - /** - * The directory, where site specific configuration for the current environment is placed. - * - * @param string $environment - * The environment to get the config directory for. - * @return string - */ - protected function siteConfigEnvironmentDirectory(string $environment): string - { - return $this->siteConfigSyncDirectory().'/../'.$environment; - } - /** * Get the '@self' alias record. *