Moodle

Custom course formats cannot cleanup data on course deletion because not implemented

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9.5, 1.9.6, 2.0
  • Fix Version/s: 2.0
  • Component/s: Course
  • Labels:
    None
  • Affected Branches:
    MOODLE_19_STABLE, MOODLE_20_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

When working with custom course formats (e.g. flexipage among others) that need extra information to describe information relationship, there is no hooking from core that triggers a format scope course cleanup.

Flexipage has a page_delete_course() callback that is never called from delete_course() call nor subcalls.

Result of this is that format_page and format_page_items are not deleted, which has no influence on a single platform, but is critical when roaming content from a moodle to another. In that case will gohst pages rebind accidentally to a newly restored course, aggegating old content (though assumed is was deleted !) to the course.

The fix is very simple :

Index: moodlelib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v
retrieving revision 1.960.2.127
diff -u -r1.960.2.127 moodlelib.php
— moodlelib.php 22 Apr 2009 08:39:33 -0000 1.960.2.127
+++ moodlelib.php 22 Jun 2009 12:29:46 -0000
@@ -3719,6 +3719,16 @@
}
}

+/// Clean up course format related things
+
+ $formatlib = $CFG->dirroot."/course/format/{$course->format}/lib.php";
+ if (file_exists($formatlib)){
+ include_once($formatlib);
+ $deletecourseformathook = $course->format.'_delete_course';
+ if (function_exists($deletecourseformathook)){ + $deletecourseformathook($course->id); + }
+ }

/// Clean up metacourse stuff

This fix calls the <formatname>_delete_course($courseid) callback in the current format implementation for the delted course. Portable to 2.0 I guess.

Cheers.

Issue Links

Activity

Hide
Martin Dougiamas added a comment -

+1 from me. Makes sense to you, Petr?

Show
Martin Dougiamas added a comment - +1 from me. Makes sense to you, Petr?
Hide
Petr Škoda (skodak) added a comment -

this would break really badly, we have to use frankenstyle prefixes for every plugins now, working on a fix...

Show
Petr Škoda (skodak) added a comment - this would break really badly, we have to use frankenstyle prefixes for every plugins now, working on a fix...
Hide
Petr Škoda (skodak) added a comment -

fixed, please use format_yourformat_course_delete($courseid) functions, thanks for the report

Show
Petr Škoda (skodak) added a comment - fixed, please use format_yourformat_course_delete($courseid) functions, thanks for the report

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: