Skip to content

Commit

Permalink
Merge pull request #46 from ilios/github-actions
Browse files Browse the repository at this point in the history
GitHub actions
  • Loading branch information
stopfstedt authored Jun 3, 2024
2 parents 4d5c863 + 4e53576 commit 171209d
Show file tree
Hide file tree
Showing 12 changed files with 836 additions and 545 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Moodle Plugin CI

on:
push:
pull_request:
schedule:
- cron: '33 2 * * 1' # weekly, on Monday morning

jobs:
test:
runs-on: ubuntu-latest

services:
mariadb:
image: mariadb:10
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3

strategy:
fail-fast: false
matrix:
include:
- php: '8.2'
moodle-branch: 'main'
database: 'mariadb'
- php: '8.2'
moodle-branch: 'MOODLE_403_STABLE'
database: 'mariadb'
steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
path: plugin

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
# If you are not using code coverage, keep "none". Otherwise, use "pcov" (Moodle 3.10 and up) or "xdebug".
# If you try to use code coverage with "none", it will fallback to phpdbg (which has known problems).
coverage: none

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
- name: Install moodle-plugin-ci
run: |
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}

- name: PHP Lint
if: ${{ !cancelled() }}
run: moodle-plugin-ci phplint

- name: PHP Mess Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpmd

- name: Moodle Code Checker
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpcs --max-warnings 0

- name: Moodle PHPDoc Checker
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpdoc --max-warnings 0

- name: Validating
if: ${{ !cancelled() }}
run: moodle-plugin-ci validate

- name: Check upgrade savepoints
if: ${{ !cancelled() }}
run: moodle-plugin-ci savepoints

- name: Mustache Lint
if: ${{ !cancelled() }}
run: moodle-plugin-ci mustache

- name: Grunt
if: ${{ !cancelled() }}
run: moodle-plugin-ci grunt --max-lint-warnings 0

- name: PHPUnit tests
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpunit --fail-on-warning

- name: Behat features
if: ${{ !cancelled() }}
run: moodle-plugin-ci behat --profile chrome

- name: Mark cancelled jobs as failed.
if: ${{ cancelled() }}
run: exit 1
4 changes: 4 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="MoodleCore">
<rule ref="moodle-extra"/>
</ruleset>
97 changes: 48 additions & 49 deletions ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* This file processes AJAX enrolment actions and returns JSON for the ilios plugin
* This file processes AJAX enrolment actions and returns JSON for the ilios plugin.
*
* The general idea behind this file is that any errors should throw exceptions
* which will be returned and acted upon by the calling AJAX script.
Expand All @@ -33,12 +33,12 @@
require_once($CFG->dirroot.'/group/lib.php');

// Must have the sesskey.
$id = required_param('id', PARAM_INT); // course id
$id = required_param('id', PARAM_INT); // Course ID.
$action = required_param('action', PARAM_ALPHANUMEXT);

$PAGE->set_url(new moodle_url('/enrol/ilios/ajax.php', array('id'=>$id, 'action'=>$action)));
$PAGE->set_url(new moodle_url('/enrol/ilios/ajax.php', ['id' => $id, 'action' => $action]));

$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
$course = $DB->get_record('course', ['id' => $id], '*', MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST);

