Fixed issue deleting customcerts

This commit is contained in:
Mark Nelson 2015-03-13 21:09:56 -07:00
parent e85807e298
commit 25171d1703

View file

@ -71,7 +71,7 @@ function customcert_update_instance($data, $mform) {
* @return bool true if successful * @return bool true if successful
*/ */
function customcert_delete_instance($id) { function customcert_delete_instance($id) {
global $DB; global $CFG, $DB;
// Ensure the customcert exists. // Ensure the customcert exists.
if (!$DB->get_record('customcert', array('id' => $id))) { if (!$DB->get_record('customcert', array('id' => $id))) {
@ -95,10 +95,14 @@ function customcert_delete_instance($id) {
ON e.pageid = p.id ON e.pageid = p.id
WHERE p.customcertid = :customcertid"; WHERE p.customcertid = :customcertid";
if ($elements = $DB->get_records_sql($sql, array('customcertid' => $id))) { if ($elements = $DB->get_records_sql($sql, array('customcertid' => $id))) {
require_once($CFG->dirroot . '/mod/customcert/locallib.php');
foreach ($elements as $element) { foreach ($elements as $element) {
// Get an instance of the element class. // Get an instance of the element class.
if ($e = customcert_get_element_instance($element)) { if ($e = customcert_get_element_instance($element)) {
return $e->delete_element(); $e->delete_element();
} else {
// The plugin files are missing, so just remove the entry from the DB.
$DB->delete_records('customcert_elements', array('id' => $element->id));
} }
} }
} }