MDL-48880 mod_lesson: clean lesson_branch when a page is deleted
This commit is contained in:
@@ -255,7 +255,7 @@ class restore_lesson_activity_structure_step extends restore_activity_structure_
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
// Replay the upgrade step 2015022700
|
||||
// Replay the upgrade step 2015030301
|
||||
// to clean lesson answers that should be plain text.
|
||||
// 1 = LESSON_PAGE_SHORTANSWER, 8 = LESSON_PAGE_NUMERICAL, 20 = LESSON_PAGE_BRANCHTABLE.
|
||||
|
||||
@@ -275,6 +275,23 @@ class restore_lesson_activity_structure_step extends restore_activity_structure_
|
||||
}
|
||||
$badanswers->close();
|
||||
|
||||
// Replay the upgrade step 2015032700.
|
||||
// Delete any orphaned lesson_branch record.
|
||||
if ($DB->get_dbfamily() === 'mysql') {
|
||||
$sql = "DELETE {lesson_branch}
|
||||
FROM {lesson_branch}
|
||||
LEFT JOIN {lesson_pages}
|
||||
ON {lesson_branch}.pageid = {lesson_pages}.id
|
||||
WHERE {lesson_pages}.id IS NULL";
|
||||
} else {
|
||||
$sql = "DELETE FROM {lesson_branch}
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 'x' FROM {lesson_pages}
|
||||
WHERE {lesson_branch}.pageid = {lesson_pages}.id)";
|
||||
}
|
||||
|
||||
$DB->execute($sql);
|
||||
|
||||
// Re-map the dependency and activitylink information
|
||||
// If a depency or activitylink has no mapping in the backup data then it could either be a duplication of a
|
||||
// lesson, or a backup/restore of a single lesson. We have no way to determine which and whether this is the
|
||||
|
||||
@@ -232,5 +232,26 @@ function xmldb_lesson_upgrade($oldversion) {
|
||||
upgrade_mod_savepoint(true, 2015031500, 'lesson');
|
||||
}
|
||||
|
||||
if ($oldversion < 2015032700) {
|
||||
// Delete any orphaned lesson_branch record.
|
||||
if ($DB->get_dbfamily() === 'mysql') {
|
||||
$sql = "DELETE {lesson_branch}
|
||||
FROM {lesson_branch}
|
||||
LEFT JOIN {lesson_pages}
|
||||
ON {lesson_branch}.pageid = {lesson_pages}.id
|
||||
WHERE {lesson_pages}.id IS NULL";
|
||||
} else {
|
||||
$sql = "DELETE FROM {lesson_branch}
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 'x' FROM {lesson_pages}
|
||||
WHERE {lesson_branch}.pageid = {lesson_pages}.id)";
|
||||
}
|
||||
|
||||
$DB->execute($sql);
|
||||
|
||||
// Lesson savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2015032700, 'lesson');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2033,6 +2033,8 @@ abstract class lesson_page extends lesson_base {
|
||||
|
||||
// Then delete all the associated records...
|
||||
$DB->delete_records("lesson_attempts", array("pageid" => $this->properties->id));
|
||||
|
||||
$DB->delete_records("lesson_branch", array("pageid" => $this->properties->id));
|
||||
// ...now delete the answers...
|
||||
$DB->delete_records("lesson_answers", array("pageid" => $this->properties->id));
|
||||
// ..and the page itself
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2015032401; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2015032700; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2014110400; // Requires this Moodle version
|
||||
$plugin->component = 'mod_lesson'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->cron = 0;
|
||||
|
||||
Reference in New Issue
Block a user