Problem/Motivation
First and foremost, the challenge revolves around the fact that “we” (aka. Acquia DAM) do not own the media entities (in terms of their entity type is not defined by us) but we still have some responsibility over their future existence. We only practice ownership over the source plugins the media items rely on.
When the module gets uninstalled, thus our source plugins are gone, then all the media items that once relied on them, still remain in the system.
In such a divided situation, when the module gets re-installed for any reason (debatable how realistic case it is), then we face a somewhat different landscape compared to a vanilla-fresh installation. For example, various problems stem from getting the media__acquia_dam_asset_id DB table dropped during uninstallation of the module.
Problem I. – Inconsistent listing results after module reinstallation
After reinstalling the module existing media items once created with DAM-related media types still appear on Drupal core's media listing page but they all disappear from the module's own “DAM assets” listing page. Administrators may find this discrepancy disturbing as it confuses them about whether these media items still exist or have been gone.
Steps to reproduce
- Install the module, authenticate the site-wide client and your user account too with Widen.
- Create any media items through DAM. Ensure that in the
media__acquia_dam_asset_idtable, a record representing it exists. - Visit the /admin/content/media page. Ensure that the media item is listed.
- Visit the /admin/content/dam-media page. Ensure that the media item is listed here too.
- Uninstall the module either via the GUI or by the Drush command. Ensure that the
media__acquia_dam_asset_idtable gets dropped in the DB. - Install the module again by any means mentioned above. Ensure that the
media__acquia_dam_asset_idtable got created fully empty. - Authenticate the site-wide client and your user account too with Widen.
- Visit the /admin/content/media page. Ensure that the media item is still listed.
- Visit the /admin/content/dam-media page.
- Expected: the media item should be listed because Core's media table still holds a record of it.
- Actual: the list is empty.
This is because the current filtering logic implemented as a Views filter (source code) strictly checks the existence of records within the media__acquia_dam_asset_id table. However, when the module uninstalls, this table – among others – gets dropped, but the media items created remain. Next time, when the module is installed again the still existing media items have no mention in the examined DB table, therefore the Views listing returns empty results.
Proposed resolutions
-
Add exclusion of the
media__acquia_dam_asset_idtable on module uninstallation. Arguments:- Pro: probably the easiest solution
- Contra: residue remains in the DB which is against the general best-practice of the Drupal ecosystem.
OR
-
Alter the module process to let the administrator decide when uninstalling the module whether they want to preserve this table or not. Explain them the reasoning why is it asked. If opted to preserve, then see option #1. Suggest a default option for this decision (probably to not preserve).
- Pro: best of both worlds, responsibility given to human instead of false but hardcoded assumptions.
- Contra: research needed on how easy to alter the module uninstallation process.
OR
-
Change the filtering logic to check different values to tell whether a DAM-related media item still exists or not.
- Pro: no user interface change, only the information content gets improved.
- Contra: needs to figure out what other values we can check (for example the existence of
acquia_dam_managed_file/acquia_dam_managed_imagefields? Obviously thius can happen )
Problem II. – Misleading the asset update checking logic
The asset update checking logic (added in #3443055: Handling media items when their asset gets unavailable in Widen) believes that a media item existing from earlier installation is still DAM-related, but actually it is not anymore after it looses all its connection to their asset ID.
Problem III. – Previously saved local files blocks the URI from fresh data being stored
In #3490413: Prepare our file handling logic to residue left behind from previous installations, some further logic has been outlined regarding how we could free up the file system before saving the freshly fetched data: thumbnail images + asset files (if on-site storing is enabled).
Reminder: we cannot simply erase the two DAM-related directories in {webroot}/sites/default/files, because media entities might still exist and reference their associated managed file entities, which those files on disk belong to.
Comments
Comment #2
baluertlComment #3
baluertlComment #4
baluertlComment #5
baluertlComment #6
baluertlComment #7
baluertl