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_cron→syncAssets()) only processes media whose DAM assets were recently edited (based onlastEditDate). 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_typeargument — only processes media of that type, preventing accidental bulk operations. - Uses
forceMappedFieldRefresh()logic (same as the "Sync metadata" UI action and theMediaItemUpdatercron worker) to unconditionally overwrite all mapped fields with current values fromgetMetadata(), 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 (
--resumeflag) — 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--resumepicks 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_assetsource 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 --resumeIssue fork acquia_dam-3609734
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
Comment #2
rajeshreeputraRequesting review.
Comment #5
rajeshreeputraMR merged!