drupal-console icon indicating copy to clipboard operation
drupal-console copied to clipboard

[config:export] broken in 1.9.4

Open erilot opened this issue 4 years ago • 3 comments

[config:export] broken in 1.9.4

Problem

After upgrading to console 1.9.4, config:export incorrectly calculates the directory path for the export files, creates those incorrect directories, and doesn't export any files. No error is thrown.

May be related to https://github.com/hechoendrupal/drupal-console/issues/4195.

I am using a web docroot on Ubuntu 18.04 local development environment (Lando/Pantheon recipe), and

  • Drupal 8.7.10
  • PHP 7.2
  • Console 1.9.4

What I expect to see: execute drupal ce, accept the default directory (/app/config). All config files are exported to /config. (Note with a web docroot this is parallel to the web directory containing the drupal site). This worked as expected until upgrading to 1.9.4.

What happens instead: image

Which creates an /app/app/config directory with no files in it: image

Replacing the default with /config generates an /app//config directory structure with no files in it.

Replacing the default with / destroys the site. Do not recommend.

How to reproduce

  • Upgrade drupal/console to 1.9.4
  • Attempt a config:export

Workaround

Revert to 1.9.3, which works as expected

erilot avatar Nov 15 '19 22:11 erilot

The issue lies in the src/Command/Config/ExportCommand.php file, this is lines 95 to 118...

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $drupal_root = $this->drupalFinder->getComposerRoot();
        $directory = $drupal_root.'/'.$input->getOption('directory');
        $tar = $input->getOption('tar');
        $removeUuid = $input->getOption('remove-uuid');
        $removeHash = $input->getOption('remove-config-hash');
        $drupal_root = $this->drupalFinder->getComposerRoot();

        if (!$directory) {
            $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
        }

        $fileSystem = new Filesystem();
        try {
            $fileSystem->mkdir($drupal_root."/".$directory);
        } catch (IOExceptionInterface $e) {
            $this->getIo()->error(
                sprintf(
                    $this->trans('commands.config.export.messages.error'),
                    $e->getPath()
                )
            );
        }

You'll see that the $drupal_root is being added by default to the directory passed in to the function at line 98, which precludes specifying a full system path (in other words, you can now only pass a relative path to the export function).

The $drupal_root variable is then also being added again at line 110, so even with a relative path it will still be wrong.

Also, the $drupal_root variable itself is being defined twice (lines 97 & 102).

I believe these lines should look more like this...

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $drupal_root = $this->drupalFinder->getComposerRoot();
        $directory = $drupal_root.'/'.$input->getOption('directory');
        $tar = $input->getOption('tar');
        $removeUuid = $input->getOption('remove-uuid');
        $removeHash = $input->getOption('remove-config-hash');

        // if the directory passed in to the function exists, use it explicity
        if (is_dir($input->getOption('directory'))) {
          $directory = $input->getOption('directory');
        }

        if (!$directory) {
            $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
        }

        $fileSystem = new Filesystem();
        try {
            $fileSystem->mkdir($directory);
        } catch (IOExceptionInterface $e) {
            $this->getIo()->error(
                sprintf(
                    $this->trans('commands.config.export.messages.error'),
                    $e->getPath()
                )
            );
        }

I'm happy to be corrected though!

scothubbard avatar Jan 09 '20 11:01 scothubbard

same issue. Downgrading to 1.9.3 as suggested by @erilot works.

tivie avatar Jan 23 '20 02:01 tivie

Could be linked to https://github.com/hechoendrupal/drupal-console/issues/4195

sylvainar avatar Feb 02 '20 11:02 sylvainar

Thank you for your contribution

LOBsTerr avatar Sep 16 '22 14:09 LOBsTerr