Skip to content

Commit

Permalink
Merge branch 'MDL-58777-master' of git://github.com/cameron1729/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed May 11, 2017
2 parents 3a7afbe + 79b80ee commit e84fefd
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 107 deletions.
7 changes: 3 additions & 4 deletions lib/classes/task/refresh_mod_calendar_events_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ public function execute() {
continue;
}
// Check if the plugin implements *_refresh_events() and call it when it does.
$refresheventsfunction = $plugin->name . '_refresh_events';
if (function_exists($refresheventsfunction)) {
mtrace('Calling ' . $refresheventsfunction);
call_user_func($refresheventsfunction);
if (component_callback_exists('mod_' . $plugin->name, 'refresh_events')) {
mtrace('Refreshing events for ' . $plugin->name);
component_callback('mod_' . $plugin->name, 'refresh_events');
}
}
}
Expand Down
62 changes: 15 additions & 47 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2566,19 +2566,6 @@ function xmldb_main_upgrade($oldversion) {
$dbman->add_field($table, $field);
}

// Create adhoc task for upgrading of existing calendar events.
$record = new \stdClass();
$record->classname = "\\core\\task\\refresh_mod_calendar_events_task";
$record->component = 'core';
// Next run time based from nextruntime computation in \core\task\manager::queue_adhoc_task().
$nextruntime = time() - 1;
$record->nextruntime = $nextruntime;
$DB->insert_record('task_adhoc', $record);

// This same task is queued again in a later step, but if we already queue it here
// then there is no need to queue it again. We use this flag in the second step.
$refresheventsadhocadded = true;

// Main savepoint reached.
upgrade_main_savepoint(true, 2017030700.00);
}
Expand Down Expand Up @@ -2671,21 +2658,6 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2017040402.00);
}

if ($oldversion < 2017040403.00) {
// Create adhoc task for upgrading of existing calendar events.
$record = new \stdClass();
$record->classname = "\\core\\task\\refresh_mod_calendar_events_task";
$record->component = 'core';

// Next run time based from nextruntime computation in \core\task\manager::queue_adhoc_task().
$nextruntime = time() - 1;
$record->nextruntime = $nextruntime;
$DB->insert_record('task_adhoc', $record);

// Main savepoint reached.
upgrade_main_savepoint(true, 2017040403.00);
}

if ($oldversion < 2017040700.01) {

// Define table oauth2_issuer to be created.
Expand Down Expand Up @@ -2838,25 +2810,6 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2017041801.00);
}

if ($oldversion < 2017042600.01) {
// If the previous step didn't execute and queue the task.
if (!isset($refresheventsadhocadded)) {
// Create adhoc task for upgrading of existing calendar events.
$record = new \stdClass();
$record->classname = "\\core\\task\\refresh_mod_calendar_events_task";
$record->component = 'core';

// Next run time based from nextruntime computation in \core\task\manager::queue_adhoc_task().
$nextruntime = time() - 1;
$record->nextruntime = $nextruntime;
$DB->insert_record('task_adhoc', $record);

}

// Main savepoint reached.
upgrade_main_savepoint(true, 2017042600.01);
}

if ($oldversion < 2017050500.01) {
// Get the list of parent event IDs.
$sql = "SELECT DISTINCT repeatid
Expand Down Expand Up @@ -2894,5 +2847,20 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2017050500.02);
}

if ($oldversion < 2017050900.01) {
// Create adhoc task for upgrading of existing calendar events.
$record = new \stdClass();
$record->classname = '\core\task\refresh_mod_calendar_events_task';
$record->component = 'core';

// Next run time based from nextruntime computation in \core\task\manager::queue_adhoc_task().
$nextruntime = time() - 1;
$record->nextruntime = $nextruntime;
$DB->insert_record('task_adhoc', $record);

// Main savepoint reached.
upgrade_main_savepoint(true, 2017050900.01);
}

return true;
}
41 changes: 0 additions & 41 deletions mod/assign/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,35 +253,6 @@ function xmldb_assign_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2017021500, 'assign');
}

if ($oldversion < 2017031000) {
// Set priority of assign user overrides.
$params = [
'modulename' => 'assign',
'courseid' => 0,
'groupid' => 0,
'repeatid' => 0
];
// CALENDAR_EVENT_USER_OVERRIDE_PRIORITY has a value of 9999999.
$DB->set_field('event', 'priority', 9999999, $params);

// Set priority for group overrides for existing assign events.
$where = 'groupid IS NOT NULL';
$assignoverridesrs = $DB->get_recordset_select('assign_overrides', $where, null, '', 'id, assignid, groupid, sortorder');
foreach ($assignoverridesrs as $record) {
$params = [
'modulename' => 'assign',
'instance' => $record->assignid,
'groupid' => $record->groupid,
'repeatid' => 0
];
$DB->set_field('event', 'priority', $record->sortorder, $params);
}
$assignoverridesrs->close();

// Assign savepoint reached.
upgrade_mod_savepoint(true, 2017031000, 'assign');
}

