Skip to content

Commit

Permalink
MDL-58573 mod_assign: Upgrade code for default gradingduedate
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
junpataleta committed Apr 28, 2017
1 parent 5ccddd2 commit a43e85d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions mod/assign/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion mod/assign/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit a43e85d

Please sign in to comment.