Skip to content

Commit

Permalink
Fix Moodle plugin CI errors in local_o365
Browse files Browse the repository at this point in the history
  • Loading branch information
weilai-irl committed Oct 23, 2024
1 parent fb18258 commit 861e855
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion local/o365/classes/feature/calsync/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public function create_outlook_event_from_moodle_event($moodleventid) {
}
} catch (moodle_exception $e) {
// No token found, nothing to do.
error_log('Error creating group event. Details: ' . $e->getMessage());
debugging('Error creating group event. Details: ' . $e->getMessage());
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions local/o365/classes/feature/coursesync/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,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 = [
Expand Down Expand Up @@ -344,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);
Expand Down Expand Up @@ -439,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)) {
Expand Down Expand Up @@ -496,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);
}

Expand Down Expand Up @@ -1697,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);
Expand Down
4 changes: 2 additions & 2 deletions local/o365/classes/feature/usersync/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,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 {
Expand Down Expand Up @@ -1159,7 +1159,7 @@ public function sync_users(array $entraidusers = [], string $bindingusernameclai
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 = ?
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);
Expand Down
3 changes: 3 additions & 0 deletions local/o365/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@

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

/**
* Local userlist provider for local_o365.
*/
interface local_o365_userlist extends core_userlist_provider {
};

Expand Down
9 changes: 5 additions & 4 deletions local/o365/classes/rest/unified.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,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) {
error_log('Error getting team URL. Details: ' . $e->getMessage());
$teamurl = null;
}
if ($teamurl) {
$o365urls['team'] = $teamurl;
}

return $o365urls;
}

Expand Down
4 changes: 2 additions & 2 deletions local/o365/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1034,7 +1034,7 @@ function xmldb_local_o365_upgrade($oldversion) {
}
} catch (moodle_exception $e) {
// Do nothing.
error_log('Error updating groups cache: ' . $e->getMessage());
debugging('Error updating groups cache: ' . $e->getMessage());
}

// O365 savepoint reached.
Expand Down
4 changes: 1 addition & 3 deletions local/o365/tests/coursesyncutils_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@
use externallib_advanced_testcase;
use local_o365\feature\coursesync\utils;

global $CFG;

require_once($CFG->dirroot . '/webservice/tests/helpers.php');

