Skip to content

Commit

Permalink
MDL-56251 format_weeks: add upgrade for new 'automaticenddate' setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed May 5, 2017
1 parent b0f0200 commit 9f8a15b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions course/format/weeks/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,40 @@ function xmldb_format_weeks_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2017020200, 'format', 'weeks');
}

if ($oldversion < 2017050300) {
// Go through the existing courses using the weeks format with no value set for the 'automaticenddate'.
$sql = "SELECT c.id, c.enddate, cfo.id as cfoid
FROM {course} c
LEFT JOIN {course_format_options} cfo
ON cfo.courseid = c.id
AND cfo.format = c.format
AND cfo.name = :optionname
AND cfo.sectionid = 0
WHERE c.format = :format
AND cfo.id IS NULL";
$params = ['optionname' => 'automaticenddate', 'format' => 'weeks'];
$courses = $DB->get_recordset_sql($sql, $params);
foreach ($courses as $course) {
$option = new stdClass();
$option->courseid = $course->id;
$option->format = 'weeks';
$option->sectionid = 0;
$option->name = 'automaticenddate';
if (empty($course->enddate)) {
$option->value = 1;
$DB->insert_record('course_format_options', $option);

// Now, let's update the course end date.
format_weeks::update_end_date($course->id);
} else {
$option->value = 0;
$DB->insert_record('course_format_options', $option);
}
}
$courses->close();

upgrade_plugin_savepoint(true, 2017050300, 'format', 'weeks');
}

return true;
}
2 changes: 1 addition & 1 deletion course/format/weeks/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@

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

$plugin->version = 2017050200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2017050300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2016112900; // Requires this Moodle version.
$plugin->component = 'format_weeks'; // Full name of the plugin (used for diagnostics).

0 comments on commit 9f8a15b

Please sign in to comment.