Problem/Motivation

When new metadata field mappings are added to an existing Acquia DAM media type (via the field map UI on /admin/structure/media/manage/{media_type}, the new mapping only takes effect for media entities created after the mapping was configured. Existing media entities are never updated, their newly-mapped fields remain empty (or hold stale values).

The existing sync mechanisms don't cover this:

  • Cron sync (acquia_dam_cronsyncAssets()) only processes media whose DAM assets were recently edited (based on lastEditDate). Unedited assets are skipped.
  • Manual "Sync metadata" action works per-entity only — no batch operation exists.
  • acquia-dam:update-assets is DAM-API-centric (version checks, queue processing) and isn't designed for re-applying field configurations locally.

There is no way for a site administrator to retroactively apply field mapping changes to thousands of existing media entities without manually editing each one or resorting to custom update hooks.

Steps to reproduce

  • Update field map at /admin/structure/media/manage/{media_type}
  • Newly mapped fields are empty for existing assets.

Proposed resolution

Add a new Drush command acquia-dam:asset-sync-metadata (ad:asm) that iterates all existing DAM media entities of a given media type and force-refreshes their mapped metadata fields.

The command:

  • Accepts a required media_type argument — only processes media of that type, preventing accidental bulk operations.
  • Uses forceMappedFieldRefresh() logic (same as the "Sync metadata" UI action and the MediaItemUpdater cron worker) to unconditionally overwrite all mapped fields with current values from getMetadata(), including entity_reference resolution to taxonomy terms.
  • Processes in configurable batches (--batch-size, default 50) with entity cache clearing and periodic garbage collection to handle large media inventories.
  • Supports resumable processing (--resume flag) — stores the last processed media ID in Drupal state (acquia_dam.metadata_sync.last_processed_id) after each chunk. If interrupted (timeout, crash), re-running with --resume picks up where it left off rather than starting over.
  • Validates the media type argument via a Drush hook validator — only media types using the acquia_dam_asset source plugin are accepted, with a helpful error listing available types.

Usage examples:

drush adsmm acquia_dam_image_asset
drush adsmm acquia_dam_pdf_asset --batch-size=100 --resume

Issue fork acquia_dam-3609734

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rajeshreeputra created an issue. See original summary.

rajeshreeputra’s picture

Title: Provide asset metadata refresh command » Provide asset metadata refresh/sync command
Status: Active » Needs review

Requesting review.

rajeshreeputra’s picture

Status: Needs review » Fixed

MR merged!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • rajeshreeputra committed 2ad941dd on 1.1.x-webhook
    Resolve #3609734 "Provide asset metadata refresh/sync command."
    

  • rajeshreeputra committed a715f84a on 1.1.x
    Resolve #3609734 "Add limit and offset option to asset metadata sync...