Skip to content

Commit

Permalink
Merge branch 'MDL-77312-400' of https://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_400_STABLE
  • Loading branch information
sarjona committed May 3, 2023
2 parents 63d423f + 71cc91a commit 4b0a13b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/licenselib.php
Expand Up @@ -186,8 +186,9 @@ static public function delete($licenseshortname) {

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');
}
Expand Down

0 comments on commit 4b0a13b

Please sign in to comment.