if ($course->id == SITEID) {
Expand All @@ -65,14 +65,14 @@

/** @var enrol_ilios_plugin $enrol */
$enrol = enrol_get_plugin('ilios');
$api_client = $enrol->get_api_client();
$access_token = $enrol->get_api_access_token();
$apiclient = $enrol->get_api_client();
$accesstoken = $enrol->get_api_access_token();

switch ($action) {
case 'getselectschooloptions':
require_capability('moodle/course:enrolconfig', $context);
$schools = $api_client->get($access_token, 'schools', '', array('title' => "ASC"));
$schoolarray = array();
$schools = $apiclient->get($accesstoken, 'schools', '', ['title' => "ASC"]);
$schoolarray = [];
foreach ($schools as $school) {
$schoolarray["$school->id:$school->title"] = $school->title;
}
Expand All @@ -81,13 +81,13 @@

case 'getselectprogramoptions':
require_capability('moodle/course:enrolconfig', $context);
$sid = required_param('filterid', PARAM_INT); // school id
$programs = array();
$programs = $api_client->get($access_token, 'programs', array('school' => $sid), array('title' => "ASC"));
$programarray = array();
$sid = required_param('filterid', PARAM_INT); // School ID.
$programs = [];
$programs = $apiclient->get($accesstoken, 'programs', ['school' => $sid], ['title' => "ASC"]);
$programarray = [];
foreach ($programs as $program) {
$key = $program->id;
foreach (array('shortTitle', 'title') as $attr) {
foreach (['shortTitle', 'title'] as $attr) {
$key .= ':';
if (property_exists($program, $attr)) {
$key .= $program->$attr;
Expand All @@ -101,24 +101,24 @@
case 'getselectcohortoptions':
require_capability('moodle/course:enrolconfig', $context);
$pid = required_param('filterid', PARAM_INT);
$programyears = $api_client->get(
$access_token,
$programyears = $apiclient->get(
$accesstoken,
'programYears',
array("program" => $pid),
array("startYear" => "ASC")
["program" => $pid],
["startYear" => "ASC"]
);
$programyeararray = array();
$cohortoptions = array();
$programyeararray = [];
$cohortoptions = [];
foreach ($programyears as $progyear) {
$programyeararray[] = $progyear->id;
}

if (!empty($programyeararray)) {
$cohorts = $api_client->get(
$access_token,
$cohorts = $apiclient->get(
$accesstoken,
'cohorts',
array("programYear" => $programyeararray),
array("title" => "ASC")
["programYear" => $programyeararray],
["title" => "ASC"]
);
foreach ($cohorts as $cohort) {
$cohortoptions["$cohort->id:$cohort->title"] = $cohort->title
Expand All @@ -131,15 +131,15 @@

case 'getselectlearnergroupoptions':
require_capability('moodle/course:enrolconfig', $context);
$cid = required_param('filterid', PARAM_INT); // cohort id
$usertype = optional_param('usertype', 0, PARAM_INT); // learner or instructor
$learnergroups = $api_client->get(
$access_token,
$cid = required_param('filterid', PARAM_INT); // Cohort ID.
$usertype = optional_param('usertype', 0, PARAM_INT); // Learner or instructor.
$learnergroups = $apiclient->get(
$accesstoken,
'learnerGroups',
array('cohort' => $cid, 'parent' => 'null'),
array('title'=> "ASC")
['cohort' => $cid, 'parent' => 'null'],
['title' => "ASC"]
);
$grouparray = array();
$grouparray = [];
foreach ($learnergroups as $group) {
$grouparray["$group->id:$group->title"] = $group->title.
' ('. count($group->children) .')';
Expand All @@ -150,27 +150,27 @@

case 'getselectsubgroupoptions':
require_capability('moodle/course:enrolconfig', $context);
$gid = required_param('filterid', PARAM_INT); // group id
$usertype = optional_param('usertype', 0, PARAM_INT); // learner or instructor
$subgroupoptions = array();
$subgroups = $api_client->get(
$access_token,
$gid = required_param('filterid', PARAM_INT); // Group ID.
$usertype = optional_param('usertype', 0, PARAM_INT); // Learner or instructor.
$subgroupoptions = [];
$subgroups = $apiclient->get(
$accesstoken,
'learnerGroups',
array("parent" => $gid),
array("title" => "ASC")
["parent" => $gid],
["title" => "ASC"]
);
foreach ($subgroups as $subgroup) {
$subgroupoptions["$subgroup->id:$subgroup->title"] = $subgroup->title.
' ('. count($subgroup->children) .')';
$subgroupoptions["$subgroup->id:$subgroup->title"] .= ' ('. count($subgroup->users) .')';

if (!empty($subgroup->children)) {
$processchildren = function ($parent) use (&$processchildren,&$subgroupoptions, $api_client, $access_token) {
$subgrps = $api_client->get(
$access_token,
$processchildren = function ($parent) use (&$processchildren, &$subgroupoptions, $apiclient, $accesstoken) {
$subgrps = $apiclient->get(
$accesstoken,
'learnerGroups',
array( 'parent' => $parent->id),
array( 'title' => "ASC")
[ 'parent' => $parent->id],
[ 'title' => "ASC"]
);
foreach ($subgrps as $subgrp) {
$subgroupoptions["$subgrp->id:$parent->title / $subgrp->title"] = $parent->title.' / '.$subgrp->title.
Expand All @@ -190,16 +190,15 @@

case 'getselectinstructorgroupoptions':
require_capability('moodle/course:enrolconfig', $context);
$gid = required_param('filterid', PARAM_INT); // group id
$instructorgroupoptions = array();
$learnergroup = $api_client->get_by_id($access_token, 'learnerGroups', $gid);
$gid = required_param('filterid', PARAM_INT); // Group ID.
$instructorgroupoptions = [];
$learnergroup = $apiclient->get_by_id($accesstoken, 'learnerGroups', $gid);
if (!empty($learnergroup->instructorGroups)) {
$instructorgroups = $api_client->get(
$access_token,
$instructorgroups = $apiclient->get(
$accesstoken,
'instructorGroups',
// array("id" => $learnergroup->instructorGroups),
'',
array("title" => "ASC")
["title" => "ASC"]
);
foreach ($instructorgroups as $instructorgroup) {
$instructorgroupoptions["$instructorgroup->id:$instructorgroup->title"] = $instructorgroup->title.
Expand Down
19 changes: 11 additions & 8 deletions classes/task/ilios_sync_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,32 @@

namespace enrol_ilios\task;

defined('MOODLE_INTERNAL') || die;
use coding_exception;
use core\task\scheduled_task;

/**
* Simple task to run sync enrolments.
*
* @package enrol_ilios
* @copyright 2018 The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class ilios_sync_task extends \core\task\scheduled_task {
class ilios_sync_task extends scheduled_task {

/**
* @inheritdoc
* Gets the task name.
*
* @return string The task name.
* @throws coding_exception
*/
public function get_name() {
return get_string('iliossync', 'enrol_ilios');
}

/**
* @inheritdoc
* Executes the task.
*/
public function execute() {
public function execute(): void {
global $CFG;

require_once($CFG->dirroot . '/enrol/ilios/lib.php');
Expand All @@ -54,8 +59,6 @@ public function execute() {
}

$plugin = enrol_get_plugin('ilios');
$result = $plugin->sync(new \text_progress_trace());
return $result;

$plugin->sync(new \text_progress_trace());
}
}
20 changes: 10 additions & 10 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@

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

$capabilities = array(
$capabilities = [

'enrol/ilios:config' => array(
'enrol/ilios:config' => [

'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'archetypes' => [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
)
),
],
],

/* This is used only when sync suspends users instead of full unenrolment. */
'enrol/ilios:unenrol' => array(
'enrol/ilios:unenrol' => [

'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'archetypes' => [
'manager' => CAP_ALLOW,
)
),
],
],

);
];
Loading

0 comments on commit 171209d

Please sign in to comment.