MDL-67062 core_h5p: delete cache assets when removing libraries
authorSara Arjona <sara@moodle.com>
Sat, 1 Feb 2020 13:51:27 +0000 (14:51 +0100)
committerSara Arjona <sara@moodle.com>
Wed, 26 Feb 2020 18:55:34 +0000 (19:55 +0100)
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

index 4818d86..3a2dc33 100644 (file)
@@ -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;