From c5c9185801ee6c9cfc3b933c2c67dd383fda40c1 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Mon, 20 Feb 2023 14:40:58 +0000 Subject: [PATCH] MDL-77312 files: exclude drafts when determining license usage. --- lib/licenselib.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/licenselib.php b/lib/licenselib.php index 9a647e3a91b..3296640a10d 100644 --- a/lib/licenselib.php +++ b/lib/licenselib.php @@ -176,8 +176,9 @@ class license_manager { if (!empty($licensetodelete)) { if ($licensetodelete->custom == self::CUSTOM_LICENSE) { - // Check that the license is not in use by any files, if so it cannot be deleted. - $countfilesusinglicense = $DB->count_records('files', ['license' => $licenseshortname]); + // Check that the license is not in use by any non-draft files, if so it cannot be deleted. + $countfilesselect = 'license = :license AND NOT (component = \'user\' AND filearea = \'draft\')'; + $countfilesusinglicense = $DB->count_records_select('files', $countfilesselect, ['license' => $licenseshortname]); if ($countfilesusinglicense > 0) { throw new moodle_exception('cannotdeletelicenseinuse', 'license'); }