diff --git a/local/o365/classes/adminsetting/tabs.php b/local/o365/classes/adminsetting/tabs.php
index e2f72f69c..d4d6dabf9 100644
--- a/local/o365/classes/adminsetting/tabs.php
+++ b/local/o365/classes/adminsetting/tabs.php
@@ -30,8 +30,6 @@
use moodle_url;
use tabobject;
-defined('MOODLE_INTERNAL') || die();
-
/**
* A tab in the plugin configuration page.
*/
@@ -136,7 +134,7 @@ public function write_setting($data) {
* @param moodle_url|null $url An explicit URL to use instead of settings page section.
* @uses $CFG
*/
- public function addtab($id, $name, moodle_url $url = null) {
+ public function addtab($id, $name, ?moodle_url $url = null) {
if (empty($url)) {
$urlparams = [
'section' => $this->section,
diff --git a/local/o365/classes/adminsetting/usersynccreationrestriction.php b/local/o365/classes/adminsetting/usersynccreationrestriction.php
index 27d3c591b..934738ef4 100644
--- a/local/o365/classes/adminsetting/usersynccreationrestriction.php
+++ b/local/o365/classes/adminsetting/usersynccreationrestriction.php
@@ -72,8 +72,8 @@ public function __construct($name, $visiblename, $description, $defaultsetting)
];
$order = 0;
while ($order++ < 15) {
- $this->remotefields['extensionAttribute' . $order] = get_string('settings_fieldmap_field_extensionattribute', 'auth_oidc',
- $order);
+ $this->remotefields['extensionAttribute' . $order] = get_string('settings_fieldmap_field_extensionattribute',
+ 'auth_oidc', $order);
}
return parent::__construct($name, $visiblename, $description, $defaultsetting);
diff --git a/local/o365/classes/adminsetting/usersyncoptions.php b/local/o365/classes/adminsetting/usersyncoptions.php
index 9ba63fc90..1b1fb21a7 100644
--- a/local/o365/classes/adminsetting/usersyncoptions.php
+++ b/local/o365/classes/adminsetting/usersyncoptions.php
@@ -83,18 +83,18 @@ public function __construct($name, $visiblename, $description) {
*/
public function output_html($data, $query = '') {
global $OUTPUT;
- if (!$this->load_choices() or empty($this->choices)) {
+ if (!$this->load_choices() || empty($this->choices)) {
return '';
}
$default = $this->get_defaultsetting();
if (is_null($default)) {
- $default = array();
+ $default = [];
}
if (is_null($data)) {
- $data = array();
+ $data = [];
}
- $options = array();
- $defaults = array();
+ $options = [];
+ $defaults = [];
foreach ($this->choices as $key => $description) {
if (!empty($data[$key])) {
$checked = 'checked="checked"';
diff --git a/local/o365/classes/adminsetting/verifysetup.php b/local/o365/classes/adminsetting/verifysetup.php
index d1647c52a..f97c35b4f 100644
--- a/local/o365/classes/adminsetting/verifysetup.php
+++ b/local/o365/classes/adminsetting/verifysetup.php
@@ -87,14 +87,10 @@ public function output_html($data, $query = '') {
if (\local_o365\adminsetting\detectoidc::setup_step_complete() === true) {
$existingsetting = $this->config_read($this->name);
if (!empty($existingsetting)) {
- $messageattrs = [
- 'class' => 'permmessage'
- ];
+ $messageattrs = ['class' => 'permmessage'];
$message = \html_writer::tag('span', get_string('settings_detectperms_valid', 'local_o365'), $messageattrs);
} else {
- $messageattrs = [
- 'class' => 'permmessage'
- ];
+ $messageattrs = ['class' => 'permmessage'];
$message = \html_writer::tag('span', get_string('settings_detectperms_invalid', 'local_o365'), $messageattrs);
}
} else {
diff --git a/local/o365/classes/event/api_call_failed.php b/local/o365/classes/event/api_call_failed.php
index e10096683..d26a60177 100644
--- a/local/o365/classes/event/api_call_failed.php
+++ b/local/o365/classes/event/api_call_failed.php
@@ -25,8 +25,6 @@
namespace local_o365\event;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Event fired whenever a user subscribes to a calendar.
*/
diff --git a/local/o365/classes/event/calendar_subscribed.php b/local/o365/classes/event/calendar_subscribed.php
index 709ccaf88..7abb9d653 100644
--- a/local/o365/classes/event/calendar_subscribed.php
+++ b/local/o365/classes/event/calendar_subscribed.php
@@ -25,8 +25,6 @@
namespace local_o365\event;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Event fired whenever a user subscribes to a calendar.
*/
diff --git a/local/o365/classes/event/calendar_unsubscribed.php b/local/o365/classes/event/calendar_unsubscribed.php
index 66b932b02..d44183225 100644
--- a/local/o365/classes/event/calendar_unsubscribed.php
+++ b/local/o365/classes/event/calendar_unsubscribed.php
@@ -25,8 +25,6 @@
namespace local_o365\event;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Event fired whenever a user unsubscribes from a calendar.
*/
diff --git a/local/o365/classes/feature/calsync/form/element/calendar.php b/local/o365/classes/feature/calsync/form/element/calendar.php
index 747b6a856..e7ac753a9 100644
--- a/local/o365/classes/feature/calsync/form/element/calendar.php
+++ b/local/o365/classes/feature/calsync/form/element/calendar.php
@@ -50,15 +50,15 @@ class calendar extends \HTML_QuickForm_advcheckbox {
/**
* Constructor, accessed through __call constructor workaround.
*
- * @param string $elementName The name of the element.
- * @param string $elementLabel The label of the element.
+ * @param string $elementname The name of the element.
+ * @param string $elementlabel The label of the element.
* @param string $text Text that appears after the checkbox.
* @param array $attributes Array of checkbox attributes.
* @param array $customdata Array of form custom data.
*/
- public function calendarconstruct($elementName = null, $elementLabel = null, $text = null, $attributes = null,
+ public function calendarconstruct($elementname = null, $elementlabel = null, $text = null, $attributes = null,
$customdata = []) {
- parent::__construct($elementName, $elementLabel, $text, $attributes, null);
+ parent::__construct($elementname, $elementlabel, $text, $attributes, null);
$this->customdata = $customdata;
$this->_type = 'advcheckbox';
}
@@ -112,7 +112,7 @@ public function setValue($value) {
*
* @return string html for help button
*/
- function getHelpButton(){
+ public function getHelpButton(){
return $this->_helpbutton;
}
diff --git a/local/o365/classes/feature/calsync/form/subscriptions.php b/local/o365/classes/feature/calsync/form/subscriptions.php
index 36b972871..fec28c5ec 100644
--- a/local/o365/classes/feature/calsync/form/subscriptions.php
+++ b/local/o365/classes/feature/calsync/form/subscriptions.php
@@ -112,11 +112,11 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
$newsetting = [
'user_id' => $USER->id,
'o365calid' => $sitecalenderid,
- 'timecreated' => time()
+ 'timecreated' => time(),
];
$newsetting['id'] = $DB->insert_record('local_o365_calsettings', (object)$newsetting);
} else if (empty($fromform->settingcal) && !empty($usersetting)) {
- $DB->delete_records('local_o365_calsettings', array('user_id' => $USER->id));
+ $DB->delete_records('local_o365_calsettings', ['user_id' => $USER->id]);
}
// Determine and organize existing subscriptions.
@@ -176,7 +176,7 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
$eventdata = [
'objectid' => $currentcaldata[$caltype]['recid'],
'userid' => $USER->id,
- 'other' => ['caltype' => $caltype]
+ 'other' => ['caltype' => $caltype],
];
$event = \local_o365\event\calendar_unsubscribed::create($eventdata);
$event->trigger();
@@ -202,13 +202,13 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
'o365calid' => $syncwith,
'syncbehav' => $syncbehav,
'isprimary' => ($syncwith == $primarycalid) ? '1' : '0',
- 'timecreated' => time()
+ 'timecreated' => time(),
];
$newsub['id'] = $DB->insert_record('local_o365_calsub', (object)$newsub);
$eventdata = [
'objectid' => $newsub['id'],
'userid' => $USER->id,
- 'other' => ['caltype' => $caltype]
+ 'other' => ['caltype' => $caltype],
];
} else {
// Already subscribed, update behavior.
@@ -222,7 +222,7 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
$eventdata = [
'objectid' => $currentcaldata[$caltype]['recid'],
'userid' => $USER->id,
- 'other' => ['caltype' => $caltype]
+ 'other' => ['caltype' => $caltype],
];
}
$event = \local_o365\event\calendar_subscribed::create($eventdata);
@@ -241,13 +241,13 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
}
}
$todelete = (empty($fromform->settingcal)) ? $existingcoursesubs : array_diff_key($existingcoursesubs, $newcoursesubs);
- $toadd = (empty($fromform->settingcal)) ? array() : array_diff_key($newcoursesubs, $existingcoursesubs);
+ $toadd = (empty($fromform->settingcal)) ? [] : array_diff_key($newcoursesubs, $existingcoursesubs);
foreach ($todelete as $courseid => $unused) {
$DB->delete_records('local_o365_calsub', ['user_id' => $USER->id, 'caltype' => 'course', 'caltypeid' => $courseid]);
$eventdata = [
'objectid' => $USER->id,
'userid' => $USER->id,
- 'other' => ['caltype' => 'course', 'caltypeid' => $courseid]
+ 'other' => ['caltype' => 'course', 'caltypeid' => $courseid],
];
$event = \local_o365\event\calendar_unsubscribed::create($eventdata);
$event->trigger();
@@ -273,7 +273,7 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
$eventdata = [
'objectid' => $USER->id,
'userid' => $USER->id,
- 'other' => ['caltype' => 'course', 'caltypeid' => $courseid]
+ 'other' => ['caltype' => 'course', 'caltypeid' => $courseid],
];
$event = \local_o365\event\calendar_subscribed::create($eventdata);
$event->trigger();
@@ -297,7 +297,7 @@ public static function update_subscriptions($fromform, $primarycalid, $cancreate
$eventdata = [
'objectid' => $USER->id,
'userid' => $USER->id,
- 'other' => ['caltype' => 'course', 'caltypeid' => $courseid]
+ 'other' => ['caltype' => 'course', 'caltypeid' => $courseid],
];
$event = \local_o365\event\calendar_subscribed::create($eventdata);
$event->trigger();
diff --git a/local/o365/classes/feature/calsync/main.php b/local/o365/classes/feature/calsync/main.php
index de9bc00ea..2dca5ef20 100644
--- a/local/o365/classes/feature/calsync/main.php
+++ b/local/o365/classes/feature/calsync/main.php
@@ -32,8 +32,6 @@
use local_o365\utils;
use moodle_exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Calendar sync feature.
*/
@@ -54,7 +52,7 @@ class main {
* @param httpclient|null $httpclient
* @throws moodle_exception
*/
- public function __construct(clientdata $clientdata = null, httpclient $httpclient = null) {
+ public function __construct(?clientdata $clientdata = null, ?httpclient $httpclient = null) {
$this->clientdata = (!empty($clientdata)) ? $clientdata : clientdata::instance_from_oidc();
$this->httpclient = (!empty($httpclient)) ? $httpclient : new httpclient();
}
@@ -293,7 +291,7 @@ public function create_outlook_event_from_moodle_event($moodleventid) {
'emailAddress' => [
'name' => $groupobject->o365name,
'address' => $outlookgroupemail,
- ]
+ ],
],
'responseRequested' => false,
'isOrganizer' => true,
@@ -313,6 +311,7 @@ public function create_outlook_event_from_moodle_event($moodleventid) {
}
} catch (moodle_exception $e) {
// No token found, nothing to do.
+ debugging('Error creating group event. Details: ' . $e->getMessage());
}
}
}
@@ -478,7 +477,7 @@ public function update_outlook_event($moodleeventid) {
try {
$apiclient->update_event($idmaprec->outlookeventid, $updated, $o365upn);
} catch (moodle_exception $e) {
- // Do nothing.
+ mtrace('Error updating event: '.$e->getMessage());
}
}
}
@@ -539,30 +538,6 @@ protected function construct_outlook_group_email($courseid) {
return $groupemail;
}
- /**
- * Get group first and last name.
- * @param string $groupname The o365 group name.
- * @return array The first index is the first name and the second index is the last name.
- */
- protected function group_first_last_name($groupname) {
- $firstname = '';
- $lastname = '';
- if (empty($groupname)) {
- return array($firstname, $lastname);
- }
-
- $pos = strpos($groupname, ': ');
-
- if (false === $pos) {
- return array($firstname, $lastname);
- }
-
- $firstname = substr($groupname, 0, $pos + 1);
- $lastname = substr($groupname, $pos + 1);
- $lastname = trim($lastname);
- return array($firstname, $lastname);
- }
-
/**
* Create a new calendar in the user's o365 calendars.
*
diff --git a/local/o365/classes/feature/calsync/observers.php b/local/o365/classes/feature/calsync/observers.php
index d88e78f50..3d89ad2f0 100644
--- a/local/o365/classes/feature/calsync/observers.php
+++ b/local/o365/classes/feature/calsync/observers.php
@@ -75,8 +75,8 @@ public static function handle_user_enrolment_deleted(\core\event\user_enrolment_
'userid' => $userid,
'other' => [
'caltype' => 'course',
- 'caltypeid' => $courseid
- ]
+ 'caltypeid' => $courseid,
+ ],
];
$event = \local_o365\event\calendar_unsubscribed::create($eventdata);
$event->trigger();
diff --git a/local/o365/classes/feature/calsync/task/importfromoutlook.php b/local/o365/classes/feature/calsync/task/importfromoutlook.php
index 68f34d413..944d68879 100644
--- a/local/o365/classes/feature/calsync/task/importfromoutlook.php
+++ b/local/o365/classes/feature/calsync/task/importfromoutlook.php
@@ -28,8 +28,6 @@
use core_date;
use moodle_exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Scheduled task to check for new o365 events and sync them into Moodle.
*/
@@ -111,7 +109,7 @@ public function execute() {
// If all day event time is stored in Outlook only as UTC time and not in the local user time.
if (isset($event['isAllDay']) && $event['isAllDay'] == '1') {
// Need to make the time the same as the user preference so no time conversion.
- $user = $DB->get_record('user', array('id' => $calsub->user_id));
+ $user = $DB->get_record('user', ['id' => $calsub->user_id]);
if ($user->timezone == 99) {
$user->timezone = core_date::get_server_timezone();
}
@@ -137,7 +135,7 @@ public function execute() {
'eventid' => $moodleevent->id,
'outlookeventid' => $event['id'],
'origin' => 'o365',
- 'userid' => $calsub->user_id
+ 'userid' => $calsub->user_id,
];
$DB->insert_record('local_o365_calidmap', (object)$idmaprec);
mtrace('Successfully imported event #'.$moodleevent->id);
diff --git a/local/o365/classes/feature/calsync/task/syncoldevents.php b/local/o365/classes/feature/calsync/task/syncoldevents.php
index ae1423929..2f276920f 100644
--- a/local/o365/classes/feature/calsync/task/syncoldevents.php
+++ b/local/o365/classes/feature/calsync/task/syncoldevents.php
@@ -28,8 +28,6 @@
use local_o365\utils;
use moodle_exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* AdHoc task to sync existing Moodle calendar events with Microsoft 365.
*
@@ -125,7 +123,7 @@ protected function sync_siteevents($timecreated) {
$calsync->update_event_raw($event->eventuserid, $event->outlookeventid,
['attendees' => $subscribersprimary]);
} catch (moodle_exception $e) {
- // Do nothing.
+ mtrace('ERROR: ' . $e->getMessage());
}
} else {
$calid = null;
@@ -146,7 +144,7 @@ protected function sync_siteevents($timecreated) {
$subscribersprimary, [], $calid);
}
} catch (moodle_exception $e) {
- mtrace('ERROR: '.$e->getMessage());
+ mtrace('ERROR: ' . $e->getMessage());
}
}
@@ -269,6 +267,7 @@ protected function sync_courseevents($courseid, $timecreated) {
['attendees' => $eventattendees]);
} catch (moodle_exception $e) {
// Do nothing.
+ mtrace('Error updating event #' . $event->eventid . ': ' . $e->getMessage());
}
} else {
$calid = null;
@@ -327,7 +326,7 @@ protected function sync_courseevents($courseid, $timecreated) {
}
} catch (moodle_exception $e) {
// Could not sync this course event. Log and continue.
- mtrace('Error syncing course event #'.$event->eventid.': '.$e->getMessage());
+ mtrace('Error syncing course event #' . $event->eventid . ': ' . $e->getMessage());
}
}
$events->close();
diff --git a/local/o365/classes/feature/cohortsync/main.php b/local/o365/classes/feature/cohortsync/main.php
index 6471e081f..2eaa5e881 100644
--- a/local/o365/classes/feature/cohortsync/main.php
+++ b/local/o365/classes/feature/cohortsync/main.php
@@ -58,9 +58,11 @@ class main {
private $cohortlist;
/**
+ * Return the list of groups.
+ *
* @return array
*/
- public function get_grouplist() : array {
+ public function get_grouplist(): array {
if (is_null($this->grouplist)) {
$this->fetch_groups_from_cache();
}
@@ -69,9 +71,11 @@ public function get_grouplist() : array {
}
/**
+ * Return the list of cohorts.
+ *
* @return array
*/
- public function get_cohortlist() : array {
+ public function get_cohortlist(): array {
if (is_null($this->cohortlist)) {
$this->fetch_cohorts();
}
@@ -97,7 +101,7 @@ public function __construct(unified $graphclient) {
* @param int $cohortid
* @return bool
*/
- public function add_mapping(string $groupoid, int $cohortid) : bool {
+ public function add_mapping(string $groupoid, int $cohortid): bool {
global $DB;
if (!$groupoid || !$cohortid) {
@@ -136,7 +140,7 @@ public function add_mapping(string $groupoid, int $cohortid) : bool {
*
* @return array
*/
- public function get_mappings() : array {
+ public function get_mappings(): array {
global $DB;
$mappings = $DB->get_records('local_o365_objects', ['type' => 'group', 'subtype' => 'cohort']);
@@ -151,7 +155,7 @@ public function get_mappings() : array {
* @param int $cohortid
* @return void
*/
- public function delete_mapping_by_group_oid_and_cohort_id(string $groupoid, int $cohortid) : void {
+ public function delete_mapping_by_group_oid_and_cohort_id(string $groupoid, int $cohortid): void {
global $DB;
$params = ['objectid' => $groupoid, 'moodleid' => $cohortid];
@@ -164,7 +168,7 @@ public function delete_mapping_by_group_oid_and_cohort_id(string $groupoid, int
* @param int $id
* @return void
*/
- public function delete_mapping_by_id(int $id) : void {
+ public function delete_mapping_by_id(int $id): void {
global $DB;
$params = ['id' => $id];
@@ -177,7 +181,7 @@ public function delete_mapping_by_id(int $id) : void {
* This function populates the $this->grouplist with the groups fetched from
* the local Moodle cache.
*/
- public function fetch_groups_from_cache() : void {
+ public function fetch_groups_from_cache(): void {
global $DB;
$sql = 'SELECT *
@@ -197,7 +201,7 @@ public function fetch_groups_from_cache() : void {
/**
* Fetch cohorts from the local Moodle cache.
*/
- public function fetch_cohorts() : void {
+ public function fetch_cohorts(): void {
$systemcontext = context_system::instance();
$systemcohorts = cohort_get_cohorts($systemcontext->id, 0, 0);
$this->cohortlist = $systemcohorts['cohorts'];
@@ -208,7 +212,7 @@ public function fetch_cohorts() : void {
*
* @return bool
*/
- public function update_groups_cache() : bool {
+ public function update_groups_cache(): bool {
global $DB;
if (utils::update_groups_cache($this->graphclient, 1)) {
@@ -230,7 +234,7 @@ public function update_groups_cache() : bool {
* @param int $cohortid
* @return void
*/
- public function sync_members_by_group_oid_and_cohort_id(string $groupoid, int $cohortid) : void {
+ public function sync_members_by_group_oid_and_cohort_id(string $groupoid, int $cohortid): void {
$groupownersandmembers = $this->get_group_owners_and_members($groupoid);
if ($groupownersandmembers !== false) {
@@ -289,7 +293,7 @@ public function get_group_owners_and_members(string $groupoid) {
* @return void
*/
private function sync_cohort_members_by_cohort_id_and_microsoft_user_objects(int $cohortid,
- array $microsoftuserobjects) : void {
+ array $microsoftuserobjects): void {
global $DB;
$microsoftuseroids = array_column($microsoftuserobjects, 'id');
@@ -322,7 +326,7 @@ private function sync_cohort_members_by_cohort_id_and_microsoft_user_objects(int
* @param array $moodleuserids
* @return array
*/
- private function get_all_potential_user_details(array $microsoftuseroids, array $moodleuserids) : array {
+ private function get_all_potential_user_details(array $microsoftuseroids, array $moodleuserids): array {
global $DB;
if (empty($microsoftuseroids) && empty($moodleuserids)) {
@@ -366,7 +370,7 @@ private function get_all_potential_user_details(array $microsoftuseroids, array
* @param string $groupoid
* @return string
*/
- public function get_group_name_by_group_oid(string $groupoid) : string {
+ public function get_group_name_by_group_oid(string $groupoid): string {
$groupname = '';
foreach ($this->grouplist as $group) {
@@ -385,7 +389,7 @@ public function get_group_name_by_group_oid(string $groupoid) : string {
* @param int $cohortid
* @return string
*/
- public function get_cohort_name_by_cohort_id(int $cohortid) : string {
+ public function get_cohort_name_by_cohort_id(int $cohortid): string {
$cohortname = '';
if (is_null($this->cohortlist)) {
diff --git a/local/o365/classes/feature/courserequest/main.php b/local/o365/classes/feature/courserequest/main.php
index d37968506..ebf4ef648 100644
--- a/local/o365/classes/feature/courserequest/main.php
+++ b/local/o365/classes/feature/courserequest/main.php
@@ -25,8 +25,6 @@
namespace local_o365\feature\courserequest;
-defined('MOODLE_INTERNAL') || die();
-
use context_course;
use core_user;
use course_request;
@@ -36,9 +34,22 @@
use local_o365\utils;
use moodle_exception;
use stdClass;
+
+/**
+ * Main class for the course request from Microsoft Teams feature.
+ */
class main {
+ /**
+ * @var int The course request status: pending.
+ */
const COURSE_REQUEST_STATUS_PENDING = 0;
+ /**
+ * @var int The course request status: approved.
+ */
const COURSE_REQUEST_STATUS_APPROVED = 1;
+ /**
+ * @var int The course request status: rejected.
+ */
const COURSE_REQUEST_STATUS_REJECTED = 2;
/**
@@ -70,7 +81,7 @@ public function __construct(unified $graphclient, bool $debug = false) {
* @param string $eol
* @return void
*/
- protected function mtrace(string $msg, int $level = 0, string $eol = "\n") : void {
+ protected function mtrace(string $msg, int $level = 0, string $eol = "\n"): void {
if ($this->debug === true) {
if ($level) {
$msg = str_repeat('...', $level) . ' ' . $msg;
@@ -86,7 +97,7 @@ protected function mtrace(string $msg, int $level = 0, string $eol = "\n") : voi
* @param array $teamdata
* @return bool
*/
- public function save_custom_course_request_data(course_request $request, array $teamdata) : bool {
+ public function save_custom_course_request_data(course_request $request, array $teamdata): bool {
global $DB;
if (empty($request) || empty($teamdata)) {
@@ -197,7 +208,7 @@ public function get_user_team_details_by_team_oid(string $teamoid) {
* @param int $courseid
* @return bool
*/
- public function enrol_team_owners_and_members_in_course_by_team_oid_and_course_id(string $teamoid, int $courseid) : bool {
+ public function enrol_team_owners_and_members_in_course_by_team_oid_and_course_id(string $teamoid, int $courseid): bool {
global $DB;
if (empty($teamoid) || empty($courseid)) {
@@ -246,7 +257,7 @@ public function enrol_team_owners_and_members_in_course_by_team_oid_and_course_i
}
if ($moodleuser->suspended || $moodleuser->deleted) {
mtrace('......... Moodle user matching Microsoft account ' . $teamowner['id'] . ' is suspended or deleted.');
- contrinue;
+ continue;
}
if (user_has_role_assignment($userconnectionrecord->moodleid, $ownerroleid, $context->id) &&
in_array($userconnectionrecord->moodleid, $enrolleduserids)) {
@@ -276,7 +287,7 @@ public function enrol_team_owners_and_members_in_course_by_team_oid_and_course_i
}
if ($moodleuser->suspended || $moodleuser->deleted) {
mtrace('......... Moodle user matching Microsoft account ' . $teammember['id'] . ' is suspended or deleted.');
- contrinue;
+ continue;
}
if (user_has_role_assignment($userconnectionrecord->moodleid, $memberroleid, $context->id) &&
in_array($userconnectionrecord->moodleid, $enrolleduserids)) {
@@ -300,7 +311,7 @@ public function enrol_team_owners_and_members_in_course_by_team_oid_and_course_i
*
* @return array
*/
- private function get_team_owners_and_members_by_team_oid(string $teamoid) : array {
+ private function get_team_owners_and_members_by_team_oid(string $teamoid): array {
$teamowners = [];
$teammembers = [];
diff --git a/local/o365/classes/feature/coursesync/main.php b/local/o365/classes/feature/coursesync/main.php
index 596d674a2..58cb77d4f 100644
--- a/local/o365/classes/feature/coursesync/main.php
+++ b/local/o365/classes/feature/coursesync/main.php
@@ -33,8 +33,6 @@
use moodle_exception;
use stdClass;
-defined('MOODLE_INTERNAL') || die();
-
define('API_CALL_RETRY_LIMIT', 5);
/**
@@ -112,14 +110,14 @@ protected function mtrace(string $msg, int $level = 0, string $eol = "\n") {
*
* @return bool
*/
- public function has_education_license() : bool {
+ public function has_education_license(): bool {
return $this->haseducationlicense;
}
/**
* Create teams and populate membership for all courses that don't have an associated team recorded.
*/
- public function sync_courses() : bool {
+ public function sync_courses(): bool {
global $DB;
$this->mtrace('Start syncing courses.');
@@ -254,7 +252,7 @@ private function create_education_group(stdClass $course, int $baselevel = 3) {
* @param int $baselevel
* @return bool
*/
- public function set_lti_properties_in_education_group(string $groupobjectid, stdClass $course, int $baselevel = 3) : bool {
+ public function set_lti_properties_in_education_group(string $groupobjectid, stdClass $course, int $baselevel = 3): bool {
$this->mtrace('Set LMS attributes in group ' . $groupobjectid . ' for course #' . $course->id, $baselevel);
$lmsattributes = [
@@ -346,7 +344,7 @@ private function create_standard_group(stdClass $course, int $baselevel = 3) {
* @return bool whether at least one owner was added.
*/
private function add_group_owners_and_members_to_group(string $groupobjectid, array $owners, array $members,
- int $baselevel = 3) : bool {
+ int $baselevel = 3): bool {
global $SESSION;
if (empty($owners) && empty($members)) {
$this->mtrace('Skip adding owners / members to the group. Reason: No users to add.', $baselevel);
@@ -441,7 +439,7 @@ private function add_group_owners_and_members_to_group(string $groupobjectid, ar
sleep(10);
}
try {
- $this->mtrace('Chunk ' . $key + 1 . ', adding ' . count($users) . ' users as ' . $role, $baselevel + 1);
+ $this->mtrace('Chunk ' . ($key + 1) . ', adding ' . count($users) . ' users as ' . $role, $baselevel + 1);
if (isset($SESSION->o365_groups_not_exist)) {
if (in_array($groupobjectid, $SESSION->o365_groups_not_exist)) {
@@ -498,7 +496,7 @@ private function add_group_owners_and_members_to_group(string $groupobjectid, ar
* @param string $exceptionmessage
* @return bool
*/
- private static function is_resource_not_exist_exception(string $exceptionmessage) : bool {
+ private static function is_resource_not_exist_exception(string $exceptionmessage): bool {
return (strpos($exceptionmessage, \local_o365\utils::RESOURCE_NOT_EXIST_ERROR) !== false);
}
@@ -754,7 +752,7 @@ public function install_moodle_app_in_team(string $groupobjectid, int $courseid,
* @return string
*/
private function add_moodle_tab_to_channel(string $groupobjectid, string $channelid, string $appid,
- int $moodlecourseid) : string {
+ int $moodlecourseid): string {
global $CFG;
$tabconfiguration = [
@@ -837,7 +835,7 @@ private function process_courses_without_groups(int $baselevel = 1) {
* @param int $baselevel
* @return bool True if group creation succeeds, or False if it fails.
*/
- public function create_group_for_course(stdClass $course, int $baselevel = 2) : bool {
+ public function create_group_for_course(stdClass $course, int $baselevel = 2): bool {
global $SESSION;
$this->mtrace('Process course #' . $course->id, $baselevel);
@@ -999,7 +997,7 @@ private function process_courses_without_teams() {
* @param array $objectrecmetadata The metadata of the object database record.
* @return bool
*/
- private function restore_group(int $objectrecid, string $objectid, array $objectrecmetadata) : bool {
+ private function restore_group(int $objectrecid, string $objectid, array $objectrecmetadata): bool {
global $DB;
$deletedgroups = $this->graphclient->list_deleted_groups();
@@ -1028,7 +1026,7 @@ private function restore_group(int $objectrecid, string $objectid, array $object
*
* @return bool
*/
- public function update_teams_cache() : bool {
+ public function update_teams_cache(): bool {
global $DB;
$this->mtrace('Update teams cache...');
@@ -1184,7 +1182,7 @@ public function cleanup_course_connection_records() {
*
* @return bool
*/
- public function update_team_name(int $courseid) : bool {
+ public function update_team_name(int $courseid): bool {
global $DB;
if (!$course = $DB->get_record('course', ['id' => $courseid])) {
@@ -1238,7 +1236,7 @@ public function update_team_name(int $courseid) : bool {
* @return bool
*/
public function process_course_reset(stdClass $course, stdClass $o365object, bool $teamexists = false,
- bool $createafterreset = true) : bool {
+ bool $createafterreset = true): bool {
global $DB;
// Rename existing group.
@@ -1477,7 +1475,7 @@ public function process_course_team_user_sync_from_moodle_to_microsoft(int $cour
* @return array
* @throws moodle_exception
*/
- public function get_group_members(string $groupobjectid) : array {
+ public function get_group_members(string $groupobjectid): array {
$groupmembers = [];
$memberrecords = $this->graphclient->get_group_members($groupobjectid);
@@ -1495,7 +1493,7 @@ public function get_group_members(string $groupobjectid) : array {
* @return array
* @throws moodle_exception
*/
- public function get_group_owners(string $groupobjectid) : array {
+ public function get_group_owners(string $groupobjectid): array {
$groupowners = [];
$ownerresults = $this->graphclient->get_group_owners($groupobjectid);
@@ -1511,7 +1509,7 @@ public function get_group_owners(string $groupobjectid) : array {
*
* @return array An array of group IDs.
*/
- public function get_all_group_ids() : array {
+ public function get_all_group_ids(): array {
$groupids = [];
$groups = $this->graphclient->get_groups();
@@ -1636,6 +1634,7 @@ public function remove_member_from_group(string $groupobjectid, string $userobje
$this->graphclient->get_aad_user_conversation_member_id($groupobjectid, $userobjectid);
} catch (moodle_exception $e) {
// Do nothing.
+ $removed = false;
}
if ($aaduserconversationmemberid) {
try {
@@ -1644,6 +1643,7 @@ public function remove_member_from_group(string $groupobjectid, string $userobje
$removed = true;
} catch (moodle_exception $e) {
// Do nothing.
+ $removed = false;
}
}
}
@@ -1669,6 +1669,7 @@ public function remove_owner_from_group(string $groupobjectid, string $userobjec
$this->graphclient->get_aad_user_conversation_member_id($groupobjectid, $userobjectid);
} catch (moodle_exception $e) {
// Do nothing.
+ $removed = false;
}
if ($aaduserconversationmemberid) {
try {
@@ -1677,6 +1678,7 @@ public function remove_owner_from_group(string $groupobjectid, string $userobjec
$removed = true;
} catch (moodle_exception $e) {
// Do nothing.
+ $removed = false;
}
}
}
@@ -1695,7 +1697,7 @@ public function remove_owner_from_group(string $groupobjectid, string $userobjec
* @return bool
*/
public function process_course_team_user_sync_from_microsoft_to_moodle(int $courseid, string $groupobjectid = '',
- array $connectedusers = null) : bool {
+ ?array $connectedusers = null): bool {
global $DB;
$coursecontext = context_course::instance($courseid, IGNORE_MISSING);
@@ -1785,8 +1787,8 @@ public function process_course_team_user_sync_from_microsoft_to_moodle(int $cour
array_keys($moodletomicrosoftusermappings));
// Sync teachers.
- // - $connectedcurrentcourseteachers contains the current teachers in the course.
- // - $connectedintendedcourseteachers contains the teachers that should be in the course.
+ // - $connectedcurrentcourseteachers contains the current teachers in the course.
+ // - $connectedintendedcourseteachers contains the teachers that should be in the course.
$teacherstoenrol = array_diff($connectedintendedcourseteachers, $connectedcurrentcourseteachers);
if ($teacherstoenrol) {
$this->mtrace('Add teacher role to ' . count($teacherstoenrol) . ' users...', 2);
@@ -1809,8 +1811,8 @@ public function process_course_team_user_sync_from_microsoft_to_moodle(int $cour
}
// Sync students.
- // - $connectedcurrentcoursestudents contains the current students in the course.
- // - $connectedintendedcoursestudents contains the students that should be in the course.
+ // - $connectedcurrentcoursestudents contains the current students in the course.
+ // - $connectedintendedcoursestudents contains the students that should be in the course.
$studentstoenrol = array_diff($connectedintendedcoursestudents, $connectedcurrentcoursestudents);
if ($studentstoenrol) {
$this->mtrace('Add student role to ' . count($studentstoenrol) . ' users...', 2);
@@ -1842,7 +1844,7 @@ public function process_course_team_user_sync_from_microsoft_to_moodle(int $cour
* @param int $roleid The ID of the role.
* @param context_course $context The context of the course.
*/
- private function assign_role_by_user_id_role_id_and_course_context(int $userid, int $roleid, context_course $context) : void {
+ private function assign_role_by_user_id_role_id_and_course_context(int $userid, int $roleid, context_course $context): void {
enrol_try_internal_enrol($context->instanceid, $userid, $roleid);
$this->mtrace('Assigned role #' . $roleid . ' to user #' . $userid . '.', 3);
}
@@ -1857,7 +1859,7 @@ private function assign_role_by_user_id_role_id_and_course_context(int $userid,
* @param bool $hasotherrole Whether the user has other role.
*/
private function unassign_role_by_user_id_role_id_and_course_context(int $userid, int $roleid, context_course $context,
- bool $hasotherrole) : void {
+ bool $hasotherrole): void {
role_unassign($roleid, $userid, $context->id);
$this->mtrace('Removed role #' . $roleid . ' from user #' . $userid . '.', 3);
@@ -1875,7 +1877,7 @@ private function unassign_role_by_user_id_role_id_and_course_context(int $userid
* @param int $courseid The ID of the course.
* @return bool
*/
- private function unenrol_user_by_user_id_and_course_id(int $userid, int $courseid) : bool {
+ private function unenrol_user_by_user_id_and_course_id(int $userid, int $courseid): bool {
global $DB;
$sql = "SELECT *
@@ -1919,7 +1921,7 @@ private function unenrol_user_by_user_id_and_course_id(int $userid, int $coursei
* @param int $courseid The ID of the course.
* @param string $groupobjectid The object ID of the Microsoft 365 group.
*/
- public function process_initial_course_team_user_sync(int $courseid, string $groupobjectid) : void {
+ public function process_initial_course_team_user_sync(int $courseid, string $groupobjectid): void {
$coursecontext = context_course::instance($courseid);
$this->mtrace('Perform initial Moodle course and Microsoft Teams user sync between course #' . $courseid .
@@ -1980,8 +1982,8 @@ public function process_initial_course_team_user_sync(int $courseid, string $gro
}
// Sync teachers from Microsoft Teams to Moodle course.
- // - $connectedcurrentcourseteachers contains the current teachers in the course.
- // - $connectedintendedcourseteachers contains the teachers that should be in the course.
+ // - $connectedcurrentcourseteachers contains the current teachers in the course.
+ // - $connectedintendedcourseteachers contains the teachers that should be in the course.
$teacherstoenrol = array_diff($connectedintendedcourseteachers, $connectedcurrentcourseteachers);
if ($teacherstoenrol) {
$this->mtrace('Add teacher role to ' . count($teacherstoenrol) . ' users...', 2);
@@ -1993,8 +1995,8 @@ public function process_initial_course_team_user_sync(int $courseid, string $gro
}
// Sync students from Microsoft Teams to Moodle course.
- // - $connectedcurrentcoursestudents contains the current students in the course.
- // - $connectedintendedcoursestudents contains the students that should be in the course.
+ // - $connectedcurrentcoursestudents contains the current students in the course.
+ // - $connectedintendedcoursestudents contains the students that should be in the course.
$studentstoenrol = array_diff($connectedintendedcoursestudents, $connectedcurrentcoursestudents);
if ($studentstoenrol) {
$this->mtrace('Add student role to ' . count($studentstoenrol) . ' users...', 2);
@@ -2025,7 +2027,7 @@ public function process_initial_course_team_user_sync(int $courseid, string $gro
*
* @return void
*/
- public function save_not_found_groups() : void {
+ public function save_not_found_groups(): void {
global $DB, $SESSION;
$this->mtrace('Save non-existing groups to groups cache...');
diff --git a/local/o365/classes/feature/coursesync/observers.php b/local/o365/classes/feature/coursesync/observers.php
index 3f2b110a8..ba2d38568 100644
--- a/local/o365/classes/feature/coursesync/observers.php
+++ b/local/o365/classes/feature/coursesync/observers.php
@@ -46,7 +46,7 @@ class observers {
* @param course_reset_started $event
* @return bool
*/
- public static function handle_course_reset_started(course_reset_started $event) : bool {
+ public static function handle_course_reset_started(course_reset_started $event): bool {
global $CFG, $DB;
if (!\local_o365\utils::is_connected()) {
@@ -88,6 +88,7 @@ public static function handle_course_reset_started(course_reset_started $event)
}
} catch (moodle_exception $e) {
// Do nothing.
+ $connectedtoteam = false;
}
}
} else {
diff --git a/local/o365/classes/feature/coursesync/utils.php b/local/o365/classes/feature/coursesync/utils.php
index 1478ae10e..59d58a157 100644
--- a/local/o365/classes/feature/coursesync/utils.php
+++ b/local/o365/classes/feature/coursesync/utils.php
@@ -46,7 +46,7 @@ class utils {
*
* @return bool True if group creation is enabled. False otherwise.
*/
- public static function is_enabled() : bool {
+ public static function is_enabled(): bool {
$coursesyncsetting = get_config('local_o365', 'coursesync');
return $coursesyncsetting === 'oncustom' || $coursesyncsetting === 'onall';
}
@@ -103,7 +103,7 @@ public static function get_enabled_courses(bool $returnallids = false) {
* @param int $courseid The Moodle course ID to check.
* @return bool Whether the course is enabled for sync.
*/
- public static function is_course_sync_enabled(int $courseid) : bool {
+ public static function is_course_sync_enabled(int $courseid): bool {
$coursesyncsetting = get_config('local_o365', 'coursesync');
if ($coursesyncsetting === 'onall') {
return true;
@@ -170,7 +170,7 @@ public static function get_o365_object(int $courseid) {
* @param int $courseid
* @return string[]|null
*/
- public static function get_course_microsoft_365_urls(int $courseid) : ?array {
+ public static function get_course_microsoft_365_urls(int $courseid): ?array {
$object = static::get_o365_object($courseid);
if (empty($object->objectid)) {
return null;
@@ -267,7 +267,7 @@ public static function set_course_sync_enabled(int $courseid, bool $enabled = tr
* @param string $currentoid
* @return array
*/
- public static function get_matching_team_options(string $currentoid = '') : array {
+ public static function get_matching_team_options(string $currentoid = ''): array {
global $DB;
$teamsoptions = [];
@@ -316,11 +316,11 @@ public static function get_matching_team_options(string $currentoid = '') : arra
*
* @param stdClass $course
* @param string $forcedprefix
- * @param stdClass $group
+ * @param stdClass|null $group
*
* @return string
*/
- public static function get_team_display_name(stdClass $course, string $forcedprefix = '', stdClass $group = null) {
+ public static function get_team_display_name(stdClass $course, string $forcedprefix = '', ?stdClass $group = null) {
if ($forcedprefix) {
$teamdisplayname = $forcedprefix;
} else {
@@ -367,7 +367,7 @@ public static function get_team_display_name(stdClass $course, string $forcedpre
*
* @return array
*/
- public static function get_sample_team_group_names() : array {
+ public static function get_sample_team_group_names(): array {
$teamgroupamesamplecourse = static::get_team_group_name_sample_course();
return [static::get_team_display_name($teamgroupamesamplecourse), static::get_group_mail_alias($teamgroupamesamplecourse)];
@@ -380,7 +380,7 @@ public static function get_sample_team_group_names() : array {
*
* @return string
*/
- public static function get_group_mail_alias(stdClass $course) : string {
+ public static function get_group_mail_alias(stdClass $course): string {
$groupmailaliasprefix = get_config('local_o365', 'group_mail_alias_prefix');
if ($groupmailaliasprefix) {
$groupmailaliasprefix = static::clean_up_group_mail_alias($groupmailaliasprefix);
@@ -428,7 +428,7 @@ public static function get_group_mail_alias(stdClass $course) : string {
public static function clean_up_group_mail_alias(string $mailalias) {
$notallowedbasicchars = ['@', '(', ')', "\\", '[', ']', '"', ';', ':', '.', '<', '>', ' '];
$chars = preg_split( '//u', $mailalias, -1, PREG_SPLIT_NO_EMPTY);
- foreach($chars as $key => $char){
+ foreach ($chars as $key => $char) {
$charorder = ord($char);
if ($charorder < 0 || $charorder > 127 || in_array($char, $notallowedbasicchars)) {
unset($chars[$key]);
@@ -443,7 +443,7 @@ public static function clean_up_group_mail_alias(string $mailalias) {
*
* @return stdClass
*/
- public static function get_team_group_name_sample_course() : stdClass {
+ public static function get_team_group_name_sample_course(): stdClass {
$samplecourse = new stdClass();
$samplecourse->fullname = 'Sample course 15';
$samplecourse->shortname = 'sample 15';
@@ -459,7 +459,7 @@ public static function get_team_group_name_sample_course() : stdClass {
* @param array $userids
* @return array
*/
- public static function get_user_object_ids_by_user_ids(array $userids) : array {
+ public static function get_user_object_ids_by_user_ids(array $userids): array {
global $DB;
if ($userids) {
@@ -540,7 +540,7 @@ public static function get_user_object_record_id_by_user_id(int $userid) {
* @param int $courseid
* @return array
*/
- public static function get_team_owner_object_ids_by_course_id(int $courseid) : array {
+ public static function get_team_owner_object_ids_by_course_id(int $courseid): array {
$teamownerobjectids = [];
$teamowneruserids = static::get_team_owner_user_ids_by_course_id($courseid);
if ($teamowneruserids) {
@@ -556,7 +556,7 @@ public static function get_team_owner_object_ids_by_course_id(int $courseid) : a
* @param int $courseid ID of Moodle course
* @return array array containing IDs of teachers.
*/
- public static function get_team_owner_user_ids_by_course_id(int $courseid) : array {
+ public static function get_team_owner_user_ids_by_course_id(int $courseid): array {
$context = context_course::instance($courseid);
$teamownerusers = get_enrolled_users($context, 'local/o365:teamowner', 0, 'u.*', null, 0, 0, true);
$teamowneruserids = [];
@@ -576,7 +576,7 @@ public static function get_team_owner_user_ids_by_course_id(int $courseid) : arr
* @param array $teamownerobjectids
* @return array
*/
- public static function get_team_member_object_ids_by_course_id(int $courseid, array $teamownerobjectids = []) : array {
+ public static function get_team_member_object_ids_by_course_id(int $courseid, array $teamownerobjectids = []): array {
$teammemberobjectids = [];
$teammemberuserids = static::get_team_member_user_ids_by_course_id($courseid);
if ($teammemberuserids) {
@@ -594,7 +594,7 @@ public static function get_team_member_object_ids_by_course_id(int $courseid, ar
* @param int $courseid ID of the Moodle course
* @return array
*/
- public static function get_team_member_user_ids_by_course_id(int $courseid) : array {
+ public static function get_team_member_user_ids_by_course_id(int $courseid): array {
$context = context_course::instance($courseid);
$teammemberusers = get_enrolled_users($context, 'local/o365:teammember', 0, 'u.*', null, 0, 0, true);
$teammemberuserids = [];
@@ -614,7 +614,7 @@ public static function get_team_member_user_ids_by_course_id(int $courseid) : ar
* @param array $members
* @return array
*/
- public static function arrange_group_users_in_chunks(array $owners, array $members) : array {
+ public static function arrange_group_users_in_chunks(array $owners, array $members): array {
$userchunks = [];
$ownerchunks = array_chunk($owners, 20);
@@ -686,6 +686,7 @@ public static function migrate_existing_groups() {
}
} catch (moodle_exception $e) {
// Cannot get graph client, nothing to do.
+ return;
}
}
@@ -698,7 +699,7 @@ public static function migrate_existing_groups() {
* @param int $excluderoleid
* @return string
*/
- public static function get_user_group_role_by_moodle_ids(int $userid, int $courseid, int $excluderoleid = 0) : string {
+ public static function get_user_group_role_by_moodle_ids(int $userid, int $courseid, int $excluderoleid = 0): string {
$grouprole = '';
$coursecontext = context_course::instance($courseid);
@@ -737,7 +738,7 @@ public static function get_user_group_role_by_moodle_ids(int $userid, int $cours
* @return bool
*/
public static function sync_user_role_in_course_group(int $userid, int $courseid, int $userobjectrecordid = 0,
- int $coursegroupobjectrecordid = 0, bool $sdscoursechecked = false, int $excluderoleid = 0) : bool {
+ int $coursegroupobjectrecordid = 0, bool $sdscoursechecked = false, int $excluderoleid = 0): bool {
global $DB;
if (empty($userid) || empty($courseid)) {
@@ -777,8 +778,8 @@ public static function sync_user_role_in_course_group(int $userid, int $courseid
$grouprole = static::get_user_group_role_by_moodle_ids($userid, $courseid, $excluderoleid);
// Get group and user object IDs.
- $groupobjectid = utils::get_object_id_by_record_id($coursegroupobjectrecordid);
- $userobjectid = utils::get_object_id_by_record_id($userobjectrecordid);
+ $groupobjectid = static::get_object_id_by_record_id($coursegroupobjectrecordid);
+ $userobjectid = static::get_object_id_by_record_id($userobjectrecordid);
// If the user doesn't have any group role, remove the user from the connected group.
if (!$grouprole) {
@@ -835,7 +836,7 @@ public static function sync_user_role_in_course_group(int $userid, int $courseid
* @param string $groupobjectid
* @return bool
*/
- public static function is_team_created_from_group(string $groupobjectid) : bool {
+ public static function is_team_created_from_group(string $groupobjectid): bool {
global $DB;
return $DB->record_exists('local_o365_objects',
diff --git a/local/o365/classes/feature/sds/task/sync.php b/local/o365/classes/feature/sds/task/sync.php
index bc37ef7dc..d90d4bfb5 100644
--- a/local/o365/classes/feature/sds/task/sync.php
+++ b/local/o365/classes/feature/sds/task/sync.php
@@ -33,8 +33,6 @@
use local_o365\utils;
use moodle_exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Scheduled task to run SDS sync.
*/
@@ -44,7 +42,7 @@ class sync extends scheduled_task {
*
* @return string
*/
- public function get_name() : string {
+ public function get_name(): string {
return get_string('task_sds_sync', 'local_o365');
}
@@ -54,7 +52,7 @@ public function get_name() : string {
* @param unified $apiclient The unified API client.
* @return bool
*/
- public static function runsync(unified $apiclient) : bool {
+ public static function runsync(unified $apiclient): bool {
global $DB, $CFG;
require_once($CFG->dirroot . '/user/lib.php');
@@ -438,7 +436,7 @@ public static function mtrace(string $str, int $level = 0) {
* @return object The course object.
*/
public static function get_or_create_class_course(string $classobjectid, string $shortname, string $fullname,
- int $categoryid = 0) : object {
+ int $categoryid = 0): object {
global $DB, $CFG;
require_once($CFG->dirroot . '/course/lib.php');
@@ -458,12 +456,12 @@ public static function get_or_create_class_course(string $classobjectid, string
}
// Create new course category and object record.
- $data = ['category' => $categoryid, 'shortname' => $shortname, 'fullname' => $fullname, 'idnumber' => $classobjectid,];
+ $data = ['category' => $categoryid, 'shortname' => $shortname, 'fullname' => $fullname, 'idnumber' => $classobjectid];
$course = create_course((object) $data);
$now = time();
$objectrec = ['type' => 'sdssection', 'subtype' => 'course', 'objectid' => $classobjectid, 'moodleid' => $course->id,
- 'o365name' => $shortname, 'tenant' => '', 'timecreated' => $now, 'timemodified' => $now,];
+ 'o365name' => $shortname, 'tenant' => '', 'timecreated' => $now, 'timemodified' => $now];
$DB->insert_record('local_o365_objects', $objectrec);
return $course;
@@ -476,7 +474,7 @@ public static function get_or_create_class_course(string $classobjectid, string
* @param string $schoolname The name of the school.
* @return core_course_category A course category object for the retrieved or created course category.
*/
- public static function get_or_create_school_coursecategory(string $schoolobjectid, string $schoolname) : core_course_category {
+ public static function get_or_create_school_coursecategory(string $schoolobjectid, string $schoolname): core_course_category {
global $DB;
// Look for existing category.
@@ -494,7 +492,7 @@ public static function get_or_create_school_coursecategory(string $schoolobjecti
}
// Create new course category and object record.
- $data = ['visible' => 1, 'name' => $schoolname, 'idnumber' => $schoolobjectid,];
+ $data = ['visible' => 1, 'name' => $schoolname, 'idnumber' => $schoolobjectid];
if (strlen($data['name']) > 255) {
static::mtrace('School name was over 255 chars when creating course category, truncating to 255.');
$data['name'] = substr($data['name'], 0, 255);
@@ -504,7 +502,7 @@ public static function get_or_create_school_coursecategory(string $schoolobjecti
$now = time();
$objectrec = ['type' => 'sdsschool', 'subtype' => 'coursecat', 'objectid' => $schoolobjectid, 'moodleid' => $coursecat->id,
- 'o365name' => $schoolname, 'tenant' => '', 'timecreated' => $now, 'timemodified' => $now,];
+ 'o365name' => $schoolname, 'tenant' => '', 'timecreated' => $now, 'timemodified' => $now];
$DB->insert_record('local_o365_objects', $objectrec);
return $coursecat;
@@ -515,7 +513,7 @@ public static function get_or_create_school_coursecategory(string $schoolobjecti
*
* @return bool
*/
- public function execute() : bool {
+ public function execute(): bool {
if (utils::is_connected() !== true) {
static::mtrace('local_o365 reported unconfigured during SDS sync task, so exiting.');
return false;
@@ -573,6 +571,7 @@ public static function clean_up_sds_sync_records() {
$sectionsinenabledschools = array_merge($sectionsinenabledschools, $schoolclasses);
} catch (moodle_exception $e) {
// Do nothing.
+ static::mtrace('Error getting school classes. Details: ' . $e->getMessage(), 2);
}
}
foreach ($sectionsinenabledschools as $sectionsinenabledschool) {
diff --git a/local/o365/classes/feature/sds/utils.php b/local/o365/classes/feature/sds/utils.php
index 9a4bfd22a..da20c9472 100644
--- a/local/o365/classes/feature/sds/utils.php
+++ b/local/o365/classes/feature/sds/utils.php
@@ -43,7 +43,7 @@ class utils {
*
* @return unified|null The SDS API client.
*/
- public static function get_apiclient() : ?unified {
+ public static function get_apiclient(): ?unified {
$httpclient = new httpclient();
try {
$clientdata = clientdata::instance_from_oidc();
@@ -69,7 +69,7 @@ public static function get_apiclient() : ?unified {
* @param unified|null $apiclient
* @return array
*/
- public static function get_profile_sync_status_with_id_name(unified $apiclient = null) : array {
+ public static function get_profile_sync_status_with_id_name(?unified $apiclient = null): array {
$profilesyncenabled = false;
$schoolid = '';
$schoolname = '';
@@ -112,7 +112,7 @@ public static function get_profile_sync_status_with_id_name(unified $apiclient =
*
* @return array[]
*/
- public static function get_sds_profile_sync_api_requirements() : array {
+ public static function get_sds_profile_sync_api_requirements(): array {
$idandnamemappings = [];
$additionalprofilemappings = [];
diff --git a/local/o365/classes/feature/userconnections/filtering.php b/local/o365/classes/feature/userconnections/filtering.php
index 8c2f31cc0..c5af3ae5b 100644
--- a/local/o365/classes/feature/userconnections/filtering.php
+++ b/local/o365/classes/feature/userconnections/filtering.php
@@ -80,13 +80,13 @@ public function get_field($fieldname, $advanced) {
* Returns sql where statement based on active user filters.
*
* @param string $extra sql
- * @param array $params named params (recommended prefix ex)
+ * @param array|null $params named params (recommended prefix ex)
* @return array sql string and $params
*/
- public function get_sql_filter($extra='', array $params=null) {
+ public function get_sql_filter($extra='', ?array $params=null) {
global $SESSION;
- $sqls = array();
+ $sqls = [];
if ($extra != '') {
$sqls[] = $extra;
}
@@ -102,7 +102,7 @@ public function get_sql_filter($extra='', array $params=null) {
}
$field = $this->_fields[$fname];
foreach ($datas as $i => $data) {
- list($s, $p) = $field->get_sql_filter($data);
+ [$s, $p] = $field->get_sql_filter($data);
$sqls[] = $s;
$params = $params + $p;
}
@@ -131,7 +131,7 @@ public function get_filter_o365username() {
$datas = $SESSION->user_filtering[$fname];
$field = $this->_fields[$fname];
foreach ($datas as $i => $data) {
- list($s, $p) = $field->get_sql_filter($data);
+ [$s, $p] = $field->get_sql_filter($data);
$sqls[] = $s;
$params = $params + $p;
}
diff --git a/local/o365/classes/feature/usersync/main.php b/local/o365/classes/feature/usersync/main.php
index 3abe97929..5a0826569 100644
--- a/local/o365/classes/feature/usersync/main.php
+++ b/local/o365/classes/feature/usersync/main.php
@@ -68,7 +68,7 @@ class main {
*
* @throws moodle_exception
*/
- public function __construct(clientdata $clientdata = null, httpclient $httpclient = null) {
+ public function __construct(?clientdata $clientdata = null, ?httpclient $httpclient = null) {
if (!PHPUNIT_TEST && !defined('BEHAT_SITE_RUNNING')) {
$this->clientdata = (!empty($clientdata))
? $clientdata
@@ -190,7 +190,7 @@ public function assign_photo(int $muserid) {
// User has no photo. Deleting previous profile photo.
$fs = \get_file_storage();
$fs->delete_area_files($context->id, 'user', 'icon');
- $DB->set_field('user', 'picture', 0, array('id' => $muser->id));
+ $DB->set_field('user', 'picture', 0, ['id' => $muser->id]);
}
$result = false;
} else {
@@ -234,7 +234,7 @@ public function assign_photo(int $muserid) {
// User has no photo. Deleting previous profile photo.
$fs = \get_file_storage();
$fs->delete_area_files($context->id, 'user', 'icon');
- $DB->set_field('user', 'picture', 0, array('id' => $muser->id));
+ $DB->set_field('user', 'picture', 0, ['id' => $muser->id]);
}
}
}
@@ -563,7 +563,8 @@ public static function apply_configured_fieldmap(array $entraiduserdata, stdClas
if (isset($countrymap[$incoming])) {
$countrycode = $incoming;
} else {
- $countrycode = array_search($entraiduserdata[$remotefield], get_string_manager()->get_list_of_countries());
+ $countrycode = array_search($entraiduserdata[$remotefield],
+ get_string_manager()->get_list_of_countries());
}
$user->$localfield = (!empty($countrycode)) ? $countrycode : '';
break;
@@ -803,7 +804,7 @@ protected function check_usercreationrestriction($entraiduserdata) {
return false;
} else {
- utils:debug('Invalid extension attribute ID', __METHOD__);
+ utils::debug('Invalid extension attribute ID', __METHOD__);
return false;
}
} else {
@@ -1012,7 +1013,7 @@ public static function sync_option_enabled($option) {
* @param string $bindingusernameclaim
* @return bool Success/Failure
*/
- public function sync_users(array $entraidusers = array(), string $bindingusernameclaim = 'userPrincipalName') {
+ public function sync_users(array $entraidusers = [], string $bindingusernameclaim = 'userPrincipalName') {
global $DB, $CFG;
$usersyncsettings = $this->get_sync_options();
@@ -1158,7 +1159,8 @@ public function sync_users(array $entraidusers = array(), string $bindingusernam
LEFT JOIN {local_o365_connections} conn ON conn.muserid = u.id
LEFT JOIN {local_o365_appassign} assign ON assign.muserid = u.id
LEFT JOIN {local_o365_objects} obj ON obj.type = ? AND obj.moodleid = u.id
- WHERE tok.oidcusername '.$useridentifiersql.' AND u.username '.$usernamesql.' AND u.mnethostid = ? AND u.deleted = ? ';
+ WHERE tok.oidcusername ' . $useridentifiersql . ' AND u.username ' . $usernamesql . ' AND u.mnethostid = ?
+ AND u.deleted = ? ';
$params = array_merge(['user'], $useridentifierparams, $usernameparams, [$CFG->mnet_localhost_id, '0']);
$linkedexistingusers = $DB->get_records_sql($sql, $params);
@@ -1258,7 +1260,8 @@ public function sync_users(array $entraidusers = array(), string $bindingusernam
$existinguserrecord->suspended = $renamedmoodleuser->suspended;
$existinguserrecord->auth = $renamedmoodleuser->auth;
- $connected = $this->sync_existing_user($usersyncsettings, $entraiduser, $existinguserrecord, $exactmatch);
+ $connected = $this->sync_existing_user($usersyncsettings, $entraiduser, $existinguserrecord,
+ $exactmatch);
$existinguser = $renamedmoodleuser;
}
} else {
@@ -1281,7 +1284,8 @@ public function sync_users(array $entraidusers = array(), string $bindingusernam
if (isset($entraiduser['id']) && $entraiduser['id'] &&
$existingusermatching = $DB->get_record('local_o365_objects',
['type' => 'user', 'objectid' => $entraiduser['id']])) {
- $possibleo365names = [$entraiduser['useridentifierlower'], $entraiduser['convertedidentifier'], $entraiduser['useridentifier']];
+ $possibleo365names = [$entraiduser['useridentifierlower'], $entraiduser['convertedidentifier'],
+ $entraiduser['useridentifier']];
if (isset($entraiduser['upnsplit0'])) {
$possibleo365names[] = $entraiduser['upnsplit0'];
}
@@ -1321,7 +1325,8 @@ public function sync_users(array $entraidusers = array(), string $bindingusernam
$DB->update_record('local_o365_objects', $existingusermatching);
// Update token record.
- if ($existingtoken = $DB->get_record('auth_oidc_token', ['userid' => $renamedmoodleuser->id])) {
+ if ($existingtoken = $DB->get_record('auth_oidc_token',
+ ['userid' => $renamedmoodleuser->id])) {
$existingtoken->useridentifier = $entraiduser['useridentifier'];
$existingtoken->username = $username;
$DB->update_record('auth_oidc_token', $existingtoken);
@@ -1607,7 +1612,8 @@ protected function sync_existing_user($syncoptions, $entraiduserdata, $existingu
// Match user if needed.
if ($existinguser->auth !== 'oidc') {
$this->mtrace('Found a user in Microsoft Entra ID that seems to match a user in Moodle');
- $this->mtrace(sprintf('moodle username: %s, Entra ID user identifier: %s', $existinguser->username, $entraiduserdata['useridentifierlower']));
+ $this->mtrace(sprintf('moodle username: %s, Entra ID user identifier: %s', $existinguser->username,
+ $entraiduserdata['useridentifierlower']));
return $this->sync_users_matchuser($syncoptions, $entraiduserdata, $existinguser, $exactmatch);
} else {
$this->mtrace('The user is already using OIDC for authentication.');
diff --git a/local/o365/classes/form/cohortsync.php b/local/o365/classes/form/cohortsync.php
index feb0d7c61..47be34d53 100644
--- a/local/o365/classes/form/cohortsync.php
+++ b/local/o365/classes/form/cohortsync.php
@@ -43,7 +43,7 @@ class cohortsync extends moodleform {
/**
* Define the form elements.
*/
- public function definition() : void {
+ public function definition(): void {
$mform = $this->_form;
$cohortsyncmain = $this->_customdata['cohortsyncmain'];
diff --git a/local/o365/classes/form/courserequestform.php b/local/o365/classes/form/courserequestform.php
index 2e3767f89..6a823e8b6 100644
--- a/local/o365/classes/form/courserequestform.php
+++ b/local/o365/classes/form/courserequestform.php
@@ -44,7 +44,7 @@ class courserequestform extends course_request_form {
*
* @return void
*/
- function definition() {
+ public function definition() {
global $CFG, $DB, $USER;
$mform =& $this->_form;
@@ -108,7 +108,7 @@ function definition() {
$select = $mform->addElement('select', 'team', get_string('courserequest_teams', 'local_o365'), []);
$mform->addHelpButton('team', 'courserequest_teams', 'local_o365');
- // Populate the select element based on the availability of unmatched teams
+ // Populate the select element based on the availability of unmatched teams.
if (!empty($unmatchedteams)) {
foreach ($unmatchedteams as $unmatchedteam) {
$select->addOption($unmatchedteam['displayName'], $unmatchedteam['id']);
@@ -118,7 +118,7 @@ function definition() {
$mform->disabledIf('team', '', 'eq', '');
}
- // Add client-side validation
+ // Add client-side validation.
$mform->addRule('team', get_string('courserequest_emptyteams', 'local_o365'), 'required', null, 'client');
}
}
@@ -144,11 +144,11 @@ function definition() {
/**
* Custom validation function.
*
- * @param $data
- * @param $files
+ * @param array $data
+ * @param array $files
* @return array
*/
- public function validation($data, $files) : array {
+ public function validation($data, $files): array {
global $DB;
$errors = parent::validation($data, $files);
diff --git a/local/o365/classes/form/teamstabconfiguration.php b/local/o365/classes/form/teamstabconfiguration.php
index edf876021..0083f5b6b 100644
--- a/local/o365/classes/form/teamstabconfiguration.php
+++ b/local/o365/classes/form/teamstabconfiguration.php
@@ -52,7 +52,7 @@ public function definition() {
if ($courseoptions) {
// User can access at least one course, show tab name field and course selector.
$mform->addElement('text', 'local_o365_teams_tab_name', get_string('tab_name', 'local_o365'),
- array('onchange' => 'onTabNameChange()'));
+ ['onchange' => 'onTabNameChange()']);
$mform->setType('local_o365_teams_tab_name', PARAM_TEXT);
$tabname = get_config('local_o365', 'teams_moodle_tab_name');
if (!$tabname) {
@@ -62,7 +62,7 @@ public function definition() {
$courseselector = $mform->createElement('select', 'local_o365_teams_course',
get_string('course_selector_label', 'local_o365'),
- $courseoptions, array('onchange' => 'onCourseChange()'));
+ $courseoptions, ['onchange' => 'onCourseChange()']);
$courseselector->setSize(100);
$courseselector->setMultiple(true);
@@ -84,7 +84,7 @@ public function definition() {
private function get_course_options() {
global $DB, $USER;
- $courseoptions = array();
+ $courseoptions = [];
if (is_siteadmin($USER->id)) {
$courses = $DB->get_records('course', ['visible' => 1]);
diff --git a/local/o365/classes/healthcheck/healthcheckinterface.php b/local/o365/classes/healthcheck/healthcheckinterface.php
index d23e8d028..67696189c 100644
--- a/local/o365/classes/healthcheck/healthcheckinterface.php
+++ b/local/o365/classes/healthcheck/healthcheckinterface.php
@@ -25,15 +25,25 @@
namespace local_o365\healthcheck;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Interface for all health checks.
*/
interface healthcheckinterface {
+ /**
+ * @var int SEVERITY_OK
+ */
const SEVERITY_OK = 0;
+ /**
+ * @var int SEVERITY_TRIVIAL
+ */
const SEVERITY_TRIVIAL = 1;
+ /**
+ * @var int SEVERITY_WARNING
+ */
const SEVERITY_WARNING = 2;
+ /**
+ * @var int SEVERITY_FATAL
+ */
const SEVERITY_FATAL = 3;
/**
diff --git a/local/o365/classes/healthcheck/ratelimit.php b/local/o365/classes/healthcheck/ratelimit.php
index d56cf56e7..df8ba941c 100644
--- a/local/o365/classes/healthcheck/ratelimit.php
+++ b/local/o365/classes/healthcheck/ratelimit.php
@@ -25,8 +25,6 @@
namespace local_o365\healthcheck;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Checks current recorded rate limit
*/
diff --git a/local/o365/classes/httpclient.php b/local/o365/classes/httpclient.php
index e67ab1535..4780cd53c 100644
--- a/local/o365/classes/httpclient.php
+++ b/local/o365/classes/httpclient.php
@@ -26,24 +26,26 @@
namespace local_o365;
+use curl;
use moodle_exception;
+use stdClass;
defined('MOODLE_INTERNAL') || die();
global $CFG;
-require_once($CFG->dirroot.'/lib/filelib.php');
+require_once($CFG->dirroot . '/lib/filelib.php');
/**
* An httpclientinterface implementation, using curl class as backend and adding patch and merge methods.
*/
-class httpclient extends \curl implements \local_o365\httpclientinterface {
+class httpclient extends curl implements httpclientinterface {
/**
- * Generate a client tag.
+ * Generate client tag headers.
*
- * @return string A client tag.
+ * @return string[]
*/
- protected function get_clienttag_headers() {
+ protected function get_clienttag_headers(): array {
global $CFG;
$iid = sha1($CFG->wwwroot);
@@ -55,9 +57,10 @@ protected function get_clienttag_headers() {
$params = "lang=PHP; os={$ostype}; os_version={$osver}; arch={$arch}; version={$ver}; MoodleInstallId={$iid}";
$clienttag = "Moodle/{$mdlver} ({$params})";
+
return [
- 'User-Agent: '.$clienttag,
- 'X-ClientService-ClientTag: '.$clienttag,
+ 'User-Agent: ' . $clienttag,
+ 'X-ClientService-ClientTag: ' . $clienttag,
];
}
@@ -66,10 +69,12 @@ protected function get_clienttag_headers() {
*
* @return string The current plugin version.
*/
- protected function get_plugin_version() {
+ protected function get_plugin_version(): string {
global $CFG;
- $plugin = new \stdClass;
- require_once($CFG->dirroot.'/local/o365/version.php');
+
+ $plugin = new stdClass;
+ require_once($CFG->dirroot . '/local/o365/version.php');
+
return $plugin->release;
}
@@ -78,8 +83,9 @@ protected function get_plugin_version() {
*
* @return string The current Moodle version.
*/
- protected function get_moodle_version() {
+ protected function get_moodle_version(): string {
global $CFG;
+
return $CFG->release;
}
@@ -91,11 +97,11 @@ protected function get_moodle_version() {
* @param array $options
* @return bool
*/
- public function patch($url, $params = '', $options = array()) {
+ public function patch($url, $params = '', $options = []): bool {
$options['CURLOPT_CUSTOMREQUEST'] = 'PATCH';
if (is_array($params)) {
- $this->_tmp_file_post_params = array();
+ $this->_tmp_file_post_params = [];
foreach ($params as $key => $value) {
if ($value instanceof stored_file) {
$value->add_to_curl_request($this, $key);
@@ -109,6 +115,7 @@ public function patch($url, $params = '', $options = array()) {
// Var $params is the raw post data.
$options['CURLOPT_POSTFIELDS'] = $params;
}
+
return $this->request($url, $options);
}
@@ -120,11 +127,11 @@ public function patch($url, $params = '', $options = array()) {
* @param array $options
* @return bool
*/
- public function merge($url, $params = '', $options = array()) {
+ public function merge($url, $params = '', $options = []): bool {
$options['CURLOPT_CUSTOMREQUEST'] = 'MERGE';
if (is_array($params)) {
- $this->_tmp_file_post_params = array();
+ $this->_tmp_file_post_params = [];
foreach ($params as $key => $value) {
if ($value instanceof stored_file) {
$value->add_to_curl_request($this, $key);
@@ -138,6 +145,7 @@ public function merge($url, $params = '', $options = array()) {
// Var $params is the raw post data.
$options['CURLOPT_POSTFIELDS'] = $params;
}
+
return $this->request($url, $options);
}
@@ -149,7 +157,7 @@ public function merge($url, $params = '', $options = array()) {
* @param array $options
* @return bool
*/
- public function put($url, $params = array(), $options = array()) {
+ public function put($url, $params = [], $options = []): bool {
if (!isset($params['file'])) {
throw new moodle_exception('errorhttpclientnofileinput', 'local_o365');
}
@@ -168,12 +176,10 @@ public function put($url, $params = array(), $options = array()) {
$options['CURLOPT_PUT'] = 1;
$options['CURLOPT_INFILESIZE'] = $size;
$options['CURLOPT_INFILE'] = $fp;
- if (!isset($this->options['CURLOPT_USERPWD'])) {
- $this->setopt(array('CURLOPT_USERPWD' => 'anonymous: noreply@moodle.org'));
- }
$ret = $this->request($url, $options);
fclose($fp);
+
return $ret;
}
@@ -184,8 +190,9 @@ public function put($url, $params = array(), $options = array()) {
* @param array $options
* @return bool
*/
- public function download_file($url, $options = array()) {
- $url = str_replace(array('+', ' '), '%20', $url);
+ public function download_file($url, $options = []): bool {
+ $url = str_replace(['+', ' '], '%20', $url);
+
return $this->request($url, $options);
}
}
diff --git a/local/o365/classes/httpclientinterface.php b/local/o365/classes/httpclientinterface.php
index 0037bb511..aa5b186bf 100644
--- a/local/o365/classes/httpclientinterface.php
+++ b/local/o365/classes/httpclientinterface.php
@@ -25,41 +25,39 @@
namespace local_o365;
-defined('MOODLE_INTERNAL') || die();
-
/**
* HTTP Client Interface.
*/
interface httpclientinterface {
- /**
- * HTTP POST method
- *
- * @param string $url
- * @param array|string $params
- * @param array $options
- * @return bool
- */
- public function post($url, $params = '', $options = array());
+ /**
+ * HTTP POST method
+ *
+ * @param string $url
+ * @param array|string $params
+ * @param array $options
+ * @return bool
+ */
+ public function post($url, $params = '', $options = []);
- /**
- * HTTP GET method
- *
- * @param string $url
- * @param array $params
- * @param array $options
- * @return bool
- */
- public function get($url, $params = array(), $options = array());
+ /**
+ * HTTP GET method
+ *
+ * @param string $url
+ * @param array $params
+ * @param array $options
+ * @return bool
+ */
+ public function get($url, $params = [], $options = []);
- /**
- * HTTP PATCH method
- *
- * @param string $url
- * @param array|string $params
- * @param array $options
- * @return bool
- */
- public function patch($url, $params = '', $options = array());
+ /**
+ * HTTP PATCH method
+ *
+ * @param string $url
+ * @param array|string $params
+ * @param array $options
+ * @return bool
+ */
+ public function patch($url, $params = '', $options = []);
/**
* HTTP DELETE method
@@ -69,7 +67,7 @@ public function patch($url, $params = '', $options = array());
* @param array $options
* @return bool
*/
- public function delete($url, $param = array(), $options = array());
+ public function delete($url, $param = [], $options = []);
/**
* Set HTTP Request Header
@@ -78,8 +76,8 @@ public function delete($url, $param = array(), $options = array());
*/
public function setheader($header);
- /**
- * Resets the HTTP Request headers (to prepare for the new request)
- */
+ /**
+ * Resets the HTTP Request headers (to prepare for the new request)
+ */
public function resetheader();
}
diff --git a/local/o365/classes/oauth2/apptoken.php b/local/o365/classes/oauth2/apptoken.php
index 0e29e25cb..32fdd531f 100644
--- a/local/o365/classes/oauth2/apptoken.php
+++ b/local/o365/classes/oauth2/apptoken.php
@@ -111,7 +111,7 @@ public static function get_app_token($tokenresource, \local_o365\oauth2\clientda
$params = http_build_query($params, '', '&');
$header = [
'Content-Type: application/x-www-form-urlencoded',
- 'Content-Length: '.strlen($params)
+ 'Content-Length: ' . strlen($params),
];
$httpclient->resetheader();
$httpclient->setheader($header);
@@ -133,7 +133,7 @@ public static function get_app_token($tokenresource, \local_o365\oauth2\clientda
}
$debuginfo = [
'tokenresult' => $tokenresult,
- 'resource' => $tokenresource
+ 'resource' => $tokenresource,
];
\local_o365\utils::debug($errmsg, __METHOD__, $debuginfo);
return false;
@@ -168,7 +168,7 @@ public function refresh() {
'scope' => $this->scope,
'token' => $this->token,
'expiry' => $this->expiry,
- 'tokenresource' => $this->tokenresource
+ 'tokenresource' => $this->tokenresource,
];
$this->update_stored_token($existingtoken, $newtoken);
} else {
diff --git a/local/o365/classes/oauth2/clientdata.php b/local/o365/classes/oauth2/clientdata.php
index c9721f760..4fe54a2cc 100644
--- a/local/o365/classes/oauth2/clientdata.php
+++ b/local/o365/classes/oauth2/clientdata.php
@@ -47,7 +47,7 @@ class clientdata {
/** @var string The token endpoint URI. */
protected $tokenendpoint;
- /** @var boolean The app-only token endpoint URI. */
+ /** @var bool The app-only token endpoint URI. */
protected $apptokenendpoint = false;
/**
diff --git a/local/o365/classes/oauth2/token.php b/local/o365/classes/oauth2/token.php
index 1d6b98b0f..961b9a81a 100644
--- a/local/o365/classes/oauth2/token.php
+++ b/local/o365/classes/oauth2/token.php
@@ -27,8 +27,6 @@
use moodle_exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Represents an oauth2 token.
*/
@@ -207,7 +205,7 @@ public static function jump_tokenresource(\local_o365\oauth2\token $token, $newt
$header = [
'Content-Type: application/x-www-form-urlencoded',
- 'Content-Length: '.strlen($params)
+ 'Content-Length: ' . strlen($params),
];
$httpclient->resetheader();
$httpclient->setheader($header);
@@ -260,7 +258,7 @@ public static function get_for_new_resource($userid, $tokenresource, \local_o365
$header = [
'Content-Type: application/x-www-form-urlencoded',
- 'Content-Length: '.strlen($params)
+ 'Content-Length: ' . strlen($params),
];
$httpclient->resetheader();
$httpclient->setheader($header);
@@ -282,7 +280,7 @@ public static function get_for_new_resource($userid, $tokenresource, \local_o365
}
$debuginfo = [
'tokenresult' => $tokenresult,
- 'resource' => $tokenresource
+ 'resource' => $tokenresource,
];
\local_o365\utils::debug($errmsg, __METHOD__, $debuginfo);
}
@@ -412,7 +410,7 @@ public function refresh() {
$header = [
'Content-Type: application/x-www-form-urlencoded',
- 'Content-Length: '.strlen($params)
+ 'Content-Length: ' . strlen($params),
];
$this->httpclient->resetheader();
$this->httpclient->setheader($header);
@@ -436,7 +434,7 @@ public function refresh() {
'token' => $this->token,
'expiry' => $this->expiry,
'refreshtoken' => $this->refreshtoken,
- 'tokenresource' => $this->tokenresource
+ 'tokenresource' => $this->tokenresource,
];
$this->update_stored_token($existingtoken, $newtoken);
}
diff --git a/local/o365/classes/obj/o365user.php b/local/o365/classes/obj/o365user.php
index f6f1ac829..5fe1b9eb6 100644
--- a/local/o365/classes/obj/o365user.php
+++ b/local/o365/classes/obj/o365user.php
@@ -25,10 +25,6 @@
namespace local_o365\obj;
-use local_o365\utils;
-
-defined('MOODLE_INTERNAL') || die();
-
/**
* Class representing Microsoft 365 user information.
*/
diff --git a/local/o365/classes/observers.php b/local/o365/classes/observers.php
index 9ac6a9d85..5b1f23915 100644
--- a/local/o365/classes/observers.php
+++ b/local/o365/classes/observers.php
@@ -81,7 +81,7 @@ class observers {
* @param user_authed $event The triggered event.
* @return bool Success/Failure.
*/
- public static function handle_oidc_user_authed(user_authed $event) : bool {
+ public static function handle_oidc_user_authed(user_authed $event): bool {
require_login();
require_capability('moodle/site:config', context_system::instance());
@@ -146,6 +146,7 @@ public static function handle_oidc_user_authed(user_authed $event) : bool {
}
} catch (moodle_exception $e) {
// Do nothing.
+ $domainsfetched = false;
}
if (!$domainsfetched) {
@@ -172,7 +173,7 @@ public static function handle_oidc_user_authed(user_authed $event) : bool {
* @param user_connected $event The triggered event.
* @return bool Success/Failure.
*/
- public static function handle_oidc_user_connected(user_connected $event) : bool {
+ public static function handle_oidc_user_connected(user_connected $event): bool {
global $DB;
if (utils::is_connected() !== true) {
@@ -269,7 +270,7 @@ public static function handle_oidc_user_connected(user_connected $event) : bool
* @param user_created $event The triggered event.
* @return bool Success/Failure.
*/
- public static function handle_user_created(user_created $event) : bool {
+ public static function handle_user_created(user_created $event): bool {
global $DB;
if (utils::is_connected() !== true) {
@@ -297,7 +298,7 @@ public static function handle_user_created(user_created $event) : bool {
* @param user_disconnected $event The triggered event.
* @return bool Success/Failure.
*/
- public static function handle_oidc_user_disconnected(user_disconnected $event) : bool {
+ public static function handle_oidc_user_disconnected(user_disconnected $event): bool {
global $DB;
$eventdata = $event->get_data();
@@ -321,7 +322,7 @@ public static function handle_oidc_user_disconnected(user_disconnected $event) :
* @param user_loggedin $event The triggered event.
* @return bool Success/Failure.
*/
- public static function handle_oidc_user_loggedin(user_loggedin $event) : bool {
+ public static function handle_oidc_user_loggedin(user_loggedin $event): bool {
if (utils::is_connected() !== true) {
return false;
}
@@ -341,7 +342,7 @@ public static function handle_oidc_user_loggedin(user_loggedin $event) : bool {
* @param int $userid The ID of the user we want more information about.
* @return bool Success/Failure.
*/
- public static function get_additional_user_info(int $userid) : bool {
+ public static function get_additional_user_info(int $userid): bool {
global $DB;
try {
@@ -417,7 +418,7 @@ public static function get_additional_user_info(int $userid) : bool {
* @param user_enrolment_updated $event The triggered event.
* @return bool Success/Failure.
*/
- public static function handle_user_enrolment_updated(user_enrolment_updated $event) : bool {
+ public static function handle_user_enrolment_updated(user_enrolment_updated $event): bool {
// Do nothing if sync direction is Teams to Moodle.
$courseusersyncdirection = get_config('local_o365', 'courseusersyncdirection');
if ($courseusersyncdirection == COURSE_USER_SYNC_DIRECTION_TEAMS_TO_MOODLE) {
@@ -442,7 +443,7 @@ public static function handle_user_enrolment_updated(user_enrolment_updated $eve
* @param enrol_instance_updated $event
* @return bool
*/
- public static function handle_enrol_instance_updated(enrol_instance_updated $event) : bool {
+ public static function handle_enrol_instance_updated(enrol_instance_updated $event): bool {
global $DB;
// Do nothing if sync direction is Teams to Moodle.
@@ -505,16 +506,16 @@ public static function handle_course_created(course_created $event): bool {
$coursecreatedfromcustomcourserequest = false;
- // Process course request approval
+ // Process course request approval.
$courseid = $event->objectid;
$course = get_course($courseid);
$shortnametocheck = $course->shortname;
- // First, try to get a record with an exact match on shortname
+ // First, try to get a record with an exact match on shortname.
$customrequest = $DB->get_record('local_o365_course_request',
['courseshortname' => $shortnametocheck, 'requeststatus' => feature\courserequest\main::COURSE_REQUEST_STATUS_PENDING]);
- // If no exact match, try removing the suffix _(number)
+ // If no exact match, try removing the suffix _(number).
if (!$customrequest && preg_match('/^(.+)_(\d+)$/', $course->shortname, $matches)) {
$shortnametocheck = $matches[1];
$customrequest = $DB->get_record('local_o365_course_request', ['courseshortname' => $shortnametocheck,
@@ -551,7 +552,7 @@ public static function handle_course_created(course_created $event): bool {
*
* @return bool
*/
- public static function handle_course_restored(course_restored $event) : bool {
+ public static function handle_course_restored(course_restored $event): bool {
if (utils::is_connected() !== true) {
return false;
}
@@ -580,7 +581,7 @@ public static function handle_course_restored(course_restored $event) : bool {
* @param course_updated $event The triggered event.
* @return bool Success/Failure.
*/
- public static function handle_course_updated(course_updated $event) : bool {
+ public static function handle_course_updated(course_updated $event): bool {
if (utils::is_connected() !== true) {
return false;
}
@@ -614,7 +615,7 @@ public static function handle_course_updated(course_updated $event) : bool {
* @param course_deleted $event The triggered event.
* @return bool Success/Failure.
*/
- public static function handle_course_deleted(course_deleted $event) : bool {
+ public static function handle_course_deleted(course_deleted $event): bool {
global $DB;
if (utils::is_connected() !== true) {
@@ -647,7 +648,7 @@ public static function handle_course_deleted(course_deleted $event) : bool {
* @param role_assigned $event The triggered event.
* @return bool Success/Failure.
*/
- public static function handle_role_assigned(role_assigned $event) : bool {
+ public static function handle_role_assigned(role_assigned $event): bool {
// Do nothing if sync direction is Teams to Moodle.
$courseusersyncdirection = get_config('local_o365', 'courseusersyncdirection');
if ($courseusersyncdirection == COURSE_USER_SYNC_DIRECTION_TEAMS_TO_MOODLE) {
@@ -676,7 +677,7 @@ public static function handle_role_assigned(role_assigned $event) : bool {
* @param role_unassigned $event The triggered event.
* @return bool Success/Failure.
*/
- public static function handle_role_unassigned(role_unassigned $event) : bool {
+ public static function handle_role_unassigned(role_unassigned $event): bool {
// Do nothing if sync direction is Teams to Moodle.
$courseusersyncdirection = get_config('local_o365', 'courseusersyncdirection');
if ($courseusersyncdirection == COURSE_USER_SYNC_DIRECTION_TEAMS_TO_MOODLE) {
@@ -705,7 +706,7 @@ public static function handle_role_unassigned(role_unassigned $event) : bool {
* @param capability_assigned|capability_unassigned $event
* @return bool
*/
- public static function handle_capability_change($event) {
+ public static function handle_capability_change($event): bool {
$roleid = $event->objectid;
// Resync owners and members in the groups connected to enabled Moodle courses.
@@ -734,7 +735,7 @@ public static function handle_capability_change($event) {
* @param role_deleted $event The triggered event.
* @return bool Success/Failure.
*/
- public static function handle_role_deleted(role_deleted $event) : bool {
+ public static function handle_role_deleted(role_deleted $event): bool {
if (utils::is_connected() !== true) {
return false;
}
@@ -757,7 +758,7 @@ public static function handle_role_deleted(role_deleted $event) : bool {
* @param user_deleted $event The triggered event.
* @return bool Success/Failure.
*/
- public static function handle_user_deleted(user_deleted $event) : bool {
+ public static function handle_user_deleted(user_deleted $event): bool {
global $DB;
$userid = $event->objectid;
$DB->delete_records('local_o365_token', ['user_id' => $userid]);
@@ -774,7 +775,7 @@ public static function handle_user_deleted(user_deleted $event) : bool {
*
* @return bool
*/
- public static function handle_config_log_created(config_log_created $event) : bool {
+ public static function handle_config_log_created(config_log_created $event): bool {
global $DB;
$eventdata = $event->get_data();
@@ -843,7 +844,7 @@ public static function handle_config_log_created(config_log_created $event) : bo
*
* @return bool
*/
- public static function handle_cohort_deleted(cohort_deleted $event) : bool {
+ public static function handle_cohort_deleted(cohort_deleted $event): bool {
global $DB;
$cohortid = $event->objectid;
diff --git a/local/o365/classes/page/acp.php b/local/o365/classes/page/acp.php
index 1327618ac..7d41d1f20 100644
--- a/local/o365/classes/page/acp.php
+++ b/local/o365/classes/page/acp.php
@@ -120,7 +120,7 @@ public function mode_adminconsent() {
$auth = new authcode;
$auth->set_httpclient(new httpclient());
$stateparams = ['redirect' => '/admin/settings.php?section=local_o365', 'justauth' => true, 'forceflow' => 'authcode',
- 'action' => 'adminconsent',];
+ 'action' => 'adminconsent'];
$idptype = get_config('auth_oidc', 'idptype');
if ($idptype == AUTH_OIDC_IDP_TYPE_MICROSOFT_IDENTITY_PLATFORM) {
$auth->initiateadminconsentrequest($stateparams);
@@ -135,7 +135,7 @@ public function mode_adminconsent() {
*
* @return bool
*/
- public function checktenantsetup() : bool {
+ public function checktenantsetup(): bool {
$config = get_config('local_o365');
if (empty($config->entratenant)) {
return false;
@@ -304,7 +304,7 @@ public function mode_tenantsaddgo() {
$auth = new authcode;
$auth->set_httpclient(new httpclient());
$stateparams = ['redirect' => '/local/o365/acp.php?mode=tenantsadd', 'justauth' => true, 'forceflow' => 'authcode',
- 'action' => 'addtenant', 'ignorerestrictions' => true,];
+ 'action' => 'addtenant', 'ignorerestrictions' => true];
$idptype = get_config('auth_oidc', 'idptype');
if ($idptype == AUTH_OIDC_IDP_TYPE_MICROSOFT_IDENTITY_PLATFORM) {
$auth->initiateadminconsentrequest($stateparams);
@@ -598,7 +598,7 @@ public function mode_coursesynccustom() {
$search = optional_param('search', '', PARAM_TEXT);
$sortdir = strtolower(optional_param('sortdir', 'asc', PARAM_ALPHA));
- $headers = ['fullname' => get_string('fullnamecourse'), 'shortname' => get_string('shortnamecourse'),];
+ $headers = ['fullname' => get_string('fullnamecourse'), 'shortname' => get_string('shortnamecourse')];
if (empty($sort) || !isset($headers[$sort])) {
$sort = 'fullname';
}
@@ -627,7 +627,7 @@ public function mode_coursesynccustom() {
if ($sortdir == 'desc') {
$sortdir = -1;
}
- $options = ['recursive' => true, 'sort' => [$sort => $sortdir], 'offset' => $limitfrom, 'limit' => $perpage,];
+ $options = ['recursive' => true, 'sort' => [$sort => $sortdir], 'offset' => $limitfrom, 'limit' => $perpage];
$topcat = core_course_category::get(0);
$courses = $topcat->get_courses($options);
$totalcount = $topcat->get_courses_count($options);
@@ -707,7 +707,7 @@ public function mode_coursesynccustom() {
var local_o365_coursesync_all_set_feature = function(state) {
if (confirm("' . get_string('acp_coursesynccustom_confirm_all_action', 'local_o365') . '")) {
var enabled = (state == 1) ? true : false;
-
+
// Send data to server
$.ajax({
url: \'' . $allchangeendpoint->out(false) . '\',
@@ -879,7 +879,7 @@ public function mode_teamconnections() {
$search = optional_param('search', '', PARAM_TEXT);
$sortdir = strtolower(optional_param('sortdir', 'asc', PARAM_ALPHA));
- $headers = ['fullname' => get_string('fullnamecourse'), 'shortname' => get_string('shortnamecourse'),];
+ $headers = ['fullname' => get_string('fullnamecourse'), 'shortname' => get_string('shortnamecourse')];
if (empty($sort) || !isset($headers[$sort])) {
$sort = 'fullname';
}
@@ -908,7 +908,7 @@ public function mode_teamconnections() {
if ($sortdir == 'desc') {
$sortdir = -1;
}
- $options = ['recursive' => true, 'sort' => [$sort => $sortdir], 'offset' => $limitfrom, 'limit' => $perpage,];
+ $options = ['recursive' => true, 'sort' => [$sort => $sortdir], 'offset' => $limitfrom, 'limit' => $perpage];
$topcat = core_course_category::get(0);
$courses = $topcat->get_courses($options);
$totalcount = $topcat->get_courses_count($options);
@@ -1013,7 +1013,7 @@ public function mode_teamconnections() {
$courseurl = new moodle_url('/course/view.php', ['id' => $course->id]);
- $rowdata = [html_writer::link($courseurl, $course->fullname), $course->shortname, $existingconnection, $actionsfield,];
+ $rowdata = [html_writer::link($courseurl, $course->fullname), $course->shortname, $existingconnection, $actionsfield];
$table->data[] = $rowdata;
}
@@ -1728,7 +1728,7 @@ public function mode_userconnections() {
$searchurl = new moodle_url('/local/o365/acp.php', ['mode' => 'userconnections']);
$filterfields = ['o365username' => 0, 'realname' => 0, 'username' => 0, 'idnumber' => 1, 'firstname' => 1, 'lastname' => 1,
- 'email' => 1,];
+ 'email' => 1];
$ufiltering = new filtering($filterfields, $searchurl);
[$extrasql, $params] = $ufiltering->get_sql_filter();
[$o365usernamesql, $o365usernameparams] = $ufiltering->get_filter_o365username();
@@ -1751,7 +1751,7 @@ public function mode_userconnections() {
* @return bool
* @throws moodle_exception
*/
- public function mode_userconnections_resync() : bool {
+ public function mode_userconnections_resync(): bool {
global $DB;
$userid = required_param('userid', PARAM_INT);
confirm_sesskey();
@@ -1829,14 +1829,14 @@ public function mode_userconnections_manualmatch() {
}
// Check if a o365 user object record already exists.
- $params = ['moodleid' => $userid, 'type' => 'user',];
+ $params = ['moodleid' => $userid, 'type' => 'user'];
$existingobject = $DB->get_record('local_o365_objects', $params);
if (!empty($existingobject) && $existingobject->o365name === $o365username) {
throw new moodle_exception('acp_userconnections_manualmatch_error_muserconnected2', 'local_o365');
}
$uselogin = (!empty($fromform->uselogin)) ? 1 : 0;
- $matchrec = (object) ['muserid' => $userid, 'entraidupn' => $o365username, 'uselogin' => $uselogin,];
+ $matchrec = (object) ['muserid' => $userid, 'entraidupn' => $o365username, 'uselogin' => $uselogin];
$DB->insert_record('local_o365_connections', $matchrec);
redirect(new moodle_url('/local/o365/acp.php', ['mode' => 'userconnections']));
die();
@@ -1871,7 +1871,7 @@ public function mode_userconnections_unmatch() {
$this->standard_header();
$message = get_string('acp_userconnections_table_unmatch_confirmmsg', 'local_o365', $user->username);
$message .= '
';
- $urlparams = ['mode' => 'userconnections_unmatch', 'userid' => $userid, 'confirmed' => 1, 'sesskey' => sesskey(),];
+ $urlparams = ['mode' => 'userconnections_unmatch', 'userid' => $userid, 'confirmed' => 1, 'sesskey' => sesskey()];
$url = new moodle_url('/local/o365/acp.php', $urlparams);
$label = get_string('acp_userconnections_table_unmatch', 'local_o365');
$message .= html_writer::link($url, $label);
@@ -1907,7 +1907,7 @@ public function mode_userconnections_disconnect() {
$this->standard_header();
$message = get_string('acp_userconnections_table_disconnect_confirmmsg', 'local_o365', $user->username);
$message .= '
';
- $urlparams = ['mode' => 'userconnections_disconnect', 'userid' => $userid, 'confirmed' => 1, 'sesskey' => sesskey(),];
+ $urlparams = ['mode' => 'userconnections_disconnect', 'userid' => $userid, 'confirmed' => 1, 'sesskey' => sesskey()];
$url = new moodle_url('/local/o365/acp.php', $urlparams);
$label = get_string('acp_userconnections_table_disconnect', 'local_o365');
$message .= html_writer::link($url, $label);
diff --git a/local/o365/classes/page/ajax.php b/local/o365/classes/page/ajax.php
index 1f94f79b0..c9ffc624f 100644
--- a/local/o365/classes/page/ajax.php
+++ b/local/o365/classes/page/ajax.php
@@ -36,8 +36,6 @@
use stdClass;
use webservice;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Ajax page.
*/
@@ -361,7 +359,7 @@ public function mode_checkteamsmoodlesetup() {
// Enable REST protocol.
$webservice = 'rest';
$availablewebservices = core_component::get_plugin_list('webservice');
- $activewebservices = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols);
+ $activewebservices = empty($CFG->webserviceprotocols) ? [] : explode(',', $CFG->webserviceprotocols);
foreach ($activewebservices as $key => $active) {
if (empty($availablewebservices[$active])) {
unset($activewebservices[$key]);
@@ -386,9 +384,7 @@ public function mode_checkteamsmoodlesetup() {
if (!$o365service->enabled) {
$o365service->enabled = 1;
$webservicemanager->update_external_service($o365service);
- $params = array(
- 'objectid' => $o365service->id
- );
+ $params = ['objectid' => $o365service->id];
$event = \core\event\webservice_service_updated::create($params);
$event->trigger();
$data->success[] = get_string('settings_notice_o365serviceenabled', 'local_o365');
diff --git a/local/o365/classes/page/base.php b/local/o365/classes/page/base.php
index 5a1acf74c..1536022fa 100644
--- a/local/o365/classes/page/base.php
+++ b/local/o365/classes/page/base.php
@@ -25,8 +25,6 @@
namespace local_o365\page;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Basic page-style class handling page setup and page modes.
*/
diff --git a/local/o365/classes/privacy/provider.php b/local/o365/classes/privacy/provider.php
index 9518ff996..ee9f7d42a 100644
--- a/local/o365/classes/privacy/provider.php
+++ b/local/o365/classes/privacy/provider.php
@@ -25,14 +25,22 @@
namespace local_o365\privacy;
-use \core_privacy\local\metadata\collection;
-use \core_privacy\local\request\contextlist;
-use \core_privacy\local\request\approved_contextlist;
-use \core_privacy\local\request\writer;
+use context;
+use core_privacy\local\metadata\collection;
+use core_privacy\local\request\approved_userlist;
+use core_privacy\local\request\contextlist;
+use core_privacy\local\request\approved_contextlist;
+use core_privacy\local\request\core_userlist_provider;
+use core_privacy\local\request\userlist;
+use core_privacy\local\request\writer;
+use stdClass;
defined('MOODLE_INTERNAL') || die();
-interface local_o365_userlist extends \core_privacy\local\request\core_userlist_provider {
+/**
+ * Local userlist provider for local_o365.
+ */
+interface local_o365_userlist extends core_userlist_provider {
};
/**
@@ -44,12 +52,12 @@ class provider implements
local_o365_userlist {
/**
- * Returns meta data about this system.
+ * Returns metadata about this system.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
- public static function get_metadata(collection $collection) : collection {
+ public static function get_metadata(collection $collection): collection {
$tables = [
'local_o365_calidmap' => [
@@ -132,8 +140,8 @@ public static function get_metadata(collection $collection) : collection {
* @param int $userid The user to search.
* @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
*/
- public static function get_contexts_for_userid(int $userid) : contextlist {
- $contextlist = new \core_privacy\local\request\contextlist();
+ public static function get_contexts_for_userid(int $userid): contextlist {
+ $contextlist = new contextlist();
if (self::user_has_o365_data($userid)) {
$contextlist->add_user_context($userid);
}
@@ -143,10 +151,9 @@ public static function get_contexts_for_userid(int $userid) : contextlist {
/**
* Get the list of users who have data within a context.
*
- * @param \core_privacy\local\request\userlist $userlist The userlist containing the list of users who have data in this
- * context/plugin combination.
+ * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*/
- public static function get_users_in_context(\core_privacy\local\request\userlist $userlist) {
+ public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();
if (!$context instanceof \context_user) {
return;
@@ -173,7 +180,7 @@ public static function export_user_data(approved_contextlist $contextlist) {
foreach ($records as $record) {
writer::with_context($context)->export_data([
get_string('privacy:metadata:local_o365', 'local_o365'),
- get_string('privacy:metadata:'.$table, 'local_o365')
+ get_string('privacy:metadata:'.$table, 'local_o365'),
], $record);
}
}
@@ -184,7 +191,7 @@ public static function export_user_data(approved_contextlist $contextlist) {
*
* @param context $context The specific context to delete data for.
*/
- public static function delete_data_for_all_users_in_context(\context $context) {
+ public static function delete_data_for_all_users_in_context(context $context) {
if ($context->contextlevel == CONTEXT_USER) {
self::delete_user_data($context->instanceid);
}
@@ -209,10 +216,9 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
/**
* Delete multiple users within a single context.
*
- * @param \core_privacy\local\request\approved_userlist $userlist The approved context and user information to delete
- * information for.
+ * @param approved_userlist $userlist The approved context and user information to delete information for.
*/
- public static function delete_data_for_users(\core_privacy\local\request\approved_userlist $userlist) {
+ public static function delete_data_for_users(approved_userlist $userlist) {
$context = $userlist->get_context();
if ($context instanceof \context_user) {
self::delete_user_data($context->instanceid);
@@ -228,7 +234,7 @@ public static function delete_data_for_users(\core_privacy\local\request\approve
private static function user_has_o365_data(int $userid) {
global $DB;
- $userdata = new \stdClass;
+ $userdata = new stdClass;
$userdata->id = $userid;
$user = $DB->get_record('user', ['id' => $userid]);
if (!empty($user)) {
@@ -252,7 +258,7 @@ private static function user_has_o365_data(int $userid) {
private static function delete_user_data(int $userid) {
global $DB;
- $userdata = new \stdClass;
+ $userdata = new stdClass;
$userdata->id = $userid;
$user = $DB->get_record('user', ['id' => $userid]);
if (!empty($user)) {
@@ -267,10 +273,10 @@ private static function delete_user_data(int $userid) {
/**
* Get a map of database tables that contain user data, and the filters to get records for a user.
*
- * @param \stdClass $user The user to get the map for.
+ * @param stdClass $user The user to get the map for.
* @return array The table user map.
*/
- protected static function get_table_user_map(\stdClass $user) : array {
+ protected static function get_table_user_map(stdClass $user): array {
$tables = [
'local_o365_calidmap' => ['userid' => $user->id],
'local_o365_calsub' => ['user_id' => $user->id],
diff --git a/local/o365/classes/rest/o365api.php b/local/o365/classes/rest/o365api.php
index 27b875f8f..38e5822bb 100644
--- a/local/o365/classes/rest/o365api.php
+++ b/local/o365/classes/rest/o365api.php
@@ -27,8 +27,6 @@
use moodle_exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Abstract base class for all o365 REST api classes.
*/
@@ -345,7 +343,7 @@ public function geturl($url, $options = []) {
if ($tokenvalid !== true) {
throw new moodle_exception('erroro365apiinvalidtoken', 'local_o365');
}
- $header = ['Authorization: Bearer ' . $this->token->get_token(),];
+ $header = ['Authorization: Bearer ' . $this->token->get_token()];
$this->httpclient->resetheader();
$this->httpclient->setheader($header);
return $this->httpclient->get($url, '', $options);
diff --git a/local/o365/classes/rest/unified.php b/local/o365/classes/rest/unified.php
index aeb6643cd..7a42d20b2 100644
--- a/local/o365/classes/rest/unified.php
+++ b/local/o365/classes/rest/unified.php
@@ -53,7 +53,7 @@ class unified extends o365api {
*
* @return bool Whether the API client is configured.
*/
- public static function is_configured() : bool {
+ public static function is_configured(): bool {
// Since legacy APIs are removed, unified is always configured.
return true;
}
@@ -63,7 +63,7 @@ public static function is_configured() : bool {
*
* @return string The resource for oauth2 tokens.
*/
- public static function get_tokenresource() : string {
+ public static function get_tokenresource(): string {
$oidcresource = get_config('auth_oidc', 'oidcresource');
if (!empty($oidcresource)) {
return $oidcresource;
@@ -92,7 +92,7 @@ public function get_apiuri() {
* @param string $apimethod The API method being called.
* @return string a simplified api area string.
*/
- protected function generate_apiarea(string $apimethod) : string {
+ protected function generate_apiarea(string $apimethod): string {
$apimethod = explode('/', $apimethod);
foreach ($apimethod as $apicomponent) {
$validareas = ['applications', 'groups', 'calendars', 'events', 'trendingaround', 'users'];
@@ -205,7 +205,7 @@ public function paginatedapicall($httpmethod, $apimethod, $odataqueries = [], $e
if (!empty($result['value']) && is_array($result['value'])) {
$content = array_merge($content, $result['value']);
}
-
+
if (isset($result['odata.nextLink'])) {
$skiptoken = $this->extract_param_from_link($result['odata.nextLink'], $skipparam);
} else if (isset($result['@odata.nextLink'])) {
@@ -236,7 +236,7 @@ public function paginatedapicall($httpmethod, $apimethod, $odataqueries = [], $e
* @return bool True if tenant succeeded, false if not.
* @throws moodle_exception
*/
- public function test_tenant(string $tenant) : bool {
+ public function test_tenant(string $tenant): bool {
if (!is_string($tenant)) {
throw new moodle_exception('errortenantvaluenotstring', 'local_o365');
}
@@ -254,7 +254,7 @@ public function test_tenant(string $tenant) : bool {
* @return string
* @throws moodle_exception
*/
- public function get_default_domain_name_in_tenant() : string {
+ public function get_default_domain_name_in_tenant(): string {
$response = $this->apicall('get', '/domains');
$response = $this->process_apicall_response($response, ['value' => null]);
foreach ($response['value'] as $domain) {
@@ -301,7 +301,7 @@ public function get_all_domain_names_in_tenant() {
* @return string The OneDrive URL string.
* @throws moodle_exception
*/
- public function get_odburl() : string {
+ public function get_odburl(): string {
$tenant = $this->get_default_domain_name_in_tenant();
$suffix = '.onmicrosoft.com';
$sufflen = strlen($suffix);
@@ -319,7 +319,7 @@ public function get_odburl() : string {
* @param clientdata $clientdata oAuth2 Credentials
* @return bool Whether the received resource is valid or not.
*/
- public function validate_resource(string $tokenresource, clientdata $clientdata) : bool {
+ public function validate_resource(string $tokenresource, clientdata $clientdata): bool {
$cleanresource = clean_param($tokenresource, PARAM_URL);
if ($cleanresource !== $tokenresource) {
return false;
@@ -337,13 +337,13 @@ public function validate_resource(string $tokenresource, clientdata $clientdata)
* @param string $appobjectid
* @return string|null
*/
- public function assign_user(int $muserid, string $userobjectid, string $appobjectid) : ?string {
+ public function assign_user(int $muserid, string $userobjectid, string $appobjectid): ?string {
global $DB;
$record = $DB->get_record('local_o365_appassign', ['muserid' => $muserid]);
if (empty($record) || $record->assigned == 0) {
$roleid = '00000000-0000-0000-0000-000000000000';
$endpoint = '/users/' . $userobjectid . '/appRoleAssignments/';
- $params = ['id' => $roleid, 'resourceId' => $appobjectid, 'principalId' => $userobjectid,];
+ $params = ['id' => $roleid, 'resourceId' => $appobjectid, 'principalId' => $userobjectid];
$response = $this->betaapicall('post', $endpoint, json_encode($params));
if (empty($record)) {
$record = new stdClass();
@@ -365,7 +365,7 @@ public function assign_user(int $muserid, string $userobjectid, string $appobjec
* @return array List of groups.
* @throws moodle_exception
*/
- public function get_groups() : array {
+ public function get_groups(): array {
$endpoint = '/groups';
return $this->paginatedapicall('get', $endpoint);
@@ -380,7 +380,7 @@ public function get_groups() : array {
* @return array|null
* @throws moodle_exception
*/
- public function create_group(string $name, string $mailnickname = null, array $extra = null) : ?array {
+ public function create_group(string $name, ?string $mailnickname = null, ?array $extra = null): ?array {
if (empty($mailnickname)) {
$mailnickname = $name;
}
@@ -443,7 +443,7 @@ public function create_group(string $name, string $mailnickname = null, array $e
* @return string Null string on success, json string on failure.
* @throws moodle_exception
*/
- public function update_group(array $groupdata) : string {
+ public function update_group(array $groupdata): string {
// Check for required parameters.
if (empty($groupdata['id'])) {
throw new moodle_exception('invalidgroupdata', 'local_o365');
@@ -474,7 +474,7 @@ public function update_group(array $groupdata) : string {
* @return array Array of returned o365 group data.
* @throws moodle_exception
*/
- public function get_group(string $objectid) : array {
+ public function get_group(string $objectid): array {
$response = $this->apicall('get', '/groups/' . $objectid);
$expectedparams = ['id' => null];
return $this->process_apicall_response($response, $expectedparams);
@@ -484,10 +484,11 @@ public function get_group(string $objectid) : array {
* Get group urls.
*
* @param string $objectid The object ID of the group.
- * @return array Array of returned o365 group urls, null on no group data found.
+ * @return array|null Array of returned o365 group urls, null on no group data found.
+ * @throws \dml_exception
* @throws moodle_exception
*/
- public function get_group_urls(string $objectid) : ?array {
+ public function get_group_urls(string $objectid): ?array {
$group = $this->get_group($objectid);
if (empty($group['mailNickname'])) {
return null;
@@ -508,12 +509,13 @@ public function get_group_urls(string $objectid) : ?array {
];
try {
[$rawteam, $teamurl, $lockstatus] = $this->get_team($objectid);
- if ($teamurl) {
- $o365urls['team'] = $teamurl;
- }
} catch (moodle_exception $e) {
- // Do nothing.
+ $teamurl = null;
+ }
+ if ($teamurl) {
+ $o365urls['team'] = $teamurl;
}
+
return $o365urls;
}
@@ -550,10 +552,10 @@ public function get_team(string $objectid) {
* Get a group by its displayName
*
* @param string $name The group name,
- * @return array Array of group information, or null if group not found.
+ * @return array|null Array of group information, or null if group not found.
* @throws moodle_exception
*/
- public function get_group_by_name(string $name) : ?array {
+ public function get_group_by_name(string $name): ?array {
$response = $this->apicall('get', '/groups?$filter=displayName' . rawurlencode(' eq \'' . $name . '\''));
$expectedparams = ['value' => null];
$groups = $this->process_apicall_response($response, $expectedparams);
@@ -580,7 +582,7 @@ public function delete_group(string $objectid) {
* @return array Array of returned information.
* @throws moodle_exception
*/
- public function list_deleted_groups() : array {
+ public function list_deleted_groups(): array {
$endpoint = '/directory/deleteditems/Microsoft.Graph.Group';
return $this->paginatedapicall('get', $endpoint, [], ['value' => null], true);
@@ -593,7 +595,7 @@ public function list_deleted_groups() : array {
* @return array Array of returned information.
* @throws moodle_exception
*/
- public function restore_deleted_group(string $objectid) : array {
+ public function restore_deleted_group(string $objectid): array {
$response = $this->betaapicall('post', '/directory/deleteditems/' . $objectid . '/restore');
return $this->process_apicall_response($response);
}
@@ -605,7 +607,7 @@ public function restore_deleted_group(string $objectid) : array {
* @return array Array of returned members.
* @throws moodle_exception
*/
- public function get_group_members(string $groupobjectid) : array {
+ public function get_group_members(string $groupobjectid): array {
$endpoint = '/groups/' . $groupobjectid . '/members';
return $this->paginatedapicall('get', $endpoint);
@@ -615,10 +617,10 @@ public function get_group_members(string $groupobjectid) : array {
* Get a list of group owners.
*
* @param string $groupobjectid The object ID of the group.
- * @return array Array of returned owners.
+ * @return array|null Array of returned owners.
* @throws moodle_exception
*/
- public function get_group_owners(string $groupobjectid) : ?array {
+ public function get_group_owners(string $groupobjectid): ?array {
$endpoint = '/groups/' . $groupobjectid . '/owners';
return $this->paginatedapicall('get', $endpoint);
@@ -633,7 +635,7 @@ public function get_group_owners(string $groupobjectid) : ?array {
* @return array|null Returned response, or null if error.
* @throws moodle_exception
*/
- public function get_group_files(string $groupid, string $parentid = '', string $skiptoken = '') : ?array {
+ public function get_group_files(string $groupid, string $parentid = '', string $skiptoken = ''): ?array {
if (!empty($parentid) && $parentid !== '/') {
$endpoint = "/groups/$groupid/drive/items/$parentid/children";
} else {
@@ -664,7 +666,7 @@ public function get_group_files(string $groupid, string $parentid = '', string $
* @return array|null The file's content.
* @throws moodle_exception
*/
- public function get_group_file_metadata(string $groupid, string $fileid) : ?array {
+ public function get_group_file_metadata(string $groupid, string $fileid): ?array {
$response = $this->apicall('get', "/groups/$groupid/drive/items/$fileid");
$expectedparams = ['id' => null];
return $this->process_apicall_response($response, $expectedparams);
@@ -678,7 +680,7 @@ public function get_group_file_metadata(string $groupid, string $fileid) : ?arra
* @return string Sharing link url.
* @throws moodle_exception
*/
- public function get_group_file_sharing_link(string $groupid, string $fileid) : string {
+ public function get_group_file_sharing_link(string $groupid, string $fileid): string {
$params = ['type' => 'view', 'scope' => 'organization'];
$apiresponse = $this->apicall('post', "/groups/$groupid/drive/items/$fileid/createLink", json_encode($params));
$response = $this->process_apicall_response($apiresponse);
@@ -686,13 +688,13 @@ public function get_group_file_sharing_link(string $groupid, string $fileid) : s
}
/**
- * Get a file's content by it's file id.
+ * Get a file's content by its file id.
*
* @param string $groupid
* @param string $fileid The file's ID.
* @return string The file's content.
*/
- public function get_group_file_by_id(string $groupid, string $fileid) : string {
+ public function get_group_file_by_id(string $groupid, string $fileid): string {
return $this->apicall('get', "/groups/$groupid/drive/items/$fileid/content");
}
@@ -733,7 +735,7 @@ public function add_owner_to_group_using_group_api(string $groupobjectid, string
* @param string $memberobjectid The object ID of the item to remove (can be group object id or user object id).
* @return bool
*/
- public function remove_member_from_group_using_group_api(string $groupobjectid, string $memberobjectid) : bool {
+ public function remove_member_from_group_using_group_api(string $groupobjectid, string $memberobjectid): bool {
$endpoint = '/groups/' . $groupobjectid . '/members/' . $memberobjectid . '/$ref';
$this->betaapicall('delete', $endpoint);
if ($this->check_expected_http_code(['204'])) {
@@ -750,7 +752,7 @@ public function remove_member_from_group_using_group_api(string $groupobjectid,
* @param string $ownerobjectid The object ID of the item to remove (can be group object id or user object id).
* @return bool
*/
- public function remove_owner_from_group_using_group_api(string $groupobjectid, string $ownerobjectid) : bool {
+ public function remove_owner_from_group_using_group_api(string $groupobjectid, string $ownerobjectid): bool {
$endpoint = '/groups/' . $groupobjectid . '/owners/' . $ownerobjectid . '/$ref';
$this->betaapicall('delete', $endpoint);
if ($this->check_expected_http_code(['204'])) {
@@ -768,7 +770,7 @@ public function remove_owner_from_group_using_group_api(string $groupobjectid, s
* @return array|null
* @throws moodle_exception
*/
- public function add_member_to_group_using_teams_api(string $groupobjectid, string $userobjectid) : ?array {
+ public function add_member_to_group_using_teams_api(string $groupobjectid, string $userobjectid): ?array {
$endpoint = '/teams/' . $groupobjectid . '/members';
$data = [
'@odata.type' => '#microsoft.graph.aadUserConversationMember',
@@ -788,7 +790,7 @@ public function add_member_to_group_using_teams_api(string $groupobjectid, strin
* @return array|null
* @throws moodle_exception
*/
- public function add_owner_to_group_using_teams_api(string $groupobjectid, string $userobjectid) : ?array {
+ public function add_owner_to_group_using_teams_api(string $groupobjectid, string $userobjectid): ?array {
$endpoint = '/teams/' . $groupobjectid . '/members';
$data = [
'@odata.type' => '#microsoft.graph.aadUserConversationMember',
@@ -808,7 +810,7 @@ public function add_owner_to_group_using_teams_api(string $groupobjectid, string
* @return string
* @throws moodle_exception
*/
- public function get_aad_user_conversation_member_id(string $groupobjectid, string $userobjectid) : string {
+ public function get_aad_user_conversation_member_id(string $groupobjectid, string $userobjectid): string {
$endpoint = '/teams/' . $groupobjectid . '/members/?$filter=microsoft.graph.aadUserConversationMember/userId%20in%20("' .
$userobjectid . '")';
@@ -832,7 +834,7 @@ public function get_aad_user_conversation_member_id(string $groupobjectid, strin
* @throws moodle_exception
*/
public function remove_owner_and_member_from_group_using_teams_api(string $groupobjectid,
- string $aaduserconversationmemberid) : ?array {
+ string $aaduserconversationmemberid): ?array {
$endpoint = '/teams/' . $groupobjectid . '/members/' . $aaduserconversationmemberid;
$response = $this->apicall('delete', $endpoint);
@@ -850,7 +852,7 @@ public function remove_owner_and_member_from_group_using_teams_api(string $group
* @throws moodle_exception
*/
public function create_group_file(string $groupid, string $filename, string $content,
- string $contenttype = 'text/plain') : ?array {
+ string $contenttype = 'text/plain'): ?array {
$filename = rawurlencode($filename);
$endpoint = "/groups/$groupid/drive/root:/$filename:/content";
$fileresponse = $this->apicall('put', $endpoint, ['file' => $content], ['contenttype' => $contenttype]);
@@ -864,12 +866,12 @@ public function create_group_file(string $groupid, string $filename, string $con
* @param bool $guestuser if the fields are for a guest user.
* @return array Array of user fields.
*/
- protected function get_default_user_fields(bool $guestuser = false) : array {
+ protected function get_default_user_fields(bool $guestuser = false): array {
$defaultfields =
['id', 'userPrincipalName', 'displayName', 'givenName', 'surname', 'mail', 'streetAddress', 'city', 'postalCode',
'state', 'country', 'jobTitle', 'department', 'companyName', 'preferredLanguage', 'employeeId', 'businessPhones',
'faxNumber', 'mobilePhone', 'officeLocation', 'manager', 'teams', 'roles', 'groups', 'accountEnabled',
- 'onPremisesExtensionAttributes', 'onPremisesSamAccountName',];
+ 'onPremisesExtensionAttributes', 'onPremisesSamAccountName'];
if (!$guestuser) {
$defaultfields[] = 'preferredName';
}
@@ -884,7 +886,7 @@ protected function get_default_user_fields(bool $guestuser = false) : array {
* @return array|null Array of user information, or null if failure.
* @throws moodle_exception
*/
- public function get_users($params = 'default') : ?array {
+ public function get_users($params = 'default'): ?array {
$endpoint = "/users";
$odataqueries = [];
@@ -912,7 +914,7 @@ public function get_users($params = 'default') : ?array {
* @param string|null $deltatoken
* @return array
*/
- public function get_users_delta($params, string $deltatoken = null) : array {
+ public function get_users_delta($params, ?string $deltatoken = null): array {
$endpoint = "/users/delta";
$odataqueries = [];
@@ -961,7 +963,7 @@ public function get_users_delta($params, string $deltatoken = null) : array {
* @param string $userobjectid - user AD id
* @return array|null
*/
- public function get_user_manager(string $userobjectid) : ?array {
+ public function get_user_manager(string $userobjectid): ?array {
$endpoint = "users/$userobjectid/manager";
$response = $this->apicall('get', $endpoint);
try {
@@ -980,7 +982,7 @@ public function get_user_manager(string $userobjectid) : ?array {
* @return array
* @throws moodle_exception
*/
- public function get_user_groups(string $userobjectid) : array {
+ public function get_user_groups(string $userobjectid): array {
$endpoint = "users/$userobjectid/transitiveMemberOf/microsoft.graph.group";
return $this->paginatedapicall('get', $endpoint);
}
@@ -992,7 +994,7 @@ public function get_user_groups(string $userobjectid) : array {
* @return array
* @throws moodle_exception
*/
- public function get_user_transitive_groups(string $userobjectid) : ?array {
+ public function get_user_transitive_groups(string $userobjectid): ?array {
$endpoint = "users/$userobjectid/getMemberGroups";
return $this->paginatedapicall('post', $endpoint, [], ['value' => null], false,
json_encode(['securityEnabledOnly' => false]));
@@ -1005,7 +1007,7 @@ public function get_user_transitive_groups(string $userobjectid) : ?array {
* @return array
* @throws moodle_exception
*/
- public function get_user_teams(string $userobjectid) : array {
+ public function get_user_teams(string $userobjectid): array {
$endpoint = "users/$userobjectid/joinedTeams";
return $this->paginatedapicall('get', $endpoint);
}
@@ -1018,7 +1020,7 @@ public function get_user_teams(string $userobjectid) : array {
* @return array
* @throws moodle_exception
*/
- public function get_user_objects(string $userobjectid, bool $securityenabledonly = true) : array {
+ public function get_user_objects(string $userobjectid, bool $securityenabledonly = true): array {
$endpoint = "users/$userobjectid/getMemberObjects";
$data = ['securityEnabledOnly' => $securityenabledonly];
return $this->paginatedapicall('post', $endpoint, [], ['value' => null], false, json_encode($data));
@@ -1032,7 +1034,7 @@ public function get_user_objects(string $userobjectid, bool $securityenabledonly
* @return array|null
* @throws moodle_exception
*/
- public function get_directory_objects(array $ids, string $types = null) : ?array {
+ public function get_directory_objects(array $ids, ?string $types = null): ?array {
$endpoint = "directoryObjects/getByIds";
$data = ['ids' => $ids];
if (!empty($types)) {
@@ -1050,7 +1052,7 @@ public function get_directory_objects(array $ids, string $types = null) : ?array
* @param string $param Parameter name.
* @return string|null The extracted deltalink value, or null if none found.
*/
- protected function extract_param_from_link(string $link, string $param) : ?string {
+ protected function extract_param_from_link(string $link, string $param): ?string {
$link = parse_url($link);
if (isset($link['query'])) {
$output = [];
@@ -1068,7 +1070,7 @@ protected function extract_param_from_link(string $link, string $param) : ?strin
* @return array Array of returned information.
* @throws moodle_exception
*/
- public function list_deleted_users() : array {
+ public function list_deleted_users(): array {
$endpoint = '/directory/deleteditems/Microsoft.Graph.User';
return $this->paginatedapicall('get', $endpoint, [], ['value' => null], true);
@@ -1081,7 +1083,7 @@ public function list_deleted_users() : array {
* @return array Array of user data.
* @throws moodle_exception
*/
- public function get_user_by_upn(string $upn) : array {
+ public function get_user_by_upn(string $upn): array {
$endpoint = '/users/' . rawurlencode($upn);
$response = $this->apicall('get', $endpoint);
$expectedparams = ['id' => null, 'userPrincipalName' => null];
@@ -1092,10 +1094,10 @@ public function get_user_by_upn(string $upn) : array {
* Get a list of the user's o365 calendars.
*
* @param string $upn The user's userPrincipalName
- * @return array Returned response
+ * @return array|null Returned response
* @throws moodle_exception
*/
- public function get_calendars(string $upn) : ?array {
+ public function get_calendars(string $upn): ?array {
$endpoint = '/users/' . $upn . '/calendars';
return $this->paginatedapicall('get', $endpoint, [], ['value' => null], false, '', [], '$skip');
@@ -1109,7 +1111,7 @@ public function get_calendars(string $upn) : ?array {
* @return array|null Returned response, or null if error.
* @throws moodle_exception
*/
- public function create_calendar(string $name, string $upn) : ?array {
+ public function create_calendar(string $name, string $upn): ?array {
$calendardata = json_encode(['name' => $name]);
$response = $this->apicall('post', '/users/' . $upn . '/calendars', $calendardata);
$expectedparams = ['id' => null];
@@ -1132,7 +1134,7 @@ public function create_calendar(string $name, string $upn) : ?array {
* @return array|null Returned response, or null if error.
* @throws moodle_exception
*/
- public function update_calendar(string $calendearid, array $updated, string $upn) : ?array {
+ public function update_calendar(string $calendearid, array $updated, string $upn): ?array {
if (empty($calendearid) || empty($updated)) {
return [];
}
@@ -1161,7 +1163,7 @@ public function update_calendar(string $calendearid, array $updated, string $upn
* @throws moodle_exception
*/
public function create_event(string $subject, string $body, int $starttime, int $endtime, array $attendees, array $other,
- ?string $calendarid, string $upn) : ?array {
+ ?string $calendarid, string $upn): ?array {
$eventdata = [
'subject' => $subject,
'body' => [
@@ -1185,7 +1187,7 @@ public function create_event(string $subject, string $body, int $starttime, int
'Address' => $attendee->email,
'Name' => $attendee->firstname.' '.$attendee->lastname,
],
- 'type' => 'Resource'
+ 'type' => 'Resource',
];
}
$eventdata = array_merge($eventdata, $other);
@@ -1238,7 +1240,7 @@ public function create_group_event(string $subject, string $body, int $starttime
'Address' => $attendee->email,
'Name' => $attendee->firstname.' '.$attendee->lastname,
],
- 'type' => 'Resource'
+ 'type' => 'Resource',
];
}
$eventdata = array_merge($eventdata, $other);
@@ -1262,7 +1264,7 @@ public function create_group_event(string $subject, string $body, int $starttime
* @return array Array of events.
* @throws moodle_exception
*/
- public function get_events(string $calendarid, string $since, string $upn) : array {
+ public function get_events(string $calendarid, string $since, string $upn): array {
core_date::set_default_server_timezone();
$endpoint = (!empty($calendarid)) ? '/users/' . $upn . '/calendars/' . $calendarid . '/events' :
'/users/' . $upn . '/calendar/events';
@@ -1287,7 +1289,7 @@ public function get_events(string $calendarid, string $since, string $upn) : arr
* @return array|null Returned response, or null if error.
* @throws moodle_exception
*/
- public function update_event(string $outlookeventid, array $updated, string $upn) : ?array {
+ public function update_event(string $outlookeventid, array $updated, string $upn): ?array {
if (empty($outlookeventid) || empty($updated)) {
return [];
}
@@ -1300,10 +1302,10 @@ public function update_event(string $outlookeventid, array $updated, string $upn
}
if (!empty($updated['starttime'])) {
$updateddata['start'] =
- ['dateTime' => date('c', $updated['starttime']), 'timeZone' => date('T', $updated['starttime']),];
+ ['dateTime' => date('c', $updated['starttime']), 'timeZone' => date('T', $updated['starttime'])];
}
if (!empty($updated['endtime'])) {
- $updateddata['end'] = ['dateTime' => date('c', $updated['endtime']), 'timeZone' => date('T', $updated['endtime']),];
+ $updateddata['end'] = ['dateTime' => date('c', $updated['endtime']), 'timeZone' => date('T', $updated['endtime'])];
}
if (!empty($updated['responseRequested'])) {
$updateddata['responseRequested'] = $updated['responseRequested'];
@@ -1312,7 +1314,7 @@ public function update_event(string $outlookeventid, array $updated, string $upn
$updateddata['attendees'] = [];
foreach ($updated['attendees'] as $attendee) {
$updateddata['attendees'][] =
- ['emailAddress' => ['address' => $attendee->email, 'name' => $attendee->firstname . ' ' . $attendee->lastname,],
+ ['emailAddress' => ['address' => $attendee->email, 'name' => $attendee->firstname . ' ' . $attendee->lastname],
'type' => 'resource'];
}
}
@@ -1329,7 +1331,7 @@ public function update_event(string $outlookeventid, array $updated, string $upn
* @param string $upn user's userPrincipalName
* @return bool Success/Failure.
*/
- public function delete_event(string $outlookeventid, string $upn) : bool {
+ public function delete_event(string $outlookeventid, string $upn): bool {
if (!empty($outlookeventid)) {
$this->apicall('delete', '/users/' . $upn . '/events/' . $outlookeventid);
}
@@ -1348,7 +1350,7 @@ public function delete_event(string $outlookeventid, string $upn) : bool {
* @throws moodle_exception
*/
public function create_file(string $parentid, string $filename, string $content, string $contenttype,
- string $o365userid) : ?array {
+ string $o365userid): ?array {
$filename = rawurlencode($filename);
if (!empty($parentid)) {
$endpoint = "/users/$o365userid/drive/items/$parentid:/$filename:/content";
@@ -1369,7 +1371,7 @@ public function create_file(string $parentid, string $filename, string $content,
* @return array|null Returned response, or null if error.
* @throws moodle_exception
*/
- public function get_user_files(string $parentid, string $o365userid, string $skiptoken = '') : ?array {
+ public function get_user_files(string $parentid, string $o365userid, string $skiptoken = ''): ?array {
if (!empty($parentid) && $parentid !== '/') {
$endpoint = "/users/$o365userid/drive/items/$parentid/children";
} else {
@@ -1401,7 +1403,7 @@ public function get_user_files(string $parentid, string $o365userid, string $ski
* @return array|null Returned response, or null if error.
* @throws moodle_exception
*/
- public function get_trending_files(string $upn, string $skiptoken = '') : ?array {
+ public function get_trending_files(string $upn, string $skiptoken = ''): ?array {
$endpoint = '/users/' . $upn . '/trendingAround';
$odataqueries = [];
@@ -1428,7 +1430,7 @@ public function get_trending_files(string $upn, string $skiptoken = '') : ?array
* @return array|null The file's content.
* @throws moodle_exception
*/
- public function get_file_data(string $fileinfo) : ?array {
+ public function get_file_data(string $fileinfo): ?array {
$response = $this->apicall('get', "/$fileinfo");
$expectedparams = ['id' => null];
return $this->process_apicall_response($response, $expectedparams);
@@ -1440,7 +1442,7 @@ public function get_file_data(string $fileinfo) : ?array {
* @param string $url The file's URL.
* @return string The file's content.
*/
- public function get_file_by_url(string $url) : string {
+ public function get_file_by_url(string $url): string {
return $this->httpclient->download_file($url);
}
@@ -1452,20 +1454,20 @@ public function get_file_by_url(string $url) : string {
* @return array|null The file's metadata.
* @throws moodle_exception
*/
- public function get_file_metadata(string $fileid, string $o365userid) : ?array {
+ public function get_file_metadata(string $fileid, string $o365userid): ?array {
$response = $this->apicall('get', "/users/$o365userid/drive/items/$fileid");
$expectedparams = ['id' => null];
return $this->process_apicall_response($response, $expectedparams);
}
/**
- * Get a file's content by it's file id.
+ * Get a file's content by its file id.
*
* @param string $fileid The file's ID.
* @param string $o365userid user's Microsoft 365 account object ID
* @return string The file's content.
*/
- public function get_file_by_id(string $fileid, string $o365userid) : string {
+ public function get_file_by_id(string $fileid, string $o365userid): string {
return $this->apicall('get', "/users/$o365userid/drive/items/$fileid/content");
}
@@ -1475,7 +1477,7 @@ public function get_file_by_id(string $fileid, string $o365userid) : string {
* @return array|null Array of application information, or null if failure.
* @throws moodle_exception
*/
- public function get_application_info() : ?array {
+ public function get_application_info(): ?array {
$oidcconfig = get_config('auth_oidc');
$endpoint = '/applications/?$filter=appId%20eq%20\'' . $oidcconfig->clientid . '\'';
$response = $this->betaapicall('get', $endpoint);
@@ -1489,7 +1491,7 @@ public function get_application_info() : ?array {
* @return array|null Array of application information, or null if failure.
* @throws moodle_exception
*/
- public function get_application_serviceprincipal_info() : ?array {
+ public function get_application_serviceprincipal_info(): ?array {
$oidcconfig = get_config('auth_oidc');
$endpoint = '/servicePrincipals/?$filter=appId%20eq%20\'' . $oidcconfig->clientid . '\'';
$response = $this->betaapicall('get', $endpoint);
@@ -1500,10 +1502,10 @@ public function get_application_serviceprincipal_info() : ?array {
/**
* Get the service principal object for the Microsoft Graph API.
*
- * @return array Array representing service principal object.
+ * @return array|null Array representing service principal object.
* @throws moodle_exception
*/
- public function get_unified_api_serviceprincipal_info() : ?array {
+ public function get_unified_api_serviceprincipal_info(): ?array {
static $response = null;
if (empty($response)) {
$graphperms = $this->get_required_permissions('graph');
@@ -1518,9 +1520,9 @@ public function get_unified_api_serviceprincipal_info() : ?array {
/**
* Get all available permissions for the Microsoft Graph API.
*
- * @return array Array of available permissions, include descriptions and keys.
+ * @return array|null Array of available permissions, include descriptions and keys.
*/
- public function get_available_permissions() : ?array {
+ public function get_available_permissions(): ?array {
$svc = $this->get_unified_api_serviceprincipal_info();
if (empty($svc) || !is_array($svc)) {
return null;
@@ -1542,7 +1544,7 @@ public function get_available_permissions() : ?array {
*
* @return array Array of available app-only permissions, indexed by permission name.
*/
- public function get_graph_available_apponly_permissions() : array {
+ public function get_graph_available_apponly_permissions(): array {
// Get list of permissions and associated IDs.
$graphsp = $this->get_unified_api_serviceprincipal_info();
$graphsp = $graphsp['value'][0];
@@ -1559,7 +1561,7 @@ public function get_graph_available_apponly_permissions() : array {
* @return array Array of current app-only permissions, indexed by permission name.
* @throws moodle_exception
*/
- public function get_graph_current_apponly_permissions() : array {
+ public function get_graph_current_apponly_permissions(): array {
// Get available permissions.
$graphsp = $this->get_unified_api_serviceprincipal_info();
$graphsp = $graphsp['value'][0];
@@ -1603,7 +1605,7 @@ public function get_graph_current_apponly_permissions() : array {
* @return array|null Array of application information, or null if failure.
* @throws moodle_exception
*/
- public function get_permission_grants(string $resourceid = '') : ?array {
+ public function get_permission_grants(string $resourceid = ''): ?array {
$appinfo = $this->get_application_serviceprincipal_info();
if (empty($appinfo) || !is_array($appinfo)) {
return null;
@@ -1623,9 +1625,9 @@ public function get_permission_grants(string $resourceid = '') : ?array {
/**
* Get currently assigned permissions for the Microsoft Graph API.
*
- * @return array Array of permission keys.
+ * @return array|null Array of permission keys.
*/
- public function get_unified_api_permissions() : ?array {
+ public function get_unified_api_permissions(): ?array {
$apiinfo = $this->get_unified_api_serviceprincipal_info();
if (empty($apiinfo) || !is_array($apiinfo)) {
return null;
@@ -1649,7 +1651,7 @@ public function get_unified_api_permissions() : ?array {
*
* @return array Array of required delegated permissions.
*/
- public function get_graph_required_permissions() : array {
+ public function get_graph_required_permissions(): array {
$allperms = $this->get_required_permissions();
if (isset($allperms['graph'])) {
return $allperms['graph']['requiredDelegatedPermissionsUsingAppPermissions'];
@@ -1663,7 +1665,7 @@ public function get_graph_required_permissions() : array {
*
* @return array Array of required application permissions.
*/
- public function get_graph_required_apponly_permissions() : array {
+ public function get_graph_required_apponly_permissions(): array {
$allperms = $this->get_required_permissions();
if (isset($allperms['graph'])) {
return $allperms['graph']['requiredAppPermissions'];
@@ -1677,7 +1679,7 @@ public function get_graph_required_apponly_permissions() : array {
*
* @return array
*/
- public function check_graph_apponly_permissions() : array {
+ public function check_graph_apponly_permissions(): array {
$this->token->refresh();
$requiredperms = $this->get_graph_required_apponly_permissions();
$currentperms = $this->get_graph_current_apponly_permissions();
@@ -1727,9 +1729,9 @@ public function check_graph_apponly_permissions() : array {
/**
* Check whether all required permissions are present.
*
- * @return array Array of missing permissions, permission key as array key, human-readable name as values.
+ * @return array|null Array of missing permissions, permission key as array key, human-readable name as values.
*/
- public function check_graph_delegated_permissions() : ?array {
+ public function check_graph_delegated_permissions(): ?array {
$this->token->refresh();
$currentperms = $this->get_unified_api_permissions();
$requiredperms = $this->get_graph_required_permissions();
@@ -1821,7 +1823,7 @@ public function get_photo(string $user) {
* @return string Readonly file url.
* @throws moodle_exception
*/
- public function get_sharing_link(string $fileid, string $o365userid) : string {
+ public function get_sharing_link(string $fileid, string $o365userid): string {
$params = ['type' => 'view', 'scope' => 'organization'];
$apiresponse = $this->apicall('post', "/users/$o365userid/drive/items/$fileid/createLink", json_encode($params));
$response = $this->process_apicall_response($apiresponse);
@@ -1836,7 +1838,7 @@ public function get_sharing_link(string $fileid, string $o365userid) : string {
* @return array|null Array of user information, or null if failure.
* @throws moodle_exception
*/
- public function get_user(string $oid, bool $guestuser = false) : ?array {
+ public function get_user(string $oid, bool $guestuser = false): ?array {
$endpoint = "/users/$oid";
$odataqueries = [];
@@ -1851,7 +1853,7 @@ public function get_user(string $oid, bool $guestuser = false) : ?array {
try {
$response = $this->apicall('get', $endpoint);
- $expectedparams = ['@odata.context' => $context, 'id' => null, 'userPrincipalName' => null,];
+ $expectedparams = ['@odata.context' => $context, 'id' => null, 'userPrincipalName' => null];
$result = $this->process_apicall_response($response, $expectedparams);
if (!empty($result['id'])) {
@@ -1871,9 +1873,9 @@ public function get_user(string $oid, bool $guestuser = false) : ?array {
* @return bool
* @throws moodle_exception
*/
- public function provision_app(string $groupobjectid, string $appid) : bool {
+ public function provision_app(string $groupobjectid, string $appid): bool {
$endpoint = '/teams/' . $groupobjectid . '/installedApps';
- $data = ['teamsApp@odata.bind' => $this->get_apiuri() . '/beta/appCatalogs/teamsApps/' . $appid,];
+ $data = ['teamsApp@odata.bind' => $this->get_apiuri() . '/beta/appCatalogs/teamsApps/' . $appid];
$this->betaapicall('post', $endpoint, json_encode($data));
// If the request was successful, it would return 201; otherwise, if the request failed with "duplicate",
@@ -1892,7 +1894,7 @@ public function provision_app(string $groupobjectid, string $appid) : bool {
* @return string|null
* @throws moodle_exception
*/
- public function get_catalog_app_id(string $externalappid) : ?string {
+ public function get_catalog_app_id(string $externalappid): ?string {
$moodleappid = null;
$endpoint = '/appCatalogs/teamsApps?$filter=externalId' . rawurlencode(' eq \'' . $externalappid . '\'');
@@ -1914,7 +1916,7 @@ public function get_catalog_app_id(string $externalappid) : ?string {
* @return string|null
* @throws moodle_exception
*/
- public function get_general_channel_id(string $groupobjectid) : ?string {
+ public function get_general_channel_id(string $groupobjectid): ?string {
$generalchannelid = null;
$endpoint = '/teams/' . $groupobjectid . '/channels?$filter=displayName' . rawurlencode(' eq \'General\'');
@@ -1938,7 +1940,7 @@ public function get_general_channel_id(string $groupobjectid) : ?string {
* @param array $tabconfiguration
* @return string
*/
- public function add_tab_to_channel(string $groupobjectid, string $channelid, string $appid, array $tabconfiguration) : string {
+ public function add_tab_to_channel(string $groupobjectid, string $channelid, string $appid, array $tabconfiguration): string {
$endpoint = '/teams/' . $groupobjectid . '/channels/' . $channelid . '/tabs';
$tabname = get_config('local_o365', 'teams_moodle_tab_name');
if (!$tabname) {
@@ -1946,7 +1948,8 @@ public function add_tab_to_channel(string $groupobjectid, string $channelid, str
}
$requestparams = ['displayName' => $tabname,
'teamsApp@odata.bind' => $this->get_apiuri() . '/beta/appCatalogs/teamsApps/' . $appid,
- 'configuration' => $tabconfiguration,];
+ 'configuration' => $tabconfiguration,
+ ];
return $this->betaapicall('post', $endpoint, json_encode($requestparams));
}
@@ -1958,10 +1961,10 @@ public function add_tab_to_channel(string $groupobjectid, string $channelid, str
* @param string $displayname
* @return string
*/
- public function update_team_name(string $objectid, string $displayname) : string {
+ public function update_team_name(string $objectid, string $displayname): string {
$endpoint = '/teams/' . $objectid;
- $teamdata = ['displayName' => $displayname,];
+ $teamdata = ['displayName' => $displayname];
return $this->betaapicall('patch', $endpoint, json_encode($teamdata));
}
@@ -2007,7 +2010,7 @@ public function get_timezone(string $upn) {
* @return array|null
* @throws moodle_exception
*/
- public function get_teams() : ?array {
+ public function get_teams(): ?array {
$endpoint = '/groups';
$odataqueries = [
'$filter' => 'resourceProvisioningOptions/Any(x:x%20eq%20\'Team\')',
@@ -2022,7 +2025,7 @@ public function get_teams() : ?array {
* @return array
* @throws moodle_exception
*/
- public function get_schools() : ?array {
+ public function get_schools(): ?array {
$endpoint = '/education/schools';
return $this->paginatedapicall('get', $endpoint);
@@ -2035,7 +2038,7 @@ public function get_schools() : ?array {
* @return array
* @throws moodle_exception
*/
- public function get_school_classes(string $schoolobjectid) : ?array {
+ public function get_school_classes(string $schoolobjectid): ?array {
$endpoint = '/education/schools/' . $schoolobjectid . '/classes';
return $this->paginatedapicall('get', $endpoint);
@@ -2048,7 +2051,7 @@ public function get_school_classes(string $schoolobjectid) : ?array {
* @return array
* @throws moodle_exception
*/
- public function get_school_class_teachers(string $classobjectid) : ?array {
+ public function get_school_class_teachers(string $classobjectid): ?array {
$endpoint = '/education/classes/' . $classobjectid . '/teachers';
return $this->paginatedapicall('get', $endpoint);
@@ -2061,7 +2064,7 @@ public function get_school_class_teachers(string $classobjectid) : ?array {
* @return array|null
* @throws moodle_exception
*/
- public function get_school_class_members(string $classobjectid) : ?array {
+ public function get_school_class_members(string $classobjectid): ?array {
$endpoint = '/education/classes/' . $classobjectid . '/members';
return $this->paginatedapicall('get', $endpoint);
@@ -2074,7 +2077,7 @@ public function get_school_class_members(string $classobjectid) : ?array {
* @return array
* @throws moodle_exception
*/
- public function get_school_users(string $schoolobjectid) : ?array {
+ public function get_school_users(string $schoolobjectid): ?array {
$endpoint = '/education/schools/' . $schoolobjectid . '/users';
return $this->paginatedapicall('get', $endpoint);
@@ -2085,7 +2088,7 @@ public function get_school_users(string $schoolobjectid) : ?array {
*
* @return bool
*/
- public function has_education_license() : bool {
+ public function has_education_license(): bool {
$endpoint = '/organization';
$odataqueries = [];
$odataqueries[] = '$select=assignedPlans';
@@ -2123,7 +2126,7 @@ public function has_education_license() : bool {
* @throws moodle_exception
*/
public function create_educationclass_group(string $displayname, string $mailnickname, string $description, string $externalid,
- string $externalname) : ?array {
+ string $externalname): ?array {
if (!empty($mailnickname)) {
$mailnickname = core_text::strtolower($mailnickname);
$mailnickname = preg_replace('/[^a-z0-9_]+/iu', '', $mailnickname);
@@ -2198,7 +2201,7 @@ public function update_education_group_with_lms_data(string $groupobjectid, arra
* @return bool
* @throws moodle_exception
*/
- public function add_chunk_users_to_group(string $groupobjectid, string $role, array $userobjectids) : bool {
+ public function add_chunk_users_to_group(string $groupobjectid, string $role, array $userobjectids): bool {
$endpoint = '/groups/' . $groupobjectid;
if ($role == 'owner') {
@@ -2279,7 +2282,7 @@ public function create_standard_team_from_group(string $groupobjectid) {
* @param array $expectedhttpcodes
* @return bool
*/
- private function check_expected_http_code(array $expectedhttpcodes) : bool {
+ private function check_expected_http_code(array $expectedhttpcodes): bool {
$httpclientinfo = (array) $this->httpclient->info;
return in_array($httpclientinfo['http_code'], $expectedhttpcodes);
diff --git a/local/o365/classes/task/cohortsync.php b/local/o365/classes/task/cohortsync.php
index 847f81d17..46faf5ae3 100644
--- a/local/o365/classes/task/cohortsync.php
+++ b/local/o365/classes/task/cohortsync.php
@@ -25,8 +25,6 @@
namespace local_o365\task;
-defined('MOODLE_INTERNAL') || die();
-
use core\task\scheduled_task;
use local_o365\feature\cohortsync\main;
use local_o365\utils;
@@ -40,7 +38,7 @@ class cohortsync extends scheduled_task {
*
* @return string
*/
- public function get_name() : string {
+ public function get_name(): string {
return get_string('cohortsync_taskname', 'local_o365');
}
@@ -49,7 +47,7 @@ public function get_name() : string {
*
* @return bool
*/
- public function execute() : bool {
+ public function execute(): bool {
$graphclient = main::get_unified_api(__METHOD__);
if (empty($graphclient)) {
utils::mtrace("Failed to get Graph API client. Exiting.", 1);
@@ -69,7 +67,7 @@ public function execute() : bool {
* @param main $cohortsync
* @return void
*/
- private function execute_sync(main $cohortsync) : void {
+ private function execute_sync(main $cohortsync): void {
if ($cohortsync->update_groups_cache()) {
utils::clean_up_not_found_groups();
} else {
diff --git a/local/o365/classes/task/coursemembershipsync.php b/local/o365/classes/task/coursemembershipsync.php
index 3a4875b46..fd45990ab 100644
--- a/local/o365/classes/task/coursemembershipsync.php
+++ b/local/o365/classes/task/coursemembershipsync.php
@@ -45,7 +45,7 @@ class coursemembershipsync extends scheduled_task {
*
* @return string
*/
- public function get_name() : string {
+ public function get_name(): string {
return get_string('task_coursemembershipsync', 'local_o365');
}
@@ -54,7 +54,7 @@ public function get_name() : string {
*
* @return bool
*/
- public function execute() : bool {
+ public function execute(): bool {
// If the sync direction is Moodle to Teams, we don't want to sync the course membership.
$courseusersyncdirection = get_config('local_o365', 'courseusersyncdirection');
if ($courseusersyncdirection == COURSE_USER_SYNC_DIRECTION_MOODLE_TO_TEAMS) {
diff --git a/local/o365/classes/task/coursesync.php b/local/o365/classes/task/coursesync.php
index 59b50271a..9387c27a0 100644
--- a/local/o365/classes/task/coursesync.php
+++ b/local/o365/classes/task/coursesync.php
@@ -25,16 +25,15 @@
namespace local_o365\task;
+use core\task\scheduled_task;
use local_o365\feature\coursesync\main;
use local_o365\utils;
use moodle_exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Create any needed groups in Microsoft 365.
*/
-class coursesync extends \core\task\scheduled_task {
+class coursesync extends scheduled_task {
/**
* Get a descriptive name for this task (shown to admins).
*
diff --git a/local/o365/classes/task/groupmembershipsync.php b/local/o365/classes/task/groupmembershipsync.php
index 4908c94ad..df5e6bd7a 100644
--- a/local/o365/classes/task/groupmembershipsync.php
+++ b/local/o365/classes/task/groupmembershipsync.php
@@ -67,4 +67,4 @@ public function execute() {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/local/o365/classes/task/notifysecretexpiry.php b/local/o365/classes/task/notifysecretexpiry.php
index e33d364bc..ebf4b8b79 100644
--- a/local/o365/classes/task/notifysecretexpiry.php
+++ b/local/o365/classes/task/notifysecretexpiry.php
@@ -34,13 +34,16 @@
require_once($CFG->dirroot . '/auth/oidc/lib.php');
+/**
+ * Notify secret expiry task.
+ */
class notifysecretexpiry extends scheduled_task {
/**
* Return a descriptive name of the task.
*
* @return string
*/
- public function get_name() : string {
+ public function get_name(): string {
return get_string('task_notifysecretexpiry', 'local_o365');
}
@@ -49,7 +52,7 @@ public function get_name() : string {
*
* @return bool
*/
- public function execute() : bool {
+ public function execute(): bool {
if (utils::is_connected() !== true) {
return false;
}
@@ -139,7 +142,7 @@ public function execute() : bool {
*
* @return array
*/
- private function get_notification_recipient_emails_from_configuration() : array {
+ private function get_notification_recipient_emails_from_configuration(): array {
$recipientemails = [];
$recipientssetting = get_config('auth_oidc', 'secretexpiryrecipients');
@@ -161,7 +164,7 @@ private function get_notification_recipient_emails_from_configuration() : array
*
* @return array
*/
- private function get_notification_recipients() : array {
+ private function get_notification_recipients(): array {
$notificationrecipients = [];
$recipientemails = $this->get_notification_recipient_emails_from_configuration();
diff --git a/local/o365/classes/task/processcourserequestapproval.php b/local/o365/classes/task/processcourserequestapproval.php
index 13936f7e7..093a99466 100644
--- a/local/o365/classes/task/processcourserequestapproval.php
+++ b/local/o365/classes/task/processcourserequestapproval.php
@@ -25,8 +25,6 @@
namespace local_o365\task;
-defined('MOODLE_INTERNAL') || die();
-
use core\task\adhoc_task;
use local_o365\feature\courserequest\main;
use local_o365\feature\coursesync\utils;
@@ -40,10 +38,9 @@ class processcourserequestapproval extends adhoc_task {
/**
* Execute the task.
*
- * @return void
- * @throws moodle_exception
+ * @return bool
*/
- public function execute() : bool {
+ public function execute(): bool {
global $DB;
$coursedata = $this->get_custom_data();
diff --git a/local/o365/classes/task/processmatchqueue.php b/local/o365/classes/task/processmatchqueue.php
index 0c97f403d..0a65d25c1 100644
--- a/local/o365/classes/task/processmatchqueue.php
+++ b/local/o365/classes/task/processmatchqueue.php
@@ -51,7 +51,7 @@ class processmatchqueue extends scheduled_task {
*
* @return string
*/
- public function get_name() : string {
+ public function get_name(): string {
return get_string('task_processmatchqueue', 'local_o365');
}
@@ -79,7 +79,7 @@ public function get_api() {
/**
* Do the job.
*/
- public function execute() : bool {
+ public function execute(): bool {
global $DB;
if (utils::is_connected() !== true) {
diff --git a/local/o365/classes/task/updatecourserequeststatus.php b/local/o365/classes/task/updatecourserequeststatus.php
index fc14af504..57337cbcd 100644
--- a/local/o365/classes/task/updatecourserequeststatus.php
+++ b/local/o365/classes/task/updatecourserequeststatus.php
@@ -25,8 +25,6 @@
namespace local_o365\task;
-defined('MOODLE_INTERNAL') || die();
-
use core\task\scheduled_task;
use local_o365\feature\courserequest\main;
diff --git a/local/o365/classes/task/usersync.php b/local/o365/classes/task/usersync.php
index 019635834..6195dce5e 100644
--- a/local/o365/classes/task/usersync.php
+++ b/local/o365/classes/task/usersync.php
@@ -31,8 +31,6 @@
use local_o365\utils;
use moodle_exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Scheduled task to sync users with Microsoft Entra ID.
*/
@@ -178,7 +176,7 @@ public function execute() {
if (!$suspensiontaskhour) {
$suspensiontaskhour = 0;
}
- if(!$suspensiontaskminute) {
+ if (!$suspensiontaskminute) {
$suspensiontaskminute = 0;
}
$currenthour = date('H');
@@ -186,13 +184,15 @@ public function execute() {
if ($currenthour > $suspensiontaskhour) {
$existingtaskusersynclastdeletesetting = get_config('local_o365', 'task_usersync_lastdelete');
if ($existingtaskusersynclastdeletesetting != date('Ymd')) {
- add_to_config_log('task_usersync_lastdelete', $existingtaskusersynclastdeletesetting, date('Ymd'), 'local_o365');
+ add_to_config_log('task_usersync_lastdelete', $existingtaskusersynclastdeletesetting, date('Ymd'),
+ 'local_o365');
}
set_config('task_usersync_lastdelete', date('Ymd'), 'local_o365');
} else if (($currenthour == $suspensiontaskhour) && ($currentminute >= $suspensiontaskminute)) {
$existingtaskusersynclastdeletesetting = get_config('local_o365', 'task_usersync_lastdelete');
if ($existingtaskusersynclastdeletesetting != date('Ymd')) {
- add_to_config_log('task_usersync_lastdelete', $existingtaskusersynclastdeletesetting, date('Ymd'), 'local_o365');
+ add_to_config_log('task_usersync_lastdelete', $existingtaskusersynclastdeletesetting, date('Ymd'),
+ 'local_o365');
}
set_config('task_usersync_lastdelete', date('Ymd'), 'local_o365');
} else {
@@ -276,7 +276,8 @@ protected function sync_users($usersync, $users) {
case 'sub':
case 'preferred_username':
default:
- $this->mtrace('Unsupported binding username claim: ' . $bindingusernameclaim . '. Falls back to userPrincepalName.');
+ $this->mtrace('Unsupported binding username claim: ' . $bindingusernameclaim .
+ '. Falls back to userPrincepalName.');
$bindingusernameclaim = 'userPrincipalName';
}
diff --git a/local/o365/classes/tests/mockhttpclient.php b/local/o365/classes/tests/mockhttpclient.php
index 1275de8a5..1f2f1943e 100644
--- a/local/o365/classes/tests/mockhttpclient.php
+++ b/local/o365/classes/tests/mockhttpclient.php
@@ -27,8 +27,6 @@
use moodle_exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* A mock HTTP client allowing set responses.
*
@@ -84,7 +82,7 @@ public function set_responses(array $responses) {
* @return string The set response.
* @throws moodle_exception If no responses are available.
*/
- protected function request($url, $options = array()) {
+ protected function request($url, $options = []) {
$this->requests[] = [
'url' => $url,
'options' => $options,
diff --git a/local/o365/classes/utils.php b/local/o365/classes/utils.php
index 53f4c474f..6bfe854ef 100644
--- a/local/o365/classes/utils.php
+++ b/local/o365/classes/utils.php
@@ -45,6 +45,9 @@
* General purpose utility class.
*/
class utils {
+ /**
+ * @var string RESOURCE_NOT_EXIST_ERROR
+ */
const RESOURCE_NOT_EXIST_ERROR = 'does not exist or one of its queried reference-property objects are not present';
/**
@@ -76,7 +79,7 @@ public static function is_connected() {
$clientdata = clientdata::instance_from_oidc();
$graphresource = unified::get_tokenresource();
try {
- $token = utils::get_application_token($graphresource, $clientdata, $httpclient);
+ $token = static::get_application_token($graphresource, $clientdata, $httpclient);
if ($token) {
return true;
}
@@ -158,7 +161,7 @@ public static function is_configured_apponlyaccess() {
*
* @return bool Whether app-only access is active.
*/
- public static function is_active_apponlyaccess() : bool {
+ public static function is_active_apponlyaccess(): bool {
return static::is_configured_apponlyaccess() === true && unified::is_configured() === true;
}
@@ -250,9 +253,9 @@ public static function tostring($val) {
$valinfo['errorcode'] = $val->errorcode;
$valinfo['module'] = $val->module;
}
- return print_r($valinfo, true);
+ return json_encode($valinfo, JSON_PRETTY_PRINT);
} else {
- return print_r($val, true);
+ return json_encode($val, JSON_PRETTY_PRINT);
}
}
@@ -287,7 +290,7 @@ public static function debug($message, $where = '', $debugdata = null) {
* @return unified A constructed unified API client, or throw an error.
* @throws moodle_exception
*/
- public static function get_api(int $userid = null) {
+ public static function get_api(?int $userid = null) {
$tokenresource = unified::get_tokenresource();
$clientdata = clientdata::instance_from_oidc();
$httpclient = new httpclient();
@@ -466,10 +469,10 @@ public static function disableadditionaltenant(string $tenantid) {
/**
* Delete an additional tenant from the legacy additional tenant settings.
*
- * @param $tenant
+ * @param string $tenant
* @return bool|void
*/
- public static function deletelegacyadditionaltenant($tenant) {
+ public static function deletelegacyadditionaltenant(string $tenant) {
$o365config = get_config('local_o365');
if (empty($o365config->legacymultitenants)) {
return true;
@@ -493,7 +496,7 @@ public static function deletelegacyadditionaltenant($tenant) {
* @param int $userid The ID of the user.
* @return string The tenant for the user. Empty string unless different from the host tenant.
*/
- public static function get_tenant_for_user(int $userid) : string {
+ public static function get_tenant_for_user(int $userid): string {
try {
$clientdata = clientdata::instance_from_oidc();
$httpclient = new httpclient();
@@ -506,7 +509,7 @@ public static function get_tenant_for_user(int $userid) : string {
return ($tenant != get_config('local_o365', 'entratenant')) ? $tenant : '';
}
} catch (moodle_exception $e) {
- // Do nothing.
+ return '';
}
return '';
}
@@ -530,7 +533,7 @@ public static function get_odburl_for_user($userid) {
return ($tenant != get_config('local_o365', 'odburl')) ? $tenant : '';
}
} catch (moodle_exception $e) {
- // Do nothing.
+ return '';
}
return '';
}
@@ -554,7 +557,7 @@ public static function get_microsoft_account_oid_by_user_id(int $userid) {
*
* @return array
*/
- public static function get_connected_users() : array {
+ public static function get_connected_users(): array {
global $DB;
$connectedusers = [];
@@ -574,7 +577,7 @@ public static function get_connected_users() : array {
* @param int $baselevel
* @return bool
*/
- public static function update_groups_cache(unified $graphclient, int $baselevel = 0) : bool {
+ public static function update_groups_cache(unified $graphclient, int $baselevel = 0): bool {
global $DB;
static::mtrace("Update groups cache.", $baselevel);
@@ -646,7 +649,7 @@ public static function update_groups_cache(unified $graphclient, int $baselevel
* @param int $baselevel
* @return void
*/
- public static function clean_up_not_found_groups(int $baselevel = 1) : void {
+ public static function clean_up_not_found_groups(int $baselevel = 1): void {
global $DB;
static::mtrace('Clean up non-existing groups from database', $baselevel);
@@ -677,7 +680,7 @@ public static function clean_up_not_found_groups(int $baselevel = 1) : void {
* @param string $eol
* @return void
*/
- public static function mtrace(string $message, int $level = 0, string $eol = "\n") {
+ public static function mtrace(string $message, int $level = 0, string $eol = "\n"): void {
if ($level) {
$message = str_repeat('...', $level) . ' ' . $message;
}
@@ -690,7 +693,7 @@ public static function mtrace(string $message, int $level = 0, string $eol = "\n
* @param string $errormessage
* @return string|null
*/
- public static function extract_guid_from_error_message(string $errormessage) : ?string {
+ public static function extract_guid_from_error_message(string $errormessage): ?string {
$pattern = '/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/';
preg_match($pattern, $errormessage, $matches);
return $matches[0] ?? null;
diff --git a/local/o365/classes/webservices/create_onenoteassignment.php b/local/o365/classes/webservices/create_onenoteassignment.php
index de1de3906..be208dca3 100644
--- a/local/o365/classes/webservices/create_onenoteassignment.php
+++ b/local/o365/classes/webservices/create_onenoteassignment.php
@@ -54,7 +54,7 @@ public static function assignment_create_parameters() {
'section' => new external_value(PARAM_INT, 'section', VALUE_DEFAULT, 0),
'visible' => new external_value(PARAM_BOOL, 'visible', VALUE_DEFAULT, false),
'duedate' => new external_value(PARAM_INT, 'duedate', VALUE_DEFAULT, 0),
- ])
+ ]),
]);
}
@@ -81,7 +81,6 @@ public static function assignment_create($data) {
'duedate' => 0,
'cutoffdate' => 0,
'allowsubmissionsfromdate' => 0,
- 'grade' => 0,
'gradingduedate' => 0,
'completionsubmit' => 0,
'teamsubmission' => 0,
diff --git a/local/o365/classes/webservices/delete_onenoteassignment.php b/local/o365/classes/webservices/delete_onenoteassignment.php
index 7e7ebef6d..3c6546b5e 100644
--- a/local/o365/classes/webservices/delete_onenoteassignment.php
+++ b/local/o365/classes/webservices/delete_onenoteassignment.php
@@ -50,7 +50,7 @@ public static function assignment_delete_parameters() {
'data' => new external_single_structure([
'coursemodule' => new external_value(PARAM_INT, 'course module id'),
'course' => new external_value(PARAM_INT, 'course id'),
- ])
+ ]),
]);
}
diff --git a/local/o365/classes/webservices/exception/assignnotfound.php b/local/o365/classes/webservices/exception/assignnotfound.php
index 353ebf306..8237e3fa1 100644
--- a/local/o365/classes/webservices/exception/assignnotfound.php
+++ b/local/o365/classes/webservices/exception/assignnotfound.php
@@ -25,8 +25,6 @@
namespace local_o365\webservices\exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Exception thrown when an associated assignment record is not found for a given course module.
*/
diff --git a/local/o365/classes/webservices/exception/couldnotsavegrade.php b/local/o365/classes/webservices/exception/couldnotsavegrade.php
index dd6ff24c4..16f85c17d 100644
--- a/local/o365/classes/webservices/exception/couldnotsavegrade.php
+++ b/local/o365/classes/webservices/exception/couldnotsavegrade.php
@@ -25,8 +25,6 @@
namespace local_o365\webservices\exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Exception thrown when a grade could not be saved in local_o365_update_grade.
*/
diff --git a/local/o365/classes/webservices/exception/invalidassignment.php b/local/o365/classes/webservices/exception/invalidassignment.php
index 5864d35ff..83e938ef4 100644
--- a/local/o365/classes/webservices/exception/invalidassignment.php
+++ b/local/o365/classes/webservices/exception/invalidassignment.php
@@ -25,8 +25,6 @@
namespace local_o365\webservices\exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Exception thrown when a module is called that is not a OneNote assignment.
*/
diff --git a/local/o365/classes/webservices/exception/modulenotfound.php b/local/o365/classes/webservices/exception/modulenotfound.php
index c6d9e045f..cbe6829ca 100644
--- a/local/o365/classes/webservices/exception/modulenotfound.php
+++ b/local/o365/classes/webservices/exception/modulenotfound.php
@@ -25,8 +25,6 @@
namespace local_o365\webservices\exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Exception thrown when a module that does not exist is called.
*/
diff --git a/local/o365/classes/webservices/exception/sectionnotfound.php b/local/o365/classes/webservices/exception/sectionnotfound.php
index aa493ef69..10be9e256 100644
--- a/local/o365/classes/webservices/exception/sectionnotfound.php
+++ b/local/o365/classes/webservices/exception/sectionnotfound.php
@@ -25,8 +25,6 @@
namespace local_o365\webservices\exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Exception thrown when a course section that does not exist is used to update an assignment.
*/
diff --git a/local/o365/classes/webservices/read_assignments.php b/local/o365/classes/webservices/read_assignments.php
index 0a546d028..9bbd154ab 100644
--- a/local/o365/classes/webservices/read_assignments.php
+++ b/local/o365/classes/webservices/read_assignments.php
@@ -80,7 +80,7 @@ public static function assignments_read_parameters() {
'courseids to not be empty.',
VALUE_DEFAULT,
false
- )
+ ),
]);
}
@@ -94,26 +94,26 @@ public static function assignments_read_parameters() {
* @param array $capabilities An array of additional capability checks you wish to be made on the course context.
* @param bool $includenotenrolledcourses Wheter to return courses that the user can see even if is not enroled in.
* This requires the parameter $courseids to not be empty.
- * @return An array of courses and warnings.
+ * @return array An array of courses and warnings.
* @since Moodle 2.4
*/
public static function assignments_read($courseids = [], $assignmentids = [], $capabilities = [],
$includenotenrolledcourses = false) {
- global $USER, $DB, $CFG;
+ global $USER, $DB;
$params = self::validate_parameters(
self::assignments_read_parameters(),
- array(
+ [
'courseids' => $courseids,
'assignmentids' => $assignmentids,
'capabilities' => $capabilities,
- 'includenotenrolledcourses' => $includenotenrolledcourses
- )
+ 'includenotenrolledcourses' => $includenotenrolledcourses,
+ ]
);
$assignmentids = array_flip($params['assignmentids']);
- $warnings = array();
- $courses = array();
+ $warnings = [];
+ $courses = [];
$fields = 'sortorder,shortname,fullname,timemodified';
// If the courseids list is empty, we return only the courses where the user is enrolled in.
@@ -131,12 +131,12 @@ public static function assignments_read($courseids = [], $assignmentids = [], $c
foreach ($params['courseids'] as $courseid) {
if (!in_array($courseid, $mycourseids)) {
unset($courses[$courseid]);
- $warnings[] = array(
+ $warnings[] = [
'item' => 'course',
'itemid' => $courseid,
'warningcode' => '2',
- 'message' => 'User is not enrolled or does not have requested capability'
- );
+ 'message' => 'User is not enrolled or does not have requested capability',
+ ];
} else {
$courses[$courseid] = $mycourses[$courseid];
}
@@ -156,12 +156,12 @@ public static function assignments_read($courseids = [], $assignmentids = [], $c
}
} catch (moodle_exception $e) {
unset($courses[$cid]);
- $warnings[] = array(
+ $warnings[] = [
'item' => 'course',
'itemid' => $cid,
'warningcode' => '1',
- 'message' => 'No access rights in course context ' . $e->getMessage()
- );
+ 'message' => 'No access rights in course context ' . $e->getMessage(),
+ ];
continue;
}
if (count($params['capabilities']) > 0 && !has_all_capabilities($params['capabilities'], $context)) {
@@ -193,10 +193,10 @@ public static function assignments_read($courseids = [], $assignmentids = [], $c
'm.requiresubmissionstatement, '.
'm.intro, '.
'm.introformat';
- $coursearray = array();
+ $coursearray = [];
foreach ($courses as $id => $course) {
- $assignmentarray = array();
+ $assignmentarray = [];
// Get a list of assignments for the course.
if ($modules = get_coursemodules_in_course('assign', $courses[$id]->id, $extrafields)) {
foreach ($modules as $module) {
@@ -211,29 +211,29 @@ public static function assignments_read($courseids = [], $assignmentids = [], $c
self::validate_context($context);
require_capability('mod/assign:view', $context);
} catch (moodle_exception $e) {
- $warnings[] = array(
+ $warnings[] = [
'item' => 'module',
'itemid' => $module->id,
'warningcode' => '1',
- 'message' => 'No access rights in module context'
- );
+ 'message' => 'No access rights in module context',
+ ];
continue;
}
- $configrecords = $DB->get_recordset('assign_plugin_config', array('assignment' => $module->assignmentid));
- $configarray = array();
+ $configrecords = $DB->get_recordset('assign_plugin_config', ['assignment' => $module->assignmentid]);
+ $configarray = [];
foreach ($configrecords as $configrecord) {
- $configarray[] = array(
+ $configarray[] = [
'id' => $configrecord->id,
'assignment' => $configrecord->assignment,
'plugin' => $configrecord->plugin,
'subtype' => $configrecord->subtype,
'name' => $configrecord->name,
- 'value' => $configrecord->value
- );
+ 'value' => $configrecord->value,
+ ];
}
$configrecords->close();
- $assignment = array(
+ $assignment = [
'id' => $module->assignmentid,
'cmid' => $module->id,
'course' => $module->course,
@@ -259,8 +259,8 @@ public static function assignments_read($courseids = [], $assignmentids = [], $c
'markingworkflow' => $module->markingworkflow,
'markingallocation' => $module->markingallocation,
'requiresubmissionstatement' => $module->requiresubmissionstatement,
- 'configs' => $configarray
- );
+ 'configs' => $configarray,
+ ];
// Return or not intro and file attachments depending on the plugin settings.
$assign = new \assign($context, null, null);
@@ -272,18 +272,18 @@ public static function assignments_read($courseids = [], $assignmentids = [], $c
$fs = get_file_storage();
if ($files = $fs->get_area_files($context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA,
- 0, 'timemodified', false)) {
+ 0, 'timemodified', false)) {
- $assignment['introattachments'] = array();
+ $assignment['introattachments'] = [];
foreach ($files as $file) {
$filename = $file->get_filename();
- $assignment['introattachments'][] = array(
+ $assignment['introattachments'][] = [
'filename' => $filename,
'mimetype' => $file->get_mimetype(),
- 'fileurl' => \moodle_url::make_webservice_pluginfile_url(
- $context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0, '/', $filename)->out(false)
- );
+ 'fileurl' => \moodle_url::make_webservice_pluginfile_url(
+ $context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0, '/', $filename)->out(false),
+ ];
}
}
}
@@ -291,19 +291,20 @@ public static function assignments_read($courseids = [], $assignmentids = [], $c
$assignmentarray[] = $assignment;
}
}
- $coursearray[] = array(
+ $coursearray[] = [
'id' => $courses[$id]->id,
'fullname' => $courses[$id]->fullname,
'shortname' => $courses[$id]->shortname,
'timemodified' => $courses[$id]->timemodified,
- 'assignments' => $assignmentarray
- );
+ 'assignments' => $assignmentarray,
+ ];
}
- $result = array(
+ $result = [
'courses' => $coursearray,
- 'warnings' => $warnings
- );
+ 'warnings' => $warnings,
+ ];
+
return $result;
}
@@ -315,7 +316,7 @@ public static function assignments_read($courseids = [], $assignmentids = [], $c
*/
private static function get_assignments_assignment_structure() {
return new external_single_structure(
- array(
+ [
'id' => new external_value(PARAM_INT, 'assignment id'),
'cmid' => new external_value(PARAM_INT, 'course module id'),
'course' => new external_value(PARAM_INT, 'course id'),
@@ -347,14 +348,14 @@ private static function get_assignments_assignment_structure() {
'introformat' => new external_format_value('intro', VALUE_OPTIONAL),
'introattachments' => new external_multiple_structure(
new external_single_structure(
- array (
+ [
'filename' => new external_value(PARAM_FILE, 'file name'),
'mimetype' => new external_value(PARAM_RAW, 'mime type'),
- 'fileurl' => new external_value(PARAM_URL, 'file download url')
- )
+ 'fileurl' => new external_value(PARAM_URL, 'file download url'),
+ ]
), 'intro attachments files', VALUE_OPTIONAL
- )
- ), 'assignment information object');
+ ),
+ ], 'assignment information object');
}
/**
@@ -365,14 +366,14 @@ private static function get_assignments_assignment_structure() {
*/
private static function get_assignments_config_structure() {
return new external_single_structure(
- array(
+ [
'id' => new external_value(PARAM_INT, 'assign_plugin_config id'),
'assignment' => new external_value(PARAM_INT, 'assignment id'),
'plugin' => new external_value(PARAM_TEXT, 'plugin'),
'subtype' => new external_value(PARAM_TEXT, 'subtype'),
'name' => new external_value(PARAM_TEXT, 'name'),
- 'value' => new external_value(PARAM_TEXT, 'value')
- ), 'assignment configuration object'
+ 'value' => new external_value(PARAM_TEXT, 'value'),
+ ], 'assignment configuration object'
);
}
@@ -384,13 +385,13 @@ private static function get_assignments_config_structure() {
*/
private static function get_assignments_course_structure() {
return new external_single_structure(
- array(
+ [
'id' => new external_value(PARAM_INT, 'course id'),
'fullname' => new external_value(PARAM_TEXT, 'course full name'),
'shortname' => new external_value(PARAM_TEXT, 'course short name'),
'timemodified' => new external_value(PARAM_INT, 'last time modified'),
- 'assignments' => new external_multiple_structure(self::get_assignments_assignment_structure(), 'assignment info')
- ), 'course information object'
+ 'assignments' => new external_multiple_structure(self::get_assignments_assignment_structure(), 'assignment info'),
+ ], 'course information object'
);
}
@@ -402,12 +403,12 @@ private static function get_assignments_course_structure() {
*/
public static function assignments_read_returns() {
return new external_single_structure(
- array(
+ [
'courses' => new external_multiple_structure(self::get_assignments_course_structure(), 'list of courses'),
- 'warnings' => new external_warnings('item can be \'course\' (errorcode 1 or 2) or \'module\' (errorcode 1)',
+ 'warnings' => new external_warnings('item can be \'course\' (errorcode 1 or 2) or \'module\' (errorcode 1)',
'When item is a course then itemid is a course id. When the item is a module then itemid is a module id',
- 'errorcode can be 1 (no access rights) or 2 (not enrolled or no permissions)')
- )
+ 'errorcode can be 1 (no access rights) or 2 (not enrolled or no permissions)'),
+ ]
);
}
diff --git a/local/o365/classes/webservices/read_courseusers.php b/local/o365/classes/webservices/read_courseusers.php
index 274b95588..3f39b0054 100644
--- a/local/o365/classes/webservices/read_courseusers.php
+++ b/local/o365/classes/webservices/read_courseusers.php
@@ -109,7 +109,7 @@ public static function courseusers_read($courseid, $limitfrom = 0, $limitnumber
$limitnumber = clean_param($limitnumber, PARAM_INT);
if ($courseid == SITEID) {
- // TODO exception.
+ return [];
}
$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
$context = \context_course::instance($courseid);
diff --git a/local/o365/classes/webservices/read_onenoteassignment.php b/local/o365/classes/webservices/read_onenoteassignment.php
index d1d676979..6dfe02fb5 100644
--- a/local/o365/classes/webservices/read_onenoteassignment.php
+++ b/local/o365/classes/webservices/read_onenoteassignment.php
@@ -50,7 +50,7 @@ public static function assignment_read_parameters() {
'data' => new external_single_structure([
'coursemodule' => new external_value(PARAM_INT, 'course module id'),
'course' => new external_value(PARAM_INT, 'course id'),
- ])
+ ]),
]);
}
diff --git a/local/o365/classes/webservices/read_teachercourses.php b/local/o365/classes/webservices/read_teachercourses.php
index 5bc6dfa14..ea3437c8f 100644
--- a/local/o365/classes/webservices/read_teachercourses.php
+++ b/local/o365/classes/webservices/read_teachercourses.php
@@ -73,7 +73,7 @@ public static function teachercourses_read($courseids = []) {
$params = self::validate_parameters(
self::teachercourses_read_parameters(),
[
- 'courseids' => $courseids
+ 'courseids' => $courseids,
]
);
@@ -114,7 +114,7 @@ public static function teachercourses_read($courseids = []) {
'format' => $course->format,
'showgrades' => $course->showgrades,
'lang' => $course->lang,
- 'enablecompletion' => $course->enablecompletion
+ 'enablecompletion' => $course->enablecompletion,
];
}
diff --git a/local/o365/classes/webservices/update_grade.php b/local/o365/classes/webservices/update_grade.php
index 20c6cc0b6..695d8930f 100644
--- a/local/o365/classes/webservices/update_grade.php
+++ b/local/o365/classes/webservices/update_grade.php
@@ -53,7 +53,7 @@ public static function grade_update_parameters() {
global $CFG;
require_once("$CFG->dirroot/grade/grading/lib.php");
$instance = new \assign(null, null, null);
- $pluginfeedbackparams = array();
+ $pluginfeedbackparams = [];
foreach ($instance->get_feedback_plugins() as $plugin) {
if ($plugin->is_visible()) {
@@ -64,21 +64,21 @@ public static function grade_update_parameters() {
}
}
- $advancedgradingdata = array();
+ $advancedgradingdata = [];
$methods = array_keys(\grading_manager::available_methods(false));
foreach ($methods as $method) {
- require_once($CFG->dirroot.'/grade/grading/form/'.$method.'/lib.php');
- $details = call_user_func('gradingform_'.$method.'_controller::get_external_instance_filling_details');
+ require_once($CFG->dirroot . '/grade/grading/form/' . $method . '/lib.php');
+ $details = call_user_func('gradingform_' . $method . '_controller::get_external_instance_filling_details');
if (!empty($details)) {
- $items = array();
+ $items = [];
foreach ($details as $key => $value) {
$value->required = VALUE_OPTIONAL;
unset($value->content->keys['id']);
$items[$key] = new external_multiple_structure (new external_single_structure(
- array(
+ [
'criterionid' => new external_value(PARAM_INT, 'criterion id'),
- 'fillings' => $value
- )
+ 'fillings' => $value,
+ ]
));
}
$advancedgradingdata[$method] = new external_single_structure($items, 'items', VALUE_OPTIONAL);
@@ -86,20 +86,19 @@ public static function grade_update_parameters() {
}
return new external_function_parameters(
- array(
+ [
'assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on'),
'userid' => new external_value(PARAM_INT, 'The student id to operate on'),
'grade' => new external_value(PARAM_FLOAT, 'The new grade for this user. Ignored if advanced grading used'),
'attemptnumber' => new external_value(PARAM_INT, 'The attempt number (-1 means latest attempt)'),
'addattempt' => new external_value(PARAM_BOOL, 'Allow another attempt if the attempt reopen method is manual'),
'workflowstate' => new external_value(PARAM_ALPHA, 'The next marking workflow state'),
- 'applytoall' => new external_value(PARAM_BOOL, 'If true, this grade will be applied ' .
- 'to all members ' .
- 'of the group (for group assignments).'),
- 'plugindata' => new external_single_structure($pluginfeedbackparams, 'plugin data', VALUE_DEFAULT, array()),
+ 'applytoall' => new external_value(PARAM_BOOL, 'If true, this grade will be applied to all members ' .
+ 'of the group (for group assignments).'),
+ 'plugindata' => new external_single_structure($pluginfeedbackparams, 'plugin data', VALUE_DEFAULT, []),
'advancedgradingdata' => new external_single_structure($advancedgradingdata, 'advanced grading data',
- VALUE_DEFAULT, array())
- )
+ VALUE_DEFAULT, []),
+ ]
);
}
@@ -119,27 +118,14 @@ public static function grade_update_parameters() {
* @throws exception\couldnotsavegrade
* @since Moodle 2.6
*/
- public static function grade_update($assignmentid,
- $userid,
- $grade,
- $attemptnumber,
- $addattempt,
- $workflowstate,
- $applytoall,
- $plugindata = array(),
- $advancedgradingdata = array()) {
- global $CFG, $USER, $DB;
-
- $params = self::validate_parameters(self::grade_update_parameters(),
- array('assignmentid' => $assignmentid,
- 'userid' => $userid,
- 'grade' => $grade,
- 'attemptnumber' => $attemptnumber,
- 'workflowstate' => $workflowstate,
- 'addattempt' => $addattempt,
- 'applytoall' => $applytoall,
- 'plugindata' => $plugindata,
- 'advancedgradingdata' => $advancedgradingdata));
+ public static function grade_update($assignmentid, $userid, $grade, $attemptnumber, $addattempt, $workflowstate, $applytoall,
+ $plugindata = [], $advancedgradingdata = []) {
+ global $DB;
+
+ $params = self::validate_parameters(self::grade_update_parameters(), ['assignmentid' => $assignmentid,
+ 'userid' => $userid, 'grade' => $grade, 'attemptnumber' => $attemptnumber, 'workflowstate' => $workflowstate,
+ 'addattempt' => $addattempt, 'applytoall' => $applytoall, 'plugindata' => $plugindata,
+ 'advancedgradingdata' => $advancedgradingdata]);
$cm = get_coursemodule_from_instance('assign', $params['assignmentid'], 0, false, MUST_EXIST);
$context = \context_module::instance($cm->id);
@@ -156,10 +142,10 @@ public static function grade_update($assignmentid,
$gradedata->grade = $params['grade'];
if (!empty($params['advancedgradingdata'])) {
- $advancedgrading = array();
+ $advancedgrading = [];
$criteria = reset($params['advancedgradingdata']);
foreach ($criteria as $key => $criterion) {
- $details = array();
+ $details = [];
foreach ($criterion as $value) {
foreach ($value['fillings'] as $filling) {
$details[$value['criterionid']] = $filling;
@@ -186,7 +172,7 @@ public static function grade_update($assignmentid,
return [
'id' => $graderec->id,
- 'itemid' => $graderec->itemid
+ 'itemid' => $graderec->itemid,
];
}
diff --git a/local/o365/classes/webservices/update_onenoteassignment.php b/local/o365/classes/webservices/update_onenoteassignment.php
index 0b322996d..d44bd0f62 100644
--- a/local/o365/classes/webservices/update_onenoteassignment.php
+++ b/local/o365/classes/webservices/update_onenoteassignment.php
@@ -55,7 +55,7 @@ public static function assignment_update_parameters() {
'intro' => new external_value(PARAM_TEXT, 'intro', VALUE_DEFAULT, null),
'section' => new external_value(PARAM_INT, 'section', VALUE_DEFAULT, null),
'visible' => new external_value(PARAM_BOOL, 'visible', VALUE_DEFAULT, null),
- ])
+ ]),
]);
}
diff --git a/local/o365/classes/webservices/utils.php b/local/o365/classes/webservices/utils.php
index 7eb061611..f9f2333c9 100644
--- a/local/o365/classes/webservices/utils.php
+++ b/local/o365/classes/webservices/utils.php
@@ -28,11 +28,9 @@
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
-use \local_o365\webservices\exception as exception;
+use local_o365\webservices\exception as exception;
use moodle_exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Webservices utilities.
*/
diff --git a/local/o365/db/access.php b/local/o365/db/access.php
index 2363818ec..92b7cb7a7 100644
--- a/local/o365/db/access.php
+++ b/local/o365/db/access.php
@@ -32,7 +32,7 @@
'contextlevel' => CONTEXT_COURSE,
'archetypes' => [
'editingteacher' => CAP_ALLOW,
- 'manager' => CAP_ALLOW
+ 'manager' => CAP_ALLOW,
],
],
'local/o365:viewgroups' => [
diff --git a/local/o365/db/caches.php b/local/o365/db/caches.php
index 22f161420..e22d27bb1 100644
--- a/local/o365/db/caches.php
+++ b/local/o365/db/caches.php
@@ -27,6 +27,6 @@
$definitions = [
'groups' => [
- 'mode' => cache_store::MODE_SESSION
+ 'mode' => cache_store::MODE_SESSION,
],
];
diff --git a/local/o365/db/services.php b/local/o365/db/services.php
index 4aad3b421..4836c2b84 100644
--- a/local/o365/db/services.php
+++ b/local/o365/db/services.php
@@ -103,5 +103,5 @@
'restrictedusers' => 0,
'enabled' => 0,
'shortname' => 'o365_webservices',
- ]
+ ],
];
diff --git a/local/o365/db/tasks.php b/local/o365/db/tasks.php
index 57e4bb2eb..5714a487c 100644
--- a/local/o365/db/tasks.php
+++ b/local/o365/db/tasks.php
@@ -33,7 +33,7 @@
'hour' => '1',
'day' => '*',
'dayofweek' => '*',
- 'month' => '*'
+ 'month' => '*',
],
[
'classname' => 'local_o365\task\coursesync',
@@ -42,7 +42,7 @@
'hour' => '*',
'day' => '*',
'dayofweek' => '*',
- 'month' => '*'
+ 'month' => '*',
],
[
'classname' => 'local_o365\feature\calsync\task\importfromoutlook',
@@ -51,7 +51,7 @@
'hour' => '*',
'day' => '*',
'dayofweek' => '*',
- 'month' => '*'
+ 'month' => '*',
],
[
'classname' => 'local_o365\task\processmatchqueue',
@@ -60,7 +60,7 @@
'hour' => '*',
'day' => '*',
'dayofweek' => '*',
- 'month' => '*'
+ 'month' => '*',
],
[
'classname' => 'local_o365\feature\sds\task\sync',
@@ -69,7 +69,7 @@
'hour' => '3',
'day' => '*',
'dayofweek' => '*',
- 'month' => '*'
+ 'month' => '*',
],
[
'classname' => 'local_o365\task\notifysecretexpiry',
@@ -87,7 +87,7 @@
'hour' => '*',
'day' => '*',
'dayofweek' => '*',
- 'month' => '*'
+ 'month' => '*',
],
[
'classname' => 'local_o365\task\updatecourserequeststatus',
@@ -96,7 +96,7 @@
'hour' => '*',
'day' => '*',
'dayofweek' => '*',
- 'month' => '*'
+ 'month' => '*',
],
[
'classname' => 'local_o365\task\coursemembershipsync',
diff --git a/local/o365/db/upgrade.php b/local/o365/db/upgrade.php
index 312287442..939e1697c 100644
--- a/local/o365/db/upgrade.php
+++ b/local/o365/db/upgrade.php
@@ -46,7 +46,7 @@ function xmldb_local_o365_upgrade($oldversion) {
if (!$dbman->table_exists('local_o365_token')) {
$dbman->install_one_table_from_xmldb_file(__DIR__.'/install.xml', 'local_o365_token');
}
- upgrade_plugin_savepoint(true, '2014111700', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2014111700, 'local', 'o365');
}
if ($oldversion < 2014111702) {
@@ -56,21 +56,21 @@ function xmldb_local_o365_upgrade($oldversion) {
if (!$dbman->table_exists('local_o365_calidmap')) {
$dbman->install_one_table_from_xmldb_file(__DIR__.'/install.xml', 'local_o365_calidmap');
}
- upgrade_plugin_savepoint(true, '2014111702', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2014111702, 'local', 'o365');
}
if ($oldversion < 2014111703) {
$table = new xmldb_table('local_o365_calidmap');
$field = new xmldb_field('outlookeventid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'eventid');
$dbman->change_field_type($table, $field);
- upgrade_plugin_savepoint(true, '2014111703', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2014111703, 'local', 'o365');
}
if ($oldversion < 2014111707) {
if (!$dbman->table_exists('local_o365_cronqueue')) {
$dbman->install_one_table_from_xmldb_file(__DIR__.'/install.xml', 'local_o365_cronqueue');
}
- upgrade_plugin_savepoint(true, '2014111707', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2014111707, 'local', 'o365');
}
if ($oldversion < 2014111710) {
@@ -83,7 +83,7 @@ function xmldb_local_o365_upgrade($oldversion) {
if (!$dbman->table_exists('local_o365_aaduserdata')) {
$dbman->install_one_table_from_xmldb_file(__DIR__.'/install.xml', 'local_o365_aaduserdata');
}
- upgrade_plugin_savepoint(true, '2014111710', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2014111710, 'local', 'o365');
}
if ($oldversion < 2014111711) {
@@ -92,14 +92,14 @@ function xmldb_local_o365_upgrade($oldversion) {
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
- upgrade_plugin_savepoint(true, '2014111711', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2014111711, 'local', 'o365');
}
if ($oldversion < 2014111715) {
if (!$dbman->table_exists('local_o365_spgroupassign')) {
$dbman->install_one_table_from_xmldb_file(__DIR__.'/install.xml', 'local_o365_spgroupassign');
}
- upgrade_plugin_savepoint(true, '2014111715', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2014111715, 'local', 'o365');
}
if ($oldversion < 2014111716) {
@@ -122,7 +122,7 @@ function xmldb_local_o365_upgrade($oldversion) {
$dbman->add_index($table, $index);
}
- upgrade_plugin_savepoint(true, '2014111716', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2014111716, 'local', 'o365');
}
if ($oldversion < 2015012702) {
@@ -133,7 +133,7 @@ function xmldb_local_o365_upgrade($oldversion) {
add_to_config_log('sharepointlink', '', $sharepointlink, 'local_o365');
set_config('sharepointlink', $sharepointlink, 'local_o365');
}
- upgrade_plugin_savepoint(true, '2015012702', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015012702, 'local', 'o365');
}
if ($oldversion < 2015012704) {
@@ -150,7 +150,7 @@ function xmldb_local_o365_upgrade($oldversion) {
}
set_config('odburl', $config->tenant.'-my.sharepoint.com', 'local_o365');
}
- upgrade_plugin_savepoint(true, '2015012704', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015012704, 'local', 'o365');
}
if ($oldversion < 2015012707) {
@@ -163,7 +163,7 @@ function xmldb_local_o365_upgrade($oldversion) {
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
- upgrade_plugin_savepoint(true, '2015012707', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015012707, 'local', 'o365');
}
if ($oldversion < 2015012708) {
@@ -184,7 +184,7 @@ function xmldb_local_o365_upgrade($oldversion) {
}
$idmaps->close();
- upgrade_plugin_savepoint(true, '2015012708', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015012708, 'local', 'o365');
}
if ($oldversion < 2015012709) {
@@ -217,7 +217,7 @@ function xmldb_local_o365_upgrade($oldversion) {
}
$idmaps->close();
- upgrade_plugin_savepoint(true, '2015012709', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015012709, 'local', 'o365');
}
if ($oldversion < 2015012710) {
@@ -231,7 +231,7 @@ function xmldb_local_o365_upgrade($oldversion) {
}
}
$calsubs->close();
- upgrade_plugin_savepoint(true, '2015012710', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015012710, 'local', 'o365');
}
if ($oldversion < 2015012712) {
@@ -239,14 +239,14 @@ function xmldb_local_o365_upgrade($oldversion) {
$table = new xmldb_table('local_o365_token');
$field = new xmldb_field('scope', XMLDB_TYPE_TEXT, null, null, null, null, null, 'user_id');
$dbman->change_field_type($table, $field);
- upgrade_plugin_savepoint(true, '2015012712', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015012712, 'local', 'o365');
}
if ($oldversion < 2015012713) {
if (!$dbman->table_exists('local_o365_objects')) {
$dbman->install_one_table_from_xmldb_file(__DIR__.'/install.xml', 'local_o365_objects');
}
- upgrade_plugin_savepoint(true, '2015012713', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015012713, 'local', 'o365');
}
if ($oldversion < 2015012714) {
@@ -255,7 +255,7 @@ function xmldb_local_o365_upgrade($oldversion) {
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
- upgrade_plugin_savepoint(true, '2015012714', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015012714, 'local', 'o365');
}
if ($oldversion < 2015012715) {
@@ -263,7 +263,7 @@ function xmldb_local_o365_upgrade($oldversion) {
$table = new xmldb_table('local_o365_token');
$field = new xmldb_field('scope', XMLDB_TYPE_TEXT, null, null, null, null, null, 'user_id');
$dbman->change_field_type($table, $field);
- upgrade_plugin_savepoint(true, '2015012715', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015012715, 'local', 'o365');
}
if ($oldversion < 2015060102) {
@@ -272,14 +272,14 @@ function xmldb_local_o365_upgrade($oldversion) {
add_to_config_log('aadsync', '1', 'create', 'local_o365');
set_config('aadsync', 'create', 'local_o365');
}
- upgrade_plugin_savepoint(true, '2015060102', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015060102, 'local', 'o365');
}
if ($oldversion < 2015060103) {
if (!$dbman->table_exists('local_o365_connections')) {
$dbman->install_one_table_from_xmldb_file(__DIR__.'/install.xml', 'local_o365_connections');
}
- upgrade_plugin_savepoint(true, '2015060103', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015060103, 'local', 'o365');
}
if ($oldversion < 2015060104) {
@@ -288,7 +288,7 @@ function xmldb_local_o365_upgrade($oldversion) {
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
- upgrade_plugin_savepoint(true, '2015060104', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015060104, 'local', 'o365');
}
if ($oldversion < 2015060109) {
@@ -311,14 +311,14 @@ function xmldb_local_o365_upgrade($oldversion) {
}
}
}
- upgrade_plugin_savepoint(true, '2015060109', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015060109, 'local', 'o365');
}
if ($oldversion < 2015060111) {
// Clean up old "calendarsyncin" task record, if present. Replaced by \local_o365\feature\calsync\task\importfromoutlook.
$conditions = ['component' => 'local_o365', 'classname' => '\local_o365\task\calendarsyncin'];
$DB->delete_records('task_scheduled', $conditions);
- upgrade_plugin_savepoint(true, '2015060111', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015060111, 'local', 'o365');
}
if ($oldversion < 2015111900.01) {
@@ -343,7 +343,7 @@ function xmldb_local_o365_upgrade($oldversion) {
}
}
- upgrade_plugin_savepoint(true, '2015111900.01', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015111900.01, 'local', 'o365');
}
if ($oldversion < 2015111900.02) {
@@ -351,7 +351,7 @@ function xmldb_local_o365_upgrade($oldversion) {
if (!$dbman->table_exists($table)) {
$dbman->install_one_table_from_xmldb_file(__DIR__.'/install.xml', 'local_o365_appassign');
}
- upgrade_plugin_savepoint(true, '2015111900.02', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015111900.02, 'local', 'o365');
}
if ($oldversion < 2015111901.01) {
@@ -359,7 +359,7 @@ function xmldb_local_o365_upgrade($oldversion) {
if (!$dbman->table_exists($table)) {
$dbman->install_one_table_from_xmldb_file(__DIR__.'/install.xml', 'local_o365_matchqueue');
}
- upgrade_plugin_savepoint(true, '2015111901.01', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015111901.01, 'local', 'o365');
}
if ($oldversion < 2015111901.03) {
@@ -378,12 +378,12 @@ function xmldb_local_o365_upgrade($oldversion) {
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
- upgrade_plugin_savepoint(true, '2015111901.03', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015111901.03, 'local', 'o365');
}
if ($oldversion < 2015111903) {
$table = new xmldb_table('local_o365_appassign');
- $index = new xmldb_index('userobjectid', XMLDB_INDEX_UNIQUE, array('userobjectid'));
+ $index = new xmldb_index('userobjectid', XMLDB_INDEX_UNIQUE, ['userobjectid']);
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
@@ -399,17 +399,17 @@ function xmldb_local_o365_upgrade($oldversion) {
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
- upgrade_plugin_savepoint(true, '2015111903', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015111903, 'local', 'o365');
}
if ($oldversion < 2015111905) {
// Delete custom profile fields for data type o365 and oidc which are no longer used.
$fields = $DB->get_records_sql("SELECT * FROM {user_info_field} WHERE datatype IN ('o365', 'oidc')");
foreach ($fields as $field) {
- $DB->delete_records('user_info_data', array('fieldid' => $field->id));
- $DB->delete_records('user_info_field', array('id' => $field->id));
+ $DB->delete_records('user_info_data', ['fieldid' => $field->id]);
+ $DB->delete_records('user_info_field', ['id' => $field->id]);
}
- upgrade_plugin_savepoint(true, '2015111905', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015111905, 'local', 'o365');
}
if ($oldversion < 2015111911.01) {
@@ -419,14 +419,14 @@ function xmldb_local_o365_upgrade($oldversion) {
$field->setNotNull(false);
$dbman->change_field_notnull($table, $field);
}
- upgrade_plugin_savepoint(true, '2015111911.01', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015111911.01, 'local', 'o365');
}
if ($oldversion < 2015111913) {
if (!$dbman->table_exists('local_o365_coursegroupdata')) {
$dbman->install_one_table_from_xmldb_file(__DIR__.'/install.xml', 'local_o365_coursegroupdata');
}
- upgrade_plugin_savepoint(true, '2015111913', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015111913, 'local', 'o365');
}
if ($oldversion < 2015111913.02) {
@@ -438,7 +438,7 @@ function xmldb_local_o365_upgrade($oldversion) {
}
set_config('creategroups', 'onall', 'local_o365');
}
- upgrade_plugin_savepoint(true, '2015111913.02', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015111913.02, 'local', 'o365');
}
if ($oldversion < 2015111914.02) {
@@ -452,7 +452,7 @@ function xmldb_local_o365_upgrade($oldversion) {
}
// O365 savepoint reached.
- upgrade_plugin_savepoint(true, '2015111914.02', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015111914.02, 'local', 'o365');
}
if ($oldversion < 2015111914.03) {
@@ -469,7 +469,7 @@ function xmldb_local_o365_upgrade($oldversion) {
$dbman->drop_index($table, $index);
}
- upgrade_plugin_savepoint(true, '2015111914.03', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015111914.03, 'local', 'o365');
}
if ($oldversion < 2015111916.01) {
@@ -483,7 +483,7 @@ function xmldb_local_o365_upgrade($oldversion) {
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
// Adding keys to table local_o365_calsettings.
- $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+ $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
// Conditionally launch create table for local_o365_calsettings.
if (!$dbman->table_exists($table)) {
@@ -502,13 +502,13 @@ function xmldb_local_o365_upgrade($oldversion) {
$newsetting = [
'user_id' => $USER->id,
'o365calid' => $sitecalendar['Id'],
- 'timecreated' => time()
+ 'timecreated' => time(),
];
$newsetting['id'] = $DB->insert_record('local_o365_calsettings', (object)$newsetting);
}
}
- upgrade_plugin_savepoint(true, '2015111916.01', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2015111916.01, 'local', 'o365');
}
if ($oldversion < 2016062000.01) {
@@ -517,7 +517,7 @@ function xmldb_local_o365_upgrade($oldversion) {
add_to_config_log('sharepointcourseselect', $existingsharepointcourseselectsetting, 'off', 'local_o365');
}
set_config('sharepointcourseselect', 'off', 'local_o365');
- upgrade_plugin_savepoint(true, '2016062000.01', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2016062000.01, 'local', 'o365');
}
if ($oldversion < 2016062000.02) {
@@ -528,7 +528,7 @@ function xmldb_local_o365_upgrade($oldversion) {
$caps = [
'auth/oidc:manageconnection' => ['local/o365:manageconnectionlink', 'local/o365:manageconnectionunlink'],
'auth/oidc:manageconnectionconnect' => ['local/o365:manageconnectionlink'],
- 'auth/oidc:manageconnectiondisconnect' => ['local/o365:manageconnectionunlink']
+ 'auth/oidc:manageconnectiondisconnect' => ['local/o365:manageconnectionunlink'],
];
foreach ($caps as $cap => $addcaps) {
$roles = get_roles_with_capability($cap, CAP_ALLOW);
@@ -538,8 +538,8 @@ function xmldb_local_o365_upgrade($oldversion) {
$newrolecap = $rolecap;
unset($newrolecap->id);
foreach ($addcaps as $addcap) {
- if (!$DB->record_exists('role_capabilities', ['roleid' => $role->id,
- 'capability' => $addcap, 'contextid' => $newrolecap->contextid])) {
+ if (!$DB->record_exists('role_capabilities',
+ ['roleid' => $role->id, 'capability' => $addcap, 'contextid' => $newrolecap->contextid])) {
$newrolecap->capability = $addcap;
$DB->insert_record('role_capabilities', $newrolecap);
}
@@ -560,7 +560,7 @@ function xmldb_local_o365_upgrade($oldversion) {
$dbman->add_field($table, $field);
}
}
- upgrade_plugin_savepoint(true, '2016062000.03', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2016062000.03, 'local', 'o365');
}
if ($oldversion < 2016062001.01) {
@@ -573,7 +573,7 @@ function xmldb_local_o365_upgrade($oldversion) {
add_to_config_log('sharepointcourseselect', $sharepointcourseselect, 'none', 'local_o365');
set_config('sharepointcourseselect', 'none', 'local_o365');
}
- upgrade_plugin_savepoint(true, '2016062001.01', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2016062001.01, 'local', 'o365');
}
if ($oldversion < 2016062004.01) {
@@ -590,7 +590,7 @@ function xmldb_local_o365_upgrade($oldversion) {
}
set_config('disablegraphapi', 0, 'local_o365');
}
- upgrade_plugin_savepoint(true, '2016062004.01', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2016062004.01, 'local', 'o365');
}
if ($oldversion < 2016120500.05) {
@@ -601,7 +601,7 @@ function xmldb_local_o365_upgrade($oldversion) {
$dbman->add_field($table, $field);
}
}
- upgrade_plugin_savepoint(true, '2016120500.05', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2016120500.05, 'local', 'o365');
}
if ($oldversion < 2016120500.06) {
@@ -612,12 +612,12 @@ function xmldb_local_o365_upgrade($oldversion) {
$dbman->add_field($table, $field);
}
}
- upgrade_plugin_savepoint(true, '2016120500.06', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2016120500.06, 'local', 'o365');
}
if ($oldversion < 2017111301) {
mtrace('Warning! This version removes the legacy Microsoft 365 API.');
- upgrade_plugin_savepoint(true, '2017111301', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2017111301, 'local', 'o365');
}
if ($oldversion < 2018051702) {
@@ -627,39 +627,7 @@ function xmldb_local_o365_upgrade($oldversion) {
add_to_config_log('createteams', $existingcreateteamssetting, $coursesyncsetting, 'local_o365');
}
set_config('createteams', $coursesyncsetting, 'local_o365');
- upgrade_plugin_savepoint(true, '2018051702', 'local', 'o365');
- }
-
- if ($oldversion < 2018051703) {
- // Commented out since the bot feature has been removed.
- /*
- if (!$dbman->table_exists('local_o365_notif')) {
- $dbman->install_one_table_from_xmldb_file(__DIR__ . '/install.xml', 'local_o365_notif');
- }
- */
-
- upgrade_plugin_savepoint(true, '2018051703', 'local', 'o365');
- }
-
- if ($oldversion < 2018051704) {
- // Commented out since the bot feature has been removed.
- /*
- $botappid = get_config('local_o365', 'bot_app_id');
- $botapppassword = get_config('local_o365', 'bot_app_password');
- $botwebhookendpoint = get_config('local_o365', 'bot_webhook_endpoint');
- if ($botappid && $botapppassword && $botwebhookendpoint) {
- set_config('bot_feature_enabled', '1', 'local_o365');
- } else {
- set_config('bot_feature_enabled', '0', 'local_o365');
- }
- */
- upgrade_plugin_savepoint(true, '2018051704', 'local', 'o365');
- }
-
- if ($oldversion < 2018051705) {
- // Commented out since the bot feature has been removed.
- // local_o365_check_sharedsecret();
- upgrade_plugin_savepoint(true, '2018051705', 'local', 'o365');
+ upgrade_plugin_savepoint(true, 2018051702, 'local', 'o365');
}
if ($oldversion < 2020020302) {
@@ -1066,6 +1034,7 @@ function xmldb_local_o365_upgrade($oldversion) {
}
} catch (moodle_exception $e) {
// Do nothing.
+ debugging('Error updating groups cache: ' . $e->getMessage());
}
// O365 savepoint reached.
@@ -1214,7 +1183,6 @@ function xmldb_local_o365_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2023100905, 'local', 'o365');
}
-
if ($oldversion < 2023100907) {
// Unset "systemtokens" config.
unset_config('systemtokens', 'local_o365');
diff --git a/local/o365/export_manifest.php b/local/o365/export_manifest.php
index 4414aaf3e..e8209e9b8 100644
--- a/local/o365/export_manifest.php
+++ b/local/o365/export_manifest.php
@@ -27,6 +27,8 @@
require_once($CFG->libdir . '/filestorage/zip_archive.php');
require_once($CFG->dirroot . '/local/o365/lib.php');
+require_admin();
+
// Mark manifest file as downloaded.
$existingmanifestdownloadedsetting = get_config('local_o365', 'manifest_downloaded');
if (!$existingmanifestdownloadedsetting) {
diff --git a/local/o365/lang/en/local_o365.php b/local/o365/lang/en/local_o365.php
index 39905ff16..6666e1dcc 100644
--- a/local/o365/lang/en/local_o365.php
+++ b/local/o365/lang/en/local_o365.php
@@ -167,7 +167,7 @@