From 4202104a2ee4690f39eae655852da9a9347be9f2 Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Tue, 8 Mar 2022 09:55:56 +0000 Subject: [PATCH] MDL-74123 h5p: delete any existing files when downloading new files --- h5p/classes/core.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/h5p/classes/core.php b/h5p/classes/core.php index 3d45327e363..ec4150326bf 100644 --- a/h5p/classes/core.php +++ b/h5p/classes/core.php @@ -238,8 +238,22 @@ class core extends H5PCore { $factory = new factory(); - // Download the latest content type from the H5P official repository. $fs = get_file_storage(); + + // Delete any existing file, if it was not deleted during a previous download. + $existing = $fs->get_file( + (\context_system::instance())->id, + 'core_h5p', + 'library_sources', + 0, + '/', + $library['machineName'] + ); + if ($existing) { + $existing->delete(); + } + + // Download the latest content type from the H5P official repository. $file = $fs->create_file_from_url( (object) [ 'component' => 'core_h5p',