Skip to content

Commit

Permalink
Fix Moodle plugin CI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
patmr7 committed Nov 19, 2024
1 parent 749cfa9 commit ca24f21
Show file tree
Hide file tree
Showing 101 changed files with 1,292 additions and 1,187 deletions.
86 changes: 86 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
services:
- name: selenium/standalone-chrome:3
alias: behat
- name: mysql:8.0
alias: db
command:
- '--character-set-server=utf8mb4'
- '--collation-server=utf8mb4_unicode_ci'
- '--innodb_file_per_table=On'
- '--wait-timeout=28800'
- '--skip-log-bin'

cache:
paths:
- .cache

variables:
DEBIAN_FRONTEND: 'noninteractive'
COMPOSER_ALLOW_SUPERUSER: 1
COMPOSER_CACHE_DIR: "$CI_PROJECT_DIR/.cache/composer"
NPM_CONFIG_CACHE: "$CI_PROJECT_DIR/.cache/npm"
CI_BUILD_DIR: '/tmp/plugin'
MOODLE_BRANCH: 'MOODLE_405_STABLE'
MOODLE_BEHAT_WWWROOT: 'http://localhost:8000'
MOODLE_BEHAT_WDHOST: 'http://behat:4444/wd/hub'
MOODLE_START_BEHAT_SERVERS: 'no'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
DB: 'mysqli'

stages:
- moodle-plugin-ci

.setupandruncheck: &setupandruncheck
stage: moodle-plugin-ci
before_script:
- mkdir -pv "$CI_BUILD_DIR"
- cp -ru "$CI_PROJECT_DIR/"* "$CI_BUILD_DIR"
- mkdir -p /usr/share/man/man1 /usr/share/man/man3 /usr/share/man/man7
- apt-get -qq update
- apt-get -yqq install --no-install-suggests default-jre-headless default-mysql-client
- 'curl -sS https://raw.githubusercontent.com/creationix/nvm/v0.39.3/install.sh | bash'
- . ~/.bashrc
- nvm install --default --latest-npm lts/gallium
- 'curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer'
- composer create-project -n --no-dev --no-progress --no-ansi moodlehq/moodle-plugin-ci /opt/mci ^4
- export PATH="/opt/mci/bin:/opt/mci/vendor/bin:$PATH"
- moodle-plugin-ci add-plugin --clone https://github.com/microsoft/moodle-auth_oidc.git --branch $MOODLE_BRANCH
- moodle-plugin-ci install --db-host db --db-name moodle
- '{ php -S 0.0.0.0:8000 -t "$CI_PROJECT_DIR/moodle" >/dev/null 2>&1 & }'
- TXT_RED="\e[31m"

script:
- errors=()
- moodle-plugin-ci phplint || errors+=("phplint")
- moodle-plugin-ci phpmd || errors+=("phpmd")
- moodle-plugin-ci codechecker --max-warnings 0 || errors+=("codechecker")
- moodle-plugin-ci phpdoc --max-warnings 0 || errors+=("phpdoc")
- moodle-plugin-ci validate || errors+=("validate")
- moodle-plugin-ci savepoints || errors+=("savepoints")
- moodle-plugin-ci mustache || errors+=("mustache")
- moodle-plugin-ci grunt --max-lint-warnings 0 || errors+=("grunt")
- moodle-plugin-ci phpunit || errors+=("phpunit")
- moodle-plugin-ci behat --auto-rerun 0 --profile chrome || errors+=("behat")
- |-
if [ ${#errors[@]} -ne 0 ]; then
echo -e "${TXT_RED}Check errors: ${errors[@]}";
exit 1;
fi
php81:
tags:
- docker
image: moodlehq/moodle-php-apache:8.1
<<: *setupandruncheck

php82:
tags:
- docker
image: moodlehq/moodle-php-apache:8.2
<<: *setupandruncheck

php83:
tags:
- docker
image: moodlehq/moodle-php-apache:8.3
<<: *setupandruncheck
41 changes: 0 additions & 41 deletions .travis.yml

This file was deleted.

4 changes: 1 addition & 3 deletions classes/adminsetting/tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
use moodle_url;
use tabobject;

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

/**
* A tab in the plugin configuration page.
*/
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions classes/adminsetting/usersynccreationrestriction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions classes/adminsetting/usersyncoptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"';
Expand Down
8 changes: 2 additions & 6 deletions classes/adminsetting/verifysetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions classes/event/api_call_failed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace local_o365\event;

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

/**
* Event fired whenever a user subscribes to a calendar.
*/
Expand Down
2 changes: 0 additions & 2 deletions classes/event/calendar_subscribed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace local_o365\event;

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

/**
* Event fired whenever a user subscribes to a calendar.
*/
Expand Down
2 changes: 0 additions & 2 deletions classes/event/calendar_unsubscribed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace local_o365\event;

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

/**
* Event fired whenever a user unsubscribes from a calendar.
*/
Expand Down
16 changes: 11 additions & 5 deletions classes/feature/calsync/form/element/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

require_once("$CFG->libdir/form/advcheckbox.php");

// phpcs:disable moodle.NamingConventions.ValidVariableName.VariableNameLowerCase -- Parent class uses uppercase variable names.
// phpcs:disable moodle.NamingConventions.ValidFunctionName.LowercaseMethod -- Parent class uses uppercase method names.

/**
* Calendar form element. Provides checkbox to enable/disable calendar and options for sync behavior.
*/
Expand All @@ -50,15 +53,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';
}
Expand Down Expand Up @@ -112,7 +115,7 @@ public function setValue($value) {
*
* @return string html for help button
*/
function getHelpButton(){
public function getHelpButton() {
return $this->_helpbutton;
}

Expand Down Expand Up @@ -183,3 +186,6 @@ public function toHtml() {
return $html;
}
}

// phpcs:enable moodle.NamingConventions.ValidVariableName.VariableNameLowerCase
// phpcs:enable moodle.NamingConventions.ValidFunctionName.LowercaseMethod
20 changes: 10 additions & 10 deletions classes/feature/calsync/form/subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
Loading

0 comments on commit ca24f21

Please sign in to comment.