From 2b8d97326dc692f4eee94692e1aa4b36cf704dcc Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Sat, 1 Feb 2020 14:51:27 +0100 Subject: [PATCH] MDL-67062 core_h5p: delete cache assets when removing libraries The cache assets linked to a library have to be removed also when a library is deleted, in order to rebuild them again next time they are required. --- h5p/classes/framework.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/h5p/classes/framework.php b/h5p/classes/framework.php index 4818d861224..3a2dc33574e 100644 --- a/h5p/classes/framework.php +++ b/h5p/classes/framework.php @@ -1138,6 +1138,8 @@ class framework implements \H5PFrameworkInterface { $fs = new \core_h5p\file_storage(); // Delete the library from the file system. $fs->delete_library(array('libraryId' => $library->id)); + // Delete also the cache assets to rebuild them next time. + $this->deleteCachedAssets($library->id); // Remove library data from database. $DB->delete_records('h5p_library_dependencies', array('libraryid' => $library->id)); @@ -1451,6 +1453,10 @@ class framework implements \H5PFrameworkInterface { list($sql, $params) = $DB->get_in_or_equal($hashes, SQL_PARAMS_NAMED); // Remove all invalid keys. $DB->delete_records_select('h5p_libraries_cachedassets', 'hash ' . $sql, $params); + + // Remove also the cachedassets files. + $fs = new file_storage(); + $fs->deleteCachedAssets($hashes); } return $hashes;