Option to overwrite export files instead of creating a copy with _N suffix

Created on 12 February 2025, 2 months ago

Problem/Motivation

Now if we export the same entity multiple times using the command drush content:export --entities=123 - the module creates new files with _0, _1 suffix, etc, here is an example:
node-page-8f4140bf-2287-4bff-a29d-edc3a700a99d.yml
node-page-8f4140bf-2287-4bff-a29d-edc3a700a99d_0.yml
node-page-8f4140bf-2287-4bff-a29d-edc3a700a99d_1.yml
node-page-8f4140bf-2287-4bff-a29d-edc3a700a99d_2.yml
node-page-8f4140bf-2287-4bff-a29d-edc3a700a99d_3.yml
node-page-8f4140bf-2287-4bff-a29d-edc3a700a99d_4.yml

Steps to reproduce

Execute the same export command multiple times, like this:
drush content:export --entities=123

Proposed resolution

Add an option to overwrite current files instead of creating new copies. And maybe even make this behavior by default?

I can't imagine cases where copies of the same entity content in different files can be useful. Maybe it's useful to keep the history, but the git history of the single file should be much more convenient, than multiple files, from my point of view.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

1.4

Component

Code

Created by

🇦🇲Armenia murz Yerevan, Armenia

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

Merge Requests

Comments & Activities

  • Issue created by @murz
  • Pipeline finished with Success
    2 months ago
    Total: 181s
    #427501
  • 🇦🇲Armenia murz Yerevan, Armenia

    Seems the source of this issue is that we use Drupal-managed file entities to export files. It is good for downloading the files using admin panel, but for drush commands it gives more problems than benefits.

    So, my suggestion for drush command is to do writing the files directly to the filesystem.

    I prepared an MR with a new function generateBulkYamlFiles() that generates files directly into the target directory, please review.

  • Pipeline finished with Success
    2 months ago
    Total: 177s
    #427504
  • 🇦🇲Armenia murz Yerevan, Armenia
  • 🇦🇲Armenia murz Yerevan, Armenia

    Also, noticed a problem that on each drush content:export module creates new files in the file_managed table, so this table grows for no reason, because with Drush we can operate with files directly.

    So, the provided fix also fixes this problem with growing managed files list in Drupal.

  • 🇦🇲Armenia murz Yerevan, Armenia

    Added more examples of the problem to the issue description.

  • 🇦🇲Armenia murz Yerevan, Armenia

    Attaching a static patch file with those changes, to make it possible to use in composer until 🐛 GitLab Merge Requests Unable to Generate Incremental Patch Files Active is resolved.

  • 🇦🇲Armenia murz Yerevan, Armenia

    Attaching a static patch file with those changes, to make it possible to use in composer until #3204538: GitLab Merge Requests Unable to Generate Incremental Patch Files is resolved.

  • Pipeline finished with Success
    about 1 month ago
    Total: 202s
    #455943
Production build 0.71.5 2024