Skip to content

Commit ceede39

Browse files
committed
Improve the logic for checking whether the Outlook calendar exists
1 parent ed31cd8 commit ceede39

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

classes/feature/calsync/main.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,23 @@ public function get_event_link_html($event) {
739739
*/
740740
public function calendar_exists(int $userid, string $outlookcalendarid): bool {
741741
try {
742+
if (empty($outlookcalendarid)) {
743+
return false;
744+
}
745+
742746
$apiclient = $this->construct_calendar_api($userid, true);
743747
$o365upn = utils::get_o365_upn($userid);
744-
if (empty($o365upn) || empty($outlookcalendarid)) {
745-
return false;
748+
749+
if (empty($o365upn)) {
750+
return true;
751+
}
752+
753+
$calendars = $apiclient->get_calendars($o365upn);
754+
755+
if (empty($calendars)) {
756+
return true;
746757
}
747758

748-
$calendars = $apiclient->get_calendars($o365upn) ?? [];
749759
foreach ($calendars as $calendar) {
750760
if (isset($calendar['id']) && $calendar['id'] === $outlookcalendarid) {
751761
return true;
@@ -754,7 +764,7 @@ public function calendar_exists(int $userid, string $outlookcalendarid): bool {
754764

755765
return false;
756766
} catch (moodle_exception $e) {
757-
return false;
767+
return true;
758768
}
759769
}
760770

0 commit comments

Comments
 (0)