From 7af91f412a8f19456adff491b9a658fdb3113dc8 Mon Sep 17 00:00:00 2001 From: Lai Wei Date: Mon, 15 Dec 2025 15:42:09 +0000 Subject: [PATCH 1/2] Fix Moodle plugin CI errors in block_microsoft --- block_microsoft.php | 84 +++++++++++++------ .../form/course_configure_form.php | 61 ++++++-------- classes/form/course_sync_form.php | 54 ++++++++++++ classes/privacy/provider.php | 1 - configure_reset.php | 12 ++- configure_sync.php | 4 +- db/upgrade.php | 2 +- 7 files changed, 150 insertions(+), 68 deletions(-) rename forms.php => classes/form/course_configure_form.php (60%) create mode 100644 classes/form/course_sync_form.php diff --git a/block_microsoft.php b/block_microsoft.php index faeceb9..4c2e800 100644 --- a/block_microsoft.php +++ b/block_microsoft.php @@ -83,8 +83,10 @@ public function get_content() { $this->content->text .= $this->get_user_content_connected(); } else { $connection = $DB->get_record('local_o365_connections', ['muserid' => $USER->id]); - if (!empty($connection) && (auth_oidc_connectioncapability($USER->id, 'connect') || - local_o365_connectioncapability($USER->id, 'link'))) { + if ( + !empty($connection) && (auth_oidc_connectioncapability($USER->id, 'connect') || + local_o365_connectioncapability($USER->id, 'link')) + ) { $uselogin = (!empty($connection->uselogin)) ? true : false; $this->content->text .= $this->get_user_content_matched($connection->entraidupn, $uselogin); } else { @@ -153,10 +155,15 @@ protected function get_course_content() { $coursesyncsetting = get_config('local_o365', 'coursesync'); $allowedmanageteamsyncpercourse = get_config('local_o365', 'course_sync_per_course'); if ($coursesyncsetting == 'oncustom' && $allowedmanageteamsyncpercourse) { - $configuresyncurl = new moodle_url('/blocks/microsoft/configure_sync.php', - ['course' => $courseid]); - $items[] = html_writer::link($configuresyncurl, get_string('configure_sync', 'block_microsoft'), - ['class' => 'servicelink block_microsoft_sync']); + $configuresyncurl = new moodle_url( + '/blocks/microsoft/configure_sync.php', + ['course' => $courseid] + ); + $items[] = html_writer::link( + $configuresyncurl, + get_string('configure_sync', 'block_microsoft'), + ['class' => 'servicelink block_microsoft_sync'] + ); } } @@ -178,8 +185,11 @@ protected function get_course_content() { $url = new moodle_url($microsoft365urls[$feature]); $resourcename = get_string('course_feature_' . $feature, 'block_microsoft'); - $items[] = html_writer::link($url, $resourcename, - ['target' => '_blank', 'class' => 'servicelink block_microsoft_' . $feature]); + $items[] = html_writer::link( + $url, + $resourcename, + ['target' => '_blank', 'class' => 'servicelink block_microsoft_' . $feature] + ); } // Link to course reset options. @@ -187,29 +197,39 @@ protected function get_course_content() { switch (get_config('local_o365', 'course_reset_teams')) { case COURSE_SYNC_RESET_SITE_SETTING_PER_COURSE: // Allow user to configure reset actions. - $configurereseturl = new moodle_url('/blocks/microsoft/configure_reset.php', - ['course' => $courseid]); - $items[] = html_writer::link($configurereseturl, + $configurereseturl = new moodle_url( + '/blocks/microsoft/configure_reset.php', + ['course' => $courseid] + ); + $items[] = html_writer::link( + $configurereseturl, get_string('configure_reset', 'block_microsoft'), - ['class' => 'servicelink block_microsoft_reset']); + ['class' => 'servicelink block_microsoft_reset'] + ); break; case COURSE_SYNC_RESET_SITE_SETTING_DISCONNECT_AND_CREATE_NEW: // Force archive, show notification. - $items[] = html_writer::span(get_string('course_reset_disconnect_and_create_new', - 'block_microsoft'), 'servicelink block_microsoft_reset'); + $items[] = html_writer::span(get_string( + 'course_reset_disconnect_and_create_new', + 'block_microsoft' + ), 'servicelink block_microsoft_reset'); break; case COURSE_SYNC_RESET_SITE_SETTING_DISCONNECT_ONLY: // Force disconnect, show notification. - $items[] = html_writer::span(get_string('course_reset_disconnect_only', 'block_microsoft'), - 'servicelink block_microsoft_reset'); + $items[] = html_writer::span( + get_string('course_reset_disconnect_only', 'block_microsoft'), + 'servicelink block_microsoft_reset' + ); break; default: // Force do nothing, show notification. - $items[] = html_writer::span(get_string('course_reset_do_nothing', 'block_microsoft'), - 'servicelink block_microsoft_reset'); + $items[] = html_writer::span( + get_string('course_reset_do_nothing', 'block_microsoft'), + 'servicelink block_microsoft_reset' + ); } } } @@ -232,8 +252,12 @@ private function get_course_header_and_o365object(int $courseid) { $o365record = null; if (utils::is_course_sync_enabled($courseid)) { - if ($o365record = $DB->get_record('local_o365_objects', - ['type' => 'group', 'subtype' => 'course', 'moodleid' => $courseid])) { + if ( + $o365record = $DB->get_record( + 'local_o365_objects', + ['type' => 'group', 'subtype' => 'course', 'moodleid' => $courseid] + ) + ) { [$subtypesql, $params] = $DB->get_in_or_equal(['courseteam', 'teamfromgroup'], SQL_PARAMS_NAMED); $params['type'] = 'group'; $params['moodleid'] = $courseid; @@ -374,8 +398,11 @@ protected function get_user_content_connected() { if (!empty($this->globalconfig->settings_showmsstream)) { $streamclassicurl = 'https://web.microsoftstream.com/?noSignUpCheck=1'; $streamclassicattrs = ['target' => '_blank', 'class' => 'servicelink block_microsoft_msstream']; - $items[] = html_writer::link($streamclassicurl, get_string('linkmsstreamclassic', 'block_microsoft'), - $streamclassicattrs); + $items[] = html_writer::link( + $streamclassicurl, + get_string('linkmsstreamclassic', 'block_microsoft'), + $streamclassicattrs + ); } // Microsoft Teams. @@ -406,10 +433,12 @@ protected function get_user_content_connected() { $items[] = html_writer::link($prefsurl, $prefsstr, ['class' => 'servicelink block_microsoft_preferences']); } - if (auth_oidc_connectioncapability($USER->id, 'connect') === true + if ( + auth_oidc_connectioncapability($USER->id, 'connect') === true || auth_oidc_connectioncapability($USER->id, 'disconnect') === true || local_o365_connectioncapability($USER->id, 'link') - || local_o365_connectioncapability($USER->id, 'unlink')) { + || local_o365_connectioncapability($USER->id, 'unlink') + ) { if (!empty($this->globalconfig->settings_showmanageo365conection)) { $connecturl = new moodle_url('/local/o365/ucp.php', ['action' => 'connection']); $connectstr = get_string('linkconnection', 'block_microsoft'); @@ -507,8 +536,11 @@ protected function get_content_o365download() { $str = get_string('install_office', 'block_microsoft'); return [ - html_writer::link($url, $str, - ['class' => 'servicelink block_microsoft_downloado365', 'target' => '_blank']), + html_writer::link( + $url, + $str, + ['class' => 'servicelink block_microsoft_downloado365', 'target' => '_blank'] + ), ]; } diff --git a/forms.php b/classes/form/course_configure_form.php similarity index 60% rename from forms.php rename to classes/form/course_configure_form.php index dc4bd42..33d71de 100644 --- a/forms.php +++ b/classes/form/course_configure_form.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Define forms used by the plugin. + * Form to configure course reset actions. * * @package block_microsoft * @author Lai Wei @@ -28,31 +28,6 @@ require_once($CFG->libdir . '/formslib.php'); require_once($CFG->dirroot . '/local/o365/lib.php'); -/** - * Form to configure course sync options. - */ -class block_microsoft_course_sync_form extends moodleform { - /** - * Form definition. - */ - protected function definition() { - $mform = $this->_form; - - $mform->addElement('hidden', 'course'); - $mform->setType('course', PARAM_INT); - - // Sync options. - $syncoptions = [ - MICROSOFT365_COURSE_SYNC_DISABLED => get_string('course_sync_option_disabled', 'block_microsoft'), - MICROSOFT365_COURSE_SYNC_ENABLED => get_string('course_sync_option_enabled', 'block_microsoft'), - ]; - $mform->addElement('select', 'sync', get_string('course_sync_option', 'block_microsoft'), $syncoptions); - $mform->setDefault('sync', MICROSOFT365_COURSE_SYNC_DISABLED); - - $this->add_action_buttons(); - } -} - /** * Form to configure course reset actions. */ @@ -67,19 +42,37 @@ protected function definition() { $mform->setType('course', PARAM_INT); $resetoptions = []; - $resetoptions[] = $mform->createElement('radio', 'reset_setting', '', - get_string('reset_option_do_nothing', 'block_microsoft'), COURSE_SYNC_RESET_COURSE_SETTING_DO_NOTHING); + $resetoptions[] = $mform->createElement( + 'radio', + 'reset_setting', + '', + get_string('reset_option_do_nothing', 'block_microsoft'), + COURSE_SYNC_RESET_COURSE_SETTING_DO_NOTHING + ); $coursesyncsetting = get_config('local_o365', 'coursesync'); if ($coursesyncsetting == 'oncustom') { - $resetoptions[] = $mform->createElement('radio', 'reset_setting', '', + $resetoptions[] = $mform->createElement( + 'radio', + 'reset_setting', + '', get_string('reset_option_disconnect_only', 'block_microsoft'), - COURSE_SYNC_RESET_COURSE_SETTING_DISCONNECT_ONLY); + COURSE_SYNC_RESET_COURSE_SETTING_DISCONNECT_ONLY + ); } - $resetoptions[] = $mform->createElement('radio', 'reset_setting', '', + $resetoptions[] = $mform->createElement( + 'radio', + 'reset_setting', + '', get_string('reset_option_disconnect_and_create_new', 'block_microsoft'), - COURSE_SYNC_RESET_COURSE_SETTING_DISCONNECT_AND_CREATE_NEW); - $mform->addGroup($resetoptions, 'resetsettinggroup', get_string('course_reset_option', 'block_microsoft'), - '
', false); + COURSE_SYNC_RESET_COURSE_SETTING_DISCONNECT_AND_CREATE_NEW + ); + $mform->addGroup( + $resetoptions, + 'resetsettinggroup', + get_string('course_reset_option', 'block_microsoft'), + '
', + false + ); $mform->setDefault('reset_setting', COURSE_SYNC_RESET_COURSE_SETTING_DO_NOTHING); $this->add_action_buttons(); diff --git a/classes/form/course_sync_form.php b/classes/form/course_sync_form.php new file mode 100644 index 0000000..e95bd06 --- /dev/null +++ b/classes/form/course_sync_form.php @@ -0,0 +1,54 @@ +. + +/** + * Form to configure course sync options. + * + * @package block_microsoft + * @author Lai Wei + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright (C) 2021 onwards Microsoft, Inc. (http://microsoft.com/) + */ + +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->libdir . '/formslib.php'); +require_once($CFG->dirroot . '/local/o365/lib.php'); + +/** + * Form to configure course sync options. + */ +class block_microsoft_course_sync_form extends moodleform { + /** + * Form definition. + */ + protected function definition() { + $mform = $this->_form; + + $mform->addElement('hidden', 'course'); + $mform->setType('course', PARAM_INT); + + // Sync options. + $syncoptions = [ + MICROSOFT365_COURSE_SYNC_DISABLED => get_string('course_sync_option_disabled', 'block_microsoft'), + MICROSOFT365_COURSE_SYNC_ENABLED => get_string('course_sync_option_enabled', 'block_microsoft'), + ]; + $mform->addElement('select', 'sync', get_string('course_sync_option', 'block_microsoft'), $syncoptions); + $mform->setDefault('sync', MICROSOFT365_COURSE_SYNC_DISABLED); + + $this->add_action_buttons(); + } +} diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 9201f47..8e76c38 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -29,7 +29,6 @@ */ class provider implements \core_privacy\local\metadata\null_provider { - /** * Get the language string identifier with the component's language * file to explain why this plugin stores no data. diff --git a/configure_reset.php b/configure_reset.php index b612fc8..36e3b74 100644 --- a/configure_reset.php +++ b/configure_reset.php @@ -25,10 +25,10 @@ use local_o365\feature\coursesync\utils; -require_once(__DIR__.'/../../config.php'); +require_once(__DIR__ . '/../../config.php'); require_once($CFG->dirroot . '/local/o365/lib.php'); require_once($CFG->dirroot . '/blocks/microsoft/lib.php'); -require_once($CFG->dirroot . '/blocks/microsoft/forms.php'); +require_once($CFG->dirroot . '/blocks/microsoft/classes/form/course_configure_form.php'); $courseid = required_param('course', PARAM_INT); $coursecontext = context_course::instance($courseid); @@ -55,8 +55,12 @@ throw new moodle_exception('error_reset_setting_not_managed_per_course', 'block_microsoft', $redirecturl); } - if (!$o365object = $DB->get_record('local_o365_objects', - ['type' => 'group', 'subtype' => 'course', 'moodleid' => $courseid])) { + if ( + !$o365object = $DB->get_record( + 'local_o365_objects', + ['type' => 'group', 'subtype' => 'course', 'moodleid' => $courseid] + ) + ) { throw new moodle_exception('error_connected_team_missing', 'block_microsoft', $redirecturl); } } else { diff --git a/configure_sync.php b/configure_sync.php index 7dfd5bc..b76e013 100644 --- a/configure_sync.php +++ b/configure_sync.php @@ -23,8 +23,8 @@ * @copyright (C) 2021 onwards Microsoft, Inc. (http://microsoft.com/) */ -require_once(__DIR__.'/../../config.php'); -require_once($CFG->dirroot . '/blocks/microsoft/forms.php'); +require_once(__DIR__ . '/../../config.php'); +require_once($CFG->dirroot . '/blocks/microsoft/classes/form/course_sync_form.php'); require_once($CFG->dirroot . '/blocks/microsoft/lib.php'); require_once($CFG->dirroot . '/local/o365/lib.php'); diff --git a/db/upgrade.php b/db/upgrade.php index 0c6023f..26b9575 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -32,7 +32,7 @@ function xmldb_block_microsoft_upgrade($oldversion) { if ($oldversion < 2015111912) { $existingshowoutlooksyncsetting = get_config('block_microsoft', 'settings_showoutlooksync'); - if ($existingshowoutlooksyncsetting != 0 ) { + if ($existingshowoutlooksyncsetting != 0) { add_to_config_log('settings_showoutlooksync', $existingshowoutlooksyncsetting, 0, 'block_microsoft'); } set_config('settings_showoutlooksync', 0, 'block_microsoft'); From 853a8b09849e97b8a4c7c4f9c99faa6bb8c39b59 Mon Sep 17 00:00:00 2001 From: Patryk Mroczko Date: Tue, 23 Dec 2025 12:11:02 +0100 Subject: [PATCH 2/2] Update plugin versions for 5.0.4 release --- version.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/version.php b/version.php index 8ff597c..6ccc4ba 100644 --- a/version.php +++ b/version.php @@ -25,11 +25,11 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2025040810; +$plugin->version = 2025040815; $plugin->requires = 2025040800; -$plugin->release = '5.0.2'; +$plugin->release = '5.0.4'; $plugin->component = 'block_microsoft'; $plugin->maturity = MATURITY_STABLE; $plugin->dependencies = [ - 'local_o365' => 2025040810, + 'local_o365' => 2025040820, ];