if ($oldversion < 2017031300) {
// Add a 'gradingduedate' field to the 'assign' table.
$table = new xmldb_table('assign');
Expand Down Expand Up @@ -318,18 +289,6 @@ function xmldb_assign_upgrade($oldversion) {
// 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');
}
Expand Down
14 changes: 9 additions & 5 deletions mod/assign/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,17 @@ function assign_update_events($assign, $override = null) {
$conds['groupid'] = $override->groupid;
}
}
$oldevents = $DB->get_records('event', $conds);
$oldevents = $DB->get_records('event', $conds, 'id ASC');

// Now make a to-do list of all that needs to be updated.
if (empty($override)) {
// We are updating the primary settings for the assign, so we need to add all the overrides.
$overrides = $DB->get_records('assign_overrides', array('assignid' => $assigninstance->id));
// As well as the original assign (empty override).
$overrides[] = new stdClass();
// We are updating the primary settings for the assignment, so we need to add all the overrides.
$overrides = $DB->get_records('assign_overrides', array('assignid' => $assigninstance->id), 'id ASC');
// It is necessary to add an empty stdClass to the beginning of the array as the $oldevents
// list contains the original (non-override) event for the module. If this is not included
// the logic below will end up updating the wrong row when we try to reconcile this $overrides
// list against the $oldevents list.
array_unshift($overrides, new stdClass());
} else {
// Just do the one override.
$overrides = array($override);
Expand Down Expand Up @@ -272,6 +275,7 @@ function assign_update_events($assign, $override = null) {
$event->timesort = $event->timestart + $event->timeduration;
$event->visible = instance_is_visible('assign', $assigninstance);
$event->eventtype = ASSIGN_EVENT_TYPE_DUE;
$event->priority = null;

// Determine the event name and priority.
if ($groupid) {
Expand Down
12 changes: 8 additions & 4 deletions mod/lesson/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,17 @@ function lesson_update_events($lesson, $override = null) {
$conds['groupid'] = $override->groupid;
}
}
$oldevents = $DB->get_records('event', $conds);
$oldevents = $DB->get_records('event', $conds, 'id ASC');

// Now make a to-do list of all that needs to be updated.
if (empty($override)) {
// We are updating the primary settings for the lesson, so we need to add all the overrides.
$overrides = $DB->get_records('lesson_overrides', array('lessonid' => $lesson->id));
// As well as the original lesson (empty override).
$overrides[] = new stdClass();
$overrides = $DB->get_records('lesson_overrides', array('lessonid' => $lesson->id), 'id ASC');
// It is necessary to add an empty stdClass to the beginning of the array as the $oldevents
// list contains the original (non-override) event for the module. If this is not included
// the logic below will end up updating the wrong row when we try to reconcile this $overrides
// list against the $oldevents list.
array_unshift($overrides, new stdClass());
} else {
// Just do the one override.
$overrides = array($override);
Expand Down Expand Up @@ -167,6 +170,7 @@ function lesson_update_events($lesson, $override = null) {
$event->timesort = $available;
$event->visible = instance_is_visible('lesson', $lesson);
$event->eventtype = LESSON_EVENT_TYPE_OPEN;
$event->priority = null;

// Determine the event name and priority.
if ($groupid) {
Expand Down
14 changes: 9 additions & 5 deletions mod/quiz/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1205,14 +1205,17 @@ function quiz_update_events($quiz, $override = null) {
$conds['groupid'] = $override->groupid;
}
}
$oldevents = $DB->get_records('event', $conds);
$oldevents = $DB->get_records('event', $conds, 'id ASC');

// Now make a to-do list of all that needs to be updated.
if (empty($override)) {
// We are updating the primary settings for the lesson, so we need to add all the overrides.
$overrides = $DB->get_records('quiz_overrides', array('quiz' => $quiz->id));
// As well as the original quiz (empty override).
$overrides[] = new stdClass();
// We are updating the primary settings for the quiz, so we need to add all the overrides.
$overrides = $DB->get_records('quiz_overrides', array('quiz' => $quiz->id), 'id ASC');
// It is necessary to add an empty stdClass to the beginning of the array as the $oldevents
// list contains the original (non-override) event for the module. If this is not included
// the logic below will end up updating the wrong row when we try to reconcile this $overrides
// list against the $oldevents list.
array_unshift($overrides, new stdClass());
} else {
// Just do the one override.
$overrides = array($override);
Expand Down Expand Up @@ -1251,6 +1254,7 @@ function quiz_update_events($quiz, $override = null) {
$event->timesort = $timeopen;
$event->visible = instance_is_visible('quiz', $quiz);
$event->eventtype = QUIZ_EVENT_TYPE_OPEN;
$event->priority = null;

// Determine the event name and priority.
if ($groupid) {
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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

$version = 2017050900.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2017050900.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.

Expand Down

0 comments on commit e84fefd

Please sign in to comment.