Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#11] Only delete programs events in cron task #12

Open
wants to merge 1 commit into
base: MOODLE_401_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions classes/local/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public static function fix_program_events(?stdClass $program): void {
LEFT JOIN {enrol_programs_allocations} pa ON pa.id = e.instance AND e.component = 'enrol_programs'
LEFT JOIN {enrol_programs_programs} p ON p.id = pa.programid
WHERE (pa.id IS NULL OR pa.archived = 1 OR p.archived = 1 OR pa.timecompleted IS NOT NULL)
AND e.component = 'enrol_programs'
$programselect
ORDER BY e.id ASC";
$rs = $DB->get_recordset_sql($sql, $params);
Expand Down
38 changes: 37 additions & 1 deletion tests/local/calendar_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1014,4 +1014,40 @@ public function test_archiving() {
['component' => 'enrol_programs', 'instance' => $allocation1x1->id, 'eventtype' => calendar::EVENTTYPE_START]);
$this->assertFalse($event);
}
}

/**
* Tests that manual events are not deleted by fixing program events
*
* @see https://github.com/open-lms-open-source/moodle-enrol_programs/issues/11 Issue
*/
public function test_manual_calendar_events_not_deleted_by_fix_program_events() {
global $DB, $USER;
$this->setAdminUser();

$event = new \stdClass();
$event->userid = $USER->id;
$event->timestart = 0;
$event->name = 'test';

// Manually created events have modulename 0 and component as null.
$event->modulename = 0;
$event->component = null;

\calendar_event::create($event);

$events = $DB->get_records('event');
$this->assertCount(1, $events);
$event = current($events);
$this->assertNull($event->component);
$this->assertEquals(0, $event->modulename);

// Run fix events, as if cron would run it.
calendar::fix_program_events(null);

// Ensure calendar event that was created is left untouched.
$events = $DB->get_records('event');
$eventids = array_column($events, 'id');
$this->assertTrue(in_array($event->id, $eventids));
}
}