Permalink
Browse files

MDL-42767 notes: Delete notes on a course delete

  • Loading branch information...
ankitagarwal authored and marinaglancy committed Nov 8, 2013
1 parent ffe199b commit bdfb46a2d05bb4bf0541a6aecb6d2f7fc9917974
Showing with 35 additions and 1 deletion.
  1. +12 −0 lib/db/upgrade.php
  2. +4 −0 lib/moodlelib.php
  3. +18 −0 lib/tests/moodlelib_test.php
  4. +1 −1 version.php
View
@@ -2849,6 +2849,18 @@ function xmldb_main_upgrade($oldversion) {
// Moodle v2.6.0 release upgrade line.
// Put any upgrade step following this.
+ if ($oldversion < 2013111800.01) {
+
+ // Delete notes of deleted courses.
+ $sql = "DELETE FROM {post}
+ WHERE NOT EXISTS (SELECT {course}.id FROM {course}
+ WHERE {course}.id = {post}.courseid)
+ AND {post}.module = ?";
+ $DB->execute($sql, array('notes'));
+
+ // Main savepoint reached.
+ upgrade_main_savepoint(true, 2013111800.01);
+ }
return true;
}
View
@@ -4960,6 +4960,7 @@ function remove_course_contents($courseid, $showfeedback = true, array $options
require_once($CFG->dirroot.'/tag/coursetagslib.php');
require_once($CFG->dirroot.'/comment/lib.php');
require_once($CFG->dirroot.'/rating/lib.php');
+ require_once($CFG->dirroot.'/notes/lib.php');
// Handle course badges.
badges_handle_course_deletion($courseid);
@@ -5122,6 +5123,9 @@ function remove_course_contents($courseid, $showfeedback = true, array $options
// Filters be gone!
filter_delete_all_for_context($coursecontext->id);
+ // Notes, you shall not pass!
+ note_delete_all($course->id);
+
// Die comments!
comment::delete_comments($coursecontext->id);
@@ -2612,6 +2612,24 @@ public function test_user_updated_event() {
}
}
+ /**
+ * Test remove_course_content deletes course contents
+ * TODO Add asserts to verify other data related to course is deleted as well.
+ */
+ public function test_remove_course_contents() {
+
+ $this->resetAfterTest();
+
+ $course = $this->getDataGenerator()->create_course();
+ $user = $this->getDataGenerator()->create_user();
+ $gen = $this->getDataGenerator()->get_plugin_generator('core_notes');
+ $note = $gen->create_instance(array('courseid' => $course->id, 'userid' => $user->id));
+
+ $this->assertNotEquals(false, note_load($note->id));
+ remove_course_contents($course->id, false);
+ $this->assertFalse(note_load($note->id));
+ }
+
/**
* Test function username_load_fields_from_object().
*/
View
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2013111800.00; // 20131118 = branching date YYYYMMDD - do not modify!
+$version = 2013111800.01; // 20131118 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.

0 comments on commit bdfb46a

Please sign in to comment.