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

[config:export] directory incorrectly prefixed with composer root

Open cburschka opened this issue 4 years ago • 1 comments

Problem/Motivation

In #4154 / 37aeb5d12, ExportCommand was modified to prefix the config sync directory with the composer root. Three bugs:

  1. A relative path is relative to Drupal root, which is not the same as the composer root - many sites created via composer put Drupal in a ./web/ subdirectory.
  2. The composer root is actually prefixed twice when making the directory.
  3. The path might already be absolute, in which case it should not be prefixed with anything at all.

How to reproduce

Include steps related how to reproduce.

  • Create a Drupal site using the drupal-composer/drupal-project template (https://github.com/drupal-composer/drupal-project)
  • Require drupal/console ^1.9.4
  • Set $settings['config_sync_directory'] = '../config/sync'; in settings.php (already the default for this composer template).
  • Run drupal config:export

Expected:

  • Config is exported to ../config/sync from Drupal root (which is config/sync from Composer root).

Actual: several issues (getting a different one on each environment where I reproduced it):

  1. Tries to create {COMPOSER_ROOT}/{COMPOSER_ROOT}/../config/sync
  2. Tries to export to {COMPOSER_ROOT}/../config/sync

Solution

A brief description of the proposed fix.

  • Use Webmozart\PathUtil\Path to check if the directory is absolute
  • If not, use drupalFinder->getDrupalRoot() and prefix the directory with that
  • Remove the extra prefixing when creating the directory.

(PR to follow)

cburschka avatar May 19 '20 15:05 cburschka

This seems to be reported in several other issues, including #4195 and #4198.

cburschka avatar May 19 '20 15:05 cburschka

THank you for your contribution

LOBsTerr avatar Sep 16 '22 14:09 LOBsTerr