Created
March 17, 2015 13:29
-
-
Save hello-josh/c4a20f9612a3eadd030e to your computer and use it in GitHub Desktop.
Diff to enable deleting of non-empty subpages based on the 2013052400 version of mod_subpage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/mod/subpage/lib.php b/mod/subpage/lib.php | |
index 2050835..07ed4fa 100644 | |
--- a/mod/subpage/lib.php | |
+++ b/mod/subpage/lib.php | |
@@ -80,10 +80,17 @@ function subpage_delete_instance($id) { | |
// if deleting a subpage activity from course/mod.php page (not delete the whole course) | |
if ($PAGE->pagetype == 'course-mod') { | |
$subpagecmid = required_param('delete', PARAM_INT); | |
- // Check if all the sections in this subpage is empty | |
- $subpageinstance = mod_subpage::get_from_cmid($subpagecmid); | |
- $subpagesections = $DB->get_records('subpage_sections', | |
- array("subpageid" => $subpage->id), '', 'sectionid'); | |
+ } else { | |
+ $cm = get_coursemodule_from_instance('subpage', $id); | |
+ $subpagecmid = $cm->id; | |
+ } | |
+ // Check if all the sections in this subpage is empty | |
+ $subpageinstance = mod_subpage::get_from_cmid($subpagecmid); | |
+ $subpagesections = $DB->get_records('subpage_sections', | |
+ array("subpageid" => $subpage->id), '', 'sectionid'); | |
+ // retain original functionality of erroring if you try | |
+ // to delete a non-empty section when happening from the course-mod page | |
+ if ($PAGE->pagetype == 'course-mod') { | |
foreach ($subpagesections as $sections) { | |
if (!$subpageinstance->is_section_empty($sections->sectionid)) { | |
// Section is not empty | |
@@ -91,10 +98,11 @@ function subpage_delete_instance($id) { | |
print_error('error_deletingsubpage', 'mod_subpage', $url); | |
} | |
} | |
- // all sections are empty, delete the empty sections | |
- foreach ($subpagesections as $sections) { | |
- $subpageinstance->delete_section($sections->sectionid); | |
- } | |
+ } | |
+ | |
+ // all sections are empty, delete the empty sections | |
+ foreach ($subpagesections as $sections) { | |
+ $subpageinstance->delete_section($sections->sectionid); | |
} | |
// Delete main table and sections |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment