Skip to content

Commit

Permalink
Merge branch 'MDL-48880' of git://github.com/jmvedrine/moodle
Browse files Browse the repository at this point in the history
Conflicts:
	mod/lesson/db/upgrade.php
	mod/lesson/version.php
  • Loading branch information
danpoltawski committed Mar 31, 2015
2 parents 4e664d1 + 7e0551f commit deadda2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
19 changes: 18 additions & 1 deletion mod/lesson/backup/moodle2/restore_lesson_stepslib.php
Expand Up @@ -261,7 +261,7 @@ protected function after_execute() {
}
$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.

Expand All @@ -281,6 +281,23 @@ protected function after_execute() {
}
$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
Expand Down
21 changes: 21 additions & 0 deletions mod/lesson/db/upgrade.php
Expand Up @@ -242,5 +242,26 @@ function xmldb_lesson_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2015032600, '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;
}
2 changes: 2 additions & 0 deletions mod/lesson/locallib.php
Expand Up @@ -2033,6 +2033,8 @@ final public function delete() {

// 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
Expand Down
2 changes: 1 addition & 1 deletion mod/lesson/version.php
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2015032600; // 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;

0 comments on commit deadda2

Please sign in to comment.