/**
* Tests \local_o365\feature\coursesync\utils.
*
* @group local_o365
*/
abstract class coursesyncutils_test extends externallib_advanced_testcase {
final class coursesyncutils_test extends externallib_advanced_testcase {
/**
* Perform setup before every test. This tells Moodle's phpunit to reset the database after every test.
*/
Expand Down
2 changes: 1 addition & 1 deletion local/o365/tests/observers_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @group local_o365
* @group office365
*/
abstract class observers_test extends advanced_testcase {
final class observers_test extends advanced_testcase {
/**
* Perform setup before every test. This tells Moodle's phpunit to reset the database after every test.
*/
Expand Down
18 changes: 9 additions & 9 deletions local/o365/tests/privacy_provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* @group office365
* @group office365_privacy
*/
abstract class privacy_provider_test extends provider_testcase {
final class privacy_provider_test extends provider_testcase {
/**
* Tests set up.
*/
Expand All @@ -51,7 +51,7 @@ protected function setUp(): void {
*
* @covers \local_o365\privacy\provider::get_contexts_for_userid
*/
public function test_get_contexts_for_userid(): void{
public function test_get_contexts_for_userid(): void {
$user = $this->getDataGenerator()->create_user();
$this->assertEmpty(provider::get_contexts_for_userid($user->id));

Expand Down Expand Up @@ -299,7 +299,7 @@ private static function create_userdata(int $userid) {
* @param int $userid
* @return stdClass
*/
private static function create_calidmap(int $userid) : stdClass {
private static function create_calidmap(int $userid): stdClass {
global $DB;
$record = new stdClass();
$record->eventid = 123;
Expand Down Expand Up @@ -338,7 +338,7 @@ private static function create_calsub(int $userid) : stdClass {
* @param int $userid
* @return stdClass
*/
private static function create_connections(int $userid) : stdClass {
private static function create_connections(int $userid): stdClass {
global $DB;
$record = new stdClass();
$record->muserid = $userid;
Expand All @@ -355,7 +355,7 @@ private static function create_connections(int $userid) : stdClass {
* @param int $userid
* @return stdClass
*/
private static function create_token(int $userid) : stdClass {
private static function create_token(int $userid): stdClass {
global $DB;
$record = new stdClass();
$record->user_id = $userid;
Expand All @@ -375,7 +375,7 @@ private static function create_token(int $userid) : stdClass {
* @param int $userid
* @return stdClass
*/
private static function create_objects(int $userid) : stdClass {
private static function create_objects(int $userid): stdClass {
global $DB;
$record = new stdClass();
$record->type = 'user';
Expand All @@ -398,7 +398,7 @@ private static function create_objects(int $userid) : stdClass {
* @param int $userid
* @return stdClass
*/
private static function create_appassign(int $userid) : stdClass {
private static function create_appassign(int $userid): stdClass {
global $DB;
$record = new stdClass();
$record->muserid = $userid;
Expand All @@ -416,7 +416,7 @@ private static function create_appassign(int $userid) : stdClass {
* @param int $userid
* @return stdClass
*/
private static function create_matchqueue(int $userid) : stdClass {
private static function create_matchqueue(int $userid): stdClass {
global $DB;
$user = $DB->get_record('user', ['id' => $userid]);
$record = new stdClass();
Expand All @@ -436,7 +436,7 @@ private static function create_matchqueue(int $userid) : stdClass {
* @param int $userid
* @return stdClass
*/
private static function create_calsettings(int $userid) : stdClass {
private static function create_calsettings(int $userid): stdClass {
global $DB;
$record = new stdClass();
$record->user_id = $userid;
Expand Down
2 changes: 1 addition & 1 deletion local/o365/tests/token_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @group local_o365
* @group office365
*/
abstract class token_test extends advanced_testcase {
token class token_test extends advanced_testcase {
/**
* Perform setup before every test. This tells Moodle's phpunit to reset the database after every test.
*/
Expand Down
4 changes: 2 additions & 2 deletions local/o365/tests/usersync_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @group local_o365
* @group office365
*/
abstract class usersync_test extends advanced_testcase {
final class usersync_test extends advanced_testcase {
/**
* Perform setup before every test. This tells Moodle's phpunit to reset the database after every test.
*/
Expand Down Expand Up @@ -114,7 +114,7 @@ protected function get_entra_id_userinfo($i = 0) {
*
* @return array Array of test parameters.
*/
public function dataprovider_create_user_from_entra_id_data() {
public function dataprovider_create_user_from_entra_id_data(): array {
global $CFG;
$tests = [];

Expand Down
8 changes: 4 additions & 4 deletions local/o365/tests/webservices_onenoteassignment_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @group local_o365
* @group office365
*/
abstract class webservices_onenoteassignment_test extends advanced_testcase {
final class webservices_onenoteassignment_test extends advanced_testcase {

// Data structure elements of the array based on old Data Provider.
/** @var int */
Expand Down Expand Up @@ -75,7 +75,7 @@ public function test_assignment_create_parameters(): void {
*
* @return array Array of test parameters.
*/
public function dataprovider_create_assignment() {
public function dataprovider_create_assignment(): array {
return [
[
[
Expand Down Expand Up @@ -270,7 +270,7 @@ public function get_general_assignment_data_tests() {
*
* @return array Array of test parameters.
*/
public function dataprovider_assignment_read() {
public function dataprovider_assignment_read(): array {
global $DB;

$generaltests = $this->get_general_assignment_data_tests();
Expand Down Expand Up @@ -368,7 +368,7 @@ public function test_assignment_update_parameters(): void {
*
* @return array Array of test parameters.
*/
public function dataprovider_assignment_update() {
public function dataprovider_assignment_update(): array {
global $DB;
$generaltests = $this->get_general_assignment_data_tests();
$return = [];
Expand Down
8 changes: 4 additions & 4 deletions local/o365/tests/webservices_utils_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @group local_o365
* @group office365
*/
abstract class webservices_utils_test extends advanced_testcase {
final class webservices_utils_test extends advanced_testcase {

/**
* Perform setup before every test. This tells Moodle's phpunit to reset the database after every test.
Expand Down Expand Up @@ -87,7 +87,7 @@ public function create_assignment_info_testdata($createcourse, $modulerecords) {
*
* @return array Array of test parameters.
*/
public function dataprovider_assignment_info() {
public function dataprovider_assignment_info(): array {
// Notes:
// [[coursemoduleid]] is replaced with the id of the *last* course_module record inserted.
// [[courseid]] is replaced with the generated course ID.
Expand Down Expand Up @@ -315,7 +315,7 @@ public function test_get_assignment_info($createcourse, $modulerecords, $expecte
*
* @return array Array of test parameters.
*/
public function dataprovider_verify_assignment() {
public function dataprovider_verify_assignment(): array {
$assignmentinfotests = $this->dataprovider_assignment_info();

$testcases = [];
Expand Down Expand Up @@ -437,7 +437,7 @@ public function test_get_assignment_return_info_schema(): void {
*
* @return array Array of test parameters.
*/
public function dataprovider_get_assignment_return_info() {
public function dataprovider_get_assignment_return_info(): array {
$assignmentinfotests = $this->dataprovider_assignment_info();

$testcases = [];
Expand Down

0 comments on commit 861e855

Please sign in to comment.