MDL-58573 mod_assign: Upgrade code for default gradingduedate

* Set default grading due date one week from the due date if:
  - there is no grading due date set; and
  - the assignment's due date is not older than 3 weeks from the
    current date.
This commit is contained in:
Jun Pataleta
2017-04-28 10:28:35 +08:00
parent 5ccddd27df
commit a43e85d5e4
2 changed files with 39 additions and 1 deletions
+38
View File
@@ -296,5 +296,43 @@ function xmldb_assign_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2017031300, 'assign');
}
if ($oldversion < 2017042800) {
// Update query to set the grading due date one week after the due date.
// Only assign instances with grading due date not set and with a due date of not older than 3 weeks will be updated.
$sql = "UPDATE {assign}
SET gradingduedate = duedate + :weeksecs
WHERE gradingduedate = 0
AND duedate > :timelimit";
// Calculate the time limit, which is 3 weeks before the current date.
$interval = new DateInterval('P3W');
$timelimit = new DateTime();
$timelimit->sub($interval);
// Update query params.
$params = [
'weeksecs' => WEEKSECS,
'timelimit' => $timelimit->getTimestamp()
];
// Execute DB update for assign instances.
$DB->execute($sql, $params);
// Create adhoc task for upgrading of existing mod_assign calendar events.
$task = new \stdClass();
$task->classname = "\\core\\task\\refresh_mod_calendar_events_task";
$task->component = 'core';
// Next run time based from nextruntime computation in \core\task\manager::queue_adhoc_task().
$nextruntime = time() - 1;
$task->nextruntime = $nextruntime;
// Indicate to the adhoc task that only the assignment module will be refreshed.
$task->customdata = json_encode(['plugins' => ['assign']]);
$DB->insert_record('task_adhoc', $task);
// Assign savepoint reached.
upgrade_mod_savepoint(true, 2017042800, 'assign');
}
return true;
}
+1 -1
View File
@@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'mod_assign'; // Full name of the plugin (used for diagnostics).
$plugin->version = 2017031300; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2017042800; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2016112900; // Requires this Moodle version.
$plugin->cron = 60;