Skip to content

Commit

Permalink
MDL-43371 mod_lesson: Remove files upon page or module deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
FMCorz committed Jan 9, 2014
1 parent e92da00 commit 40f8aec
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mod/lesson/locallib.php
Expand Up @@ -951,6 +951,9 @@ public function delete() {
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/calendar/lib.php');

$cm = get_coursemodule_from_instance('lesson', $this->properties->id, $this->properties->course);
$context = context_module::instance($cm->id);

$DB->delete_records("lesson", array("id"=>$this->properties->id));
$DB->delete_records("lesson_pages", array("lessonid"=>$this->properties->id));
$DB->delete_records("lesson_answers", array("lessonid"=>$this->properties->id));
Expand All @@ -966,6 +969,10 @@ public function delete() {
}
}

// Delete files associated with this module.
$fs = get_file_storage();
$fs->delete_area_files($context->id);

grade_update('mod/lesson', $this->properties->course, 'mod', 'lesson', $this->properties->id, 0, null, array('deleted'=>1));
return true;
}
Expand Down Expand Up @@ -1820,6 +1827,12 @@ final public function delete() {
// ..and the page itself
$DB->delete_records("lesson_pages", array("id" => $this->properties->id));

// Delete files associated with this page.
$cm = get_coursemodule_from_instance('lesson', $this->lesson->id, $this->lesson->course);
$context = context_module::instance($cm->id);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'mod_lesson', 'page_contents', $this->properties->id);

// repair the hole in the linkage
if (!$this->properties->prevpageid && !$this->properties->nextpageid) {
//This is the only page, no repair needed
Expand Down

0 comments on commit 40f8aec

Please sign in to comment.