Add support for Drush via command line only

Created on 10 November 2024, about 1 month ago

Problem/Motivation

Drush is a command line tool, and the new Drush-directed commands quick-export and quick-import should support being run, as well as options provided, via the command line only, not the GUI.

The system wide configuration synchronization directory (normally sites/default/files/sync) should be used as source and destination, storing and retrieving the menu files from a menu_migration folder inside Drupal's config folder.

Steps to reproduce

Want to use Drush only, but need to use the GUI.

Proposed resolution

Format

Add a format option for menu_migration:quick-export and menu_migration:quick-import, YAML and JSON are supported. Default is JSON.

Use Drupal's config directory as source and destination

Menu Migration should simply output the menu files inside the Drupal config directory, in a menu_migration folder.

By default, the system wide default configuration sync directory sites/default/files/sync should be used, resulting in this structure:

$ tree -L 3 web/sites/default/files/sync
web/sites/default/files/sync
├── menu_migration
│   ├── footer.json
│   └── main.json
├── admin_toolbar_search.settings.yml
├── admin_toolbar.settings.yml
├── admin_toolbar_tools.settings.yml
├── announcements_feed.settings.yml
[...]

If the user has changed the sync folder in settings.php (for example with $settings['config_sync_directory'] = '../assets/config';) this will be the structure:

$ tree -L 3 assets
assets
└── config
    ├── menu_migration
    │   ├── footer.json
    │   └── main.json
    ├── admin_toolbar_search.settings.yml
    ├── admin_toolbar.settings.yml
    ├── admin_toolbar_tools.settings.yml
    ├── announcements_feed.settings.yml
    [...]

I thought about proposing adding --source and --destination options, but they are not really needed, as I see it ...

Delete Quick Action Settings page

Delete the "Quick Action Settings" form (/admin/config/development/menu-migration/quick-action-settings) since it is no longer needed.

The result

Using export as example, where import should get the same treatment:

$ drush menu_migration:quick-export -h
Exports one or more menus using the given menu IDs.

Examples:
 menu_migration:quick-export main                  Export one menu (in this case "main")                 
 menu_migration:quick-export main,footer,some_name Export three menus (in this case "main", "footer" and 
                                                   "some_name")                                          
 menu_migration:quick-export main, --format=yaml   Export a menu in YAML format

Arguments:
 [menu_names] The machine name(s) (ID) of the menu(s). Delimit multiple using commas. 

Options:
 --format[=FORMAT]           Set the format, JSON and YAML are supported. [default: json]

Aliases: mmqe
📌 Task
Status

Active

Version

4.0

Component

Code

Created by

🇩🇰Denmark ressa Copenhagen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ressa
  • 🇩🇰Denmark ressa Copenhagen
  • 🇩🇰Denmark ressa Copenhagen
  • 🇩🇰Denmark ressa Copenhagen
  • 🇷🇴Romania bbu23

    Thank you for proposing this, but in this particular case I will mostly reject it.

    The reason is that when I created this module, I wanted a clear separation from the Drupal's configuration folder. This is one major difference with Menu Export and Structure Sync modules. I wanted full control of the exported files, I wanted them to be seen in GIT easily from the start, to encourage the user to have them placed outside the Drupal root's directory and to leave the user the choice if they sync them or not. Also, these files are not configuration, so in my opinion they don't belong in the configuration directory just by their role.

    Furthermore, the Quick Action Settings form values can always be overridden in settings.php. So, if GUI needs to be avoided in some cases for the exported path, it can always be done directly in settings.php.

    The only part that I agree with, and actually considered it while I was working on the related issue was the --format option. This we can definitely add.

  • 🇷🇴Romania bbu23

    Closing this, with the mention that the --format option will be resolved in the related ticket.

  • 🇩🇰Denmark ressa Copenhagen

    Thanks for a fast answer, as always!

    The reason is that when I created this module, I wanted a clear separation from the Drupal's configuration folder.

    I do get your point about differentiating this module from other sort of similar modules, so from that perspective it does make sense.

    I did try Menu Export originally, but it didn't seem to work with Drush... which was what attracted me to Migrate Menu. I somehow missed Structure Sync ... but it looks like it might be a better fit for my needs -- since I desire a pure Drush solution :)

    And you're right, destination/source can always be overridden. Thanks for considering adding the format option, YAML is easier to scan!

  • 🇷🇴Romania bbu23

    Indeed, Menu Export did not have a Drush command, a major problem/inconvenience for me, but that and other reasons are the core of my decision to create my own module, including the configuration.

    I didn't know about Structure Sync either, I actually discovered it after I finished the development stage of version 4, when I was doing research about "Similar modules and how are they different" for the module's page updates.

    Still, both Menu Export and Structure Sync do have the configuration sync principle, which is why my module's core functionality needs to continue on the route it was born in (independence from config).

    On the other hand, I'm glad to hear that Structure Sync fits your needs, they also seem to have more control over partial and full imports, which my module lacks.

    Thanks!

  • 🇩🇰Denmark ressa Copenhagen

    It's really strange how we both missed Structure Sync ... maybe due to bad SEO? When you search for relevant menu export import modules, with something like "site:drupal.org export menu configuration" you get a few "it doesn't work" Structure Sync issues, but are mostly guided to other modules ...

    I do understand why Menu Migration should stay on this route, to differentiate itself.

    > ... Structure Sync [...] they also seem to have more control over partial and full imports, which my module lacks.

    Actually, it's true that via the Structure Sync GUI you can select individual menu's, but not with Drush. That's a case of "Export All The Things" or nothing. So in that department Menu Migration has the lead :)

    $ drush export:menus -h
    Export menu links.
    
    Global options:
    -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
    -y, --yes            Auto-accept the default for all user prompts. Equivalent to --no-interaction.
    -l, --uri=URI        A base URL for building links and selecting a multi-site. Defaults to https://default.
                         To see all global options, run `drush topic` and pick the first choice.
    
    Aliases: em, export-menus
    
  • 🇷🇴Romania bbu23

    Yeah, it's very strange indeed, and I am trying to remember, but I'm not 100% sure. I know I was exploring the Project Browser at some point, and it could be that I found it there. But still, not sure. It could be long Google search or Project Browser.

    Oh, I see. Well, each module with their pros and cons it seems.

Production build 0.71.5 2024