How To: Migrate your data back to core filefield folders

Created on 31 January 2023, about 2 years ago
Updated 14 May 2024, 11 months ago

Problem/Motivation

I am preparing to uninstall this module since it looks like Drupal core will be handling transliteration at some point.

I observed that the core settings for the fields never get updated when using this module.

I wanted to make sure my configured folders would remain unchanged after uninstallation of this module, which proved to not be the case. <--

I am not using any of the node tokens or additional features of this module outside of folder and file transliteration so I should be able to translate my basic paths back to core pathing.

My Solution

I created a quick shell script using yq by Mike Farah to extract and in-place edit the core settings with the old value.

for i in config/sync/field.field.*.yml; do
  oldval=$(yq ".third_party_settings.filefield_paths.file_path.value" "$i")
  if [[ -n $oldval && $oldval != "null" ]]; then
    OLDVAL="$oldval" yq -i '.settings.file_directory = strenv(OLDVAL)' "$i"
  fi
done

Resolution

I had not yet explored to see if there was an existing solution.

I'm hope this useful for somebody else or it can start a discussion about uninstallation of the module and some hooks that could be implemented.

πŸ“Œ Task
Status

Active

Version

1.0

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States dasginganinja Bethlehem, PA

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

Comments & Activities

  • Issue created by @dasginganinja
  • πŸ‡ΊπŸ‡ΈUnited States dasginganinja Bethlehem, PA

    An additional thought I had about this:

    Would it be beneficial for this module to have a checkbox for keeping the core folder settings path up to date?

  • πŸ‡³πŸ‡±Netherlands megachriz

    Is this issue about moving what is in

    to

    I think that it cannot be automatically moved in all cases, because it can be the case that tokens are used that the core file module does not support.

    it looks like Drupal core will be handling transliteration at some point

    Interesting, do you have a link to a specific core issue about this?

  • πŸ‡ΊπŸ‡ΈUnited States dasginganinja Bethlehem, PA

    Yes, I was speaking about keeping those two in sync, if it was possible. I'm not sure how feasible it is, but it was something that we completely overlooked after switching over to the filefield functionality for directory pathing.

    I was checking out the filename transliteration module [1] and noticed they had linked to core's issue.

    It looks like core's issue is #2492171 [2].

    [1] - https://www.drupal.org/project/filename_transliteration β†’ -- Filename Transliteration module
    [2] - https://www.drupal.org/project/drupal/issues/2492171 ✨ Provide options to sanitize filenames (transliterate, lowercase, replace whitespace, etc) Fixed -- Provide options to sanitize filenames (transliterate, lowercase, replace whitespace, etc)

    I hope this helps. Thanks for all of your work on this and Feeds, etc.

  • πŸ‡ΊπŸ‡ΈUnited States dasginganinja Bethlehem, PA
  • Yes, I was speaking about keeping those two in sync, if it was possible.

    It's not possible. The entire reason I'm considering using this module is to have [node:some_field:target_id] in the file path. You can't use the entity's fields as tokens in core.

    The only possibility would be to notify the admin when the module is (going to be) uninstalled.

Production build 0.71.5 2024