function forumng_delete_instance($id) { global $DB; require_once dirname(__FILE__) . '/mod_forumng.php'; $cm = get_coursemodule_from_instance('forumng', $id); $forum = mod_forumng::get_from_id($id, mod_forumng::CLONE_DIRECT, true, $cm); $forum->delete_all_data(); if (mod_forumng::search_installed()) { $cm = $forum->get_course_module(); local_ousearch_document::delete_module_instance_data($cm); } if ($forum->is_shared()) { // Find all the clone instances. $clones = $forum->get_clone_details(); $transaction = $DB->start_delegated_transaction(); foreach ($clones as $clone) { if (!forumng_delete_instance($clone->cloneforumngid)) { notify("Could not delete the Clone forumng (id) {$clone->cloneforumngid} "); return false; } if (!delete_course_module($clone->context->instanceid)) { notify("Could not delete the Clone\n forumng (coursemoduleid) {$clone->context}->instanceid "); return false; } if (!delete_mod_from_section($clone->context->instanceid, $clone->sectionid)) { notify("Could not delete the sectionid {$clone->sectionid} from that section"); return false; } rebuild_course_cache($clone->courseid, true); } $transaction->allow_commit(); } return $DB->delete_records('forumng', array('id' => $id)); }
function wipe_forumng($cm) { forum_utils::start_transaction(); // Tell forum to delete itself if (!forumng_delete_instance($cm->instance)) { throw new Exception("Could not delete forum instance {$cm->instance}"); } // Delete course_module entry if (!delete_records('course_modules', 'id', $cm->id)) { throw new Exception("Could not delete course module {$cm->id}"); } // Update section if (!delete_mod_from_section($cm->id, $cm->section)) { throw new Exception("Could not delete module {$cm->id} from section {$cm->section}"); } forum_utils::finish_transaction(); }
function wipe_forumng($cm) { global $DB; $transaction = $DB->start_delegated_transaction(); // Tell forum to delete itself if (!forumng_delete_instance($cm->instance)) { throw new Exception("Could not delete forum instance {$cm->instance}"); } // Delete course_module entry $DB->delete_records('course_modules', array('id' => $cm->id)); // Update section if (!delete_mod_from_section($cm->id, $cm->section)) { throw new Exception("Could not delete module {$cm->id} from section {$cm->section}"); } $transaction->allow_commit(); }