Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit 3719a48

Browse files
Jean-Michel Vedrinemdjnelson
authored andcommitted
CONTRIB-5157 certificate: remove files in certificate_reset_userdata
1 parent 8bee30e commit 3719a48

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,22 @@ function certificate_reset_userdata($data) {
112112
$sql = "SELECT cert.id
113113
FROM {certificate} cert
114114
WHERE cert.course = :courseid";
115-
$DB->delete_records_select('certificate_issues', "certificateid IN ($sql)", array('courseid' => $data->courseid));
116-
$status[] = array('component' => $componentstr, 'item' => get_string('certificateremoved', 'certificate'), 'error' => false);
117-
}
115+
$params = array('courseid' => $data->courseid);
116+
$certificates = $DB->get_records_sql($sql, $params);
117+
$fs = get_file_storage();
118+
if ($certificates) {
119+
foreach ($certificates as $certid => $unused) {
120+
if (!$cm = get_coursemodule_from_instance('certificate', $certid)) {
121+
continue;
122+
}
123+
$context = context_module::instance($cm->id);
124+
$fs->delete_area_files($context->id, 'mod_certificate', 'issue');
125+
}
126+
}
118127

128+
$DB->delete_records_select('certificate_issues', "certificateid IN ($sql)", $params);
129+
$status[] = array('component' => $componentstr, 'item' => get_string('removecert', 'certificate'), 'error' => false);
130+
}
119131
// Updating dates - shift may be negative too
120132
if ($data->timeshift) {
121133
shift_course_mod_dates('certificate', array('timeopen', 'timeclose'), $data->timeshift, $data->courseid);

0 commit comments

Comments
 (0)