From a43e85d5e449eff0e270e9b3e8933e4a402df74d Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Mon, 24 Apr 2017 16:06:48 +0800 Subject: [PATCH] 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. --- mod/assign/db/upgrade.php | 38 ++++++++++++++++++++++++++++++++++++++ mod/assign/version.php | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/mod/assign/db/upgrade.php b/mod/assign/db/upgrade.php index 6a128fd55c8..e22b19d444c 100644 --- a/mod/assign/db/upgrade.php +++ b/mod/assign/db/upgrade.php @@ -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; } diff --git a/mod/assign/version.php b/mod/assign/version.php index 2ca508dd0c1..dc449a8b452 100644 --- a/mod/assign/version.php +++ b/mod/assign/version.php @@ -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;