All media_download_all: cache tags should be invalidate during media deletion

Created on 31 March 2023, over 1 year ago

Problem/Motivation

All media_download_all: cache tags should be invalidate during media deletion.

Steps to reproduce

  • Create node with media field
  • Add 2 medias
  • Download all media
  • Remove first media using contextual link / single media page or media manager page
  • Download all media
  • You can still see 2 medias because MDA does not know about any actions under your media entities.

Proposed resolution

  • Create service to get all media_download_all: tags from DB and invalidate them during media deletion in hook_media_delete
public function invalidateTags() {
    $connectionSettings = Database::getConnection();
    $prefix = $connectionSettings->getConnectionOptions()['prefix'];
    $tags = $this->database->query("SELECT * FROM {$prefix}cache_default WHERE cid LIKE '%media_download_all:%'")
      ->fetchAll();

    foreach ($tags as $tag) {
      $cid = $tag->cid;
      $cache = $this->cache->get($cid);
      if ($cache) {
        $cached_files = $cache->data;
        if (!empty($cached_files)) {
          foreach ($cached_files as $file) {
            unlink($file);
          }
        }
        $this->cache->delete($cid);
      }
    }
  }

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇵🇱Poland lamp5 Rzeszow

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

Comments & Activities

Production build 0.71.5 2024