Skip to content

Commit

Permalink
merge with changes from original repository
Browse files Browse the repository at this point in the history
  • Loading branch information
TamaroWalter committed Feb 24, 2025
2 parents d5f2d86 + b9d49b6 commit ba50ffe
Show file tree
Hide file tree
Showing 16 changed files with 374 additions and 195 deletions.
58 changes: 33 additions & 25 deletions .github/workflows/moodle-plugin-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ jobs:
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3

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:
php: ['7.4', '8.0', '8.1']
moodle-branch: ['MOODLE_401_STABLE']
php: ['8.1', '8.2', '8.3']
moodle-branch: ['MOODLE_405_STABLE']
database: [pgsql, mariadb]

steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: plugin

Expand All @@ -50,61 +50,69 @@ jobs:

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
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
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: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci phplint

- name: PHP Copy/Paste Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
run: moodle-plugin-ci phpcpd

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

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

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

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

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

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

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

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

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

- name: Upload Behat Faildump
if: ${{ failure() && steps.behat.outcome == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: Behat Faildump (${{ join(matrix.*, ', ') }})
path: ${{ github.workspace }}/moodledata/behat_dump
retention-days: 7
if-no-files-found: ignore

- name: Mark cancelled jobs as failed.
if: ${{ cancelled() }}
run: exit 1
66 changes: 66 additions & 0 deletions .github/workflows/moodle-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#
# Whenever a new tag starting with "v" is pushed, add the tagged version
# to the Moodle Plugins directory at https://moodle.org/plugins
#
# revision: 2021070201
#
name: Releasing in the Plugins directory

on:
push:
tags:
- v*

workflow_dispatch:
inputs:
tag:
description: 'Tag to be released'
required: true

defaults:
run:
shell: bash

jobs:
release-at-moodle-org:
runs-on: ubuntu-latest
env:
PLUGIN: local_bulkenrol
CURL: curl -s
ENDPOINT: https://moodle.org/webservice/rest/server.php
TOKEN: ${{ secrets.MOODLE_ORG_TOKEN }}
FUNCTION: local_plugins_add_version

steps:
- name: Call the service function
id: add-version
run: |
if [[ ! -z "${{ github.event.inputs.tag }}" ]]; then
TAGNAME="${{ github.event.inputs.tag }}"
elif [[ $GITHUB_REF = refs/tags/* ]]; then
TAGNAME="${GITHUB_REF##*/}"
fi
if [[ -z "${TAGNAME}" ]]; then
echo "No tag name has been provided!"
exit 1
fi
ZIPURL="https://api.github.com/repos/${{ github.repository }}/zipball/${TAGNAME}"
RESPONSE=$(${CURL} ${ENDPOINT} --data-urlencode "wstoken=${TOKEN}" \
--data-urlencode "wsfunction=${FUNCTION}" \
--data-urlencode "moodlewsrestformat=json" \
--data-urlencode "frankenstyle=${PLUGIN}" \
--data-urlencode "zipurl=${ZIPURL}" \
--data-urlencode "vcssystem=git" \
--data-urlencode "vcsrepositoryurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" \
--data-urlencode "vcstag=${TAGNAME}" \
--data-urlencode "changelogurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commits/${TAGNAME}" \
--data-urlencode "altdownloadurl=${ZIPURL}")
echo "response=${RESPONSE}" >> $GITHUB_OUTPUT
- name: Evaluate the response
id: evaluate-response
env:
RESPONSE: ${{ steps.add-version.outputs.response }}
run: |
jq <<< ${RESPONSE}
jq --exit-status ".id" <<< ${RESPONSE} > /dev/null
35 changes: 34 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,41 @@ moodle-local_bulkenrol
Changes
-------

### Unreleased
### v4.5-r1

* 2024-10-14 - Upgrade: Adopt changes from MDL-82183 and use new \core\output\pix_icon class
* 2024-10-14 - Upgrade: Adopt changes from MDL-82183 and use new \core\output\html_writer
* 2024-10-14 - Upgrade: Adopt changes from MDL-81960 and use new \core\url class
* 2024-10-14 - Upgrade: Adopt changes from MDL-82183 and use new \core_table\output\html_table_cell class.
* 2024-10-07 - Prepare compatibility for Moodle 4.5.

### v4.4-r1

* 2024-08-24 - Development: Rename master branch to main, please update your clones.
* 2024-08-20 - Upgrade: Fix a behat test which broke on Moodle 4.4.
* 2024-08-20 - Upgrade: Update Bootstrap classes for Moodle 4.4.
* 2024-08-20 - Prepare compatibility for Moodle 4.4.

### v4.3-r2

* 2024-08-19 - Fix a behat test which broke recently
* 2024-08-11 - Add section for scheduled tasks to README
* 2024-08-11 - Updated Moodle Plugin CI to latest upstream recommendations

### v4.3-r1

* 2023-10-23 - Fix Behat tests which broke on Moodle 4.3.
* 2023-10-20 - Prepare compatibility for Moodle 4.3.

### v4.2-r1

* 2023-09-01 - Prepare compatibility for Moodle 4.2.

### v4.1-r2

* 2023-10-14 - Add automated release to moodle.org/plugins
* 2023-10-14 - Make codechecker happy again
* 2023-10-10 - Updated Moodle Plugin CI to latest upstream recommendations
* 2023-04-30 - Tests: Updated Moodle Plugin CI to use PHP 8.1 and Postgres 13 from Moodle 4.1 on.

### v4.1-r1
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
moodle-local_bulkenrol
======================

[![Moodle Plugin CI](https://github.com/moodle-an-hochschulen/moodle-local_bulkenrol/workflows/Moodle%20Plugin%20CI/badge.svg?branch=master)](https://github.com/moodle-an-hochschulen/moodle-local_bulkenrol/actions?query=workflow%3A%22Moodle+Plugin+CI%22+branch%3Amaster)
[![Moodle Plugin CI](https://github.com/moodle-an-hochschulen/moodle-local_bulkenrol/workflows/Moodle%20Plugin%20CI/badge.svg?branch=main)](https://github.com/moodle-an-hochschulen/moodle-local_bulkenrol/actions?query=workflow%3A%22Moodle+Plugin+CI%22+branch%3Amain)

Moodle plugin which provides the possibility to bulk enrol a list of users who are identified by their e-mail adresses into a course.


Requirements
------------

This plugin requires Moodle 4.1+
This plugin requires Moodle 4.5+


Motivation for this plugin
Expand Down Expand Up @@ -62,6 +62,12 @@ This plugin also introduces a new capability:
By default, Moodle users are _not_ allowed to use the functionality provided by this plugin. As administrator, you can selectively grant users the ability to use this functionality by adding the local/bulkenrol:enrolusers capability to an appropriate Moodle role.


Scheduled Tasks
---------------

This plugin does not add any additional scheduled tasks.


How this plugin works
---------------------

Expand Down
28 changes: 23 additions & 5 deletions classes/bulkenrol_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace local_bulkenrol;

use moodle_exception;
use moodleform;

defined('MOODLE_INTERNAL') || die();
Expand Down Expand Up @@ -53,8 +54,8 @@ protected function definition() {
// Selector for database field to match list to.
$availablefieldsstring = get_config('local_bulkenrol', 'fieldoptions');
$availablefieldsarray = explode(',', $availablefieldsstring);
if (count($availablefieldsarray) < 1 or $availablefieldsarray[0] == '') {
print_error(get_string('error_no_options_available', 'local_bulkenrol'));
if (count($availablefieldsarray) < 1 || $availablefieldsarray[0] == '') {
throw new moodle_exception('error_no_options_available', 'local_bulkenrol');
}

$selectoptions = [];
Expand All @@ -64,7 +65,8 @@ protected function definition() {

// Format CSV, replace last , with 'or' and add spaces after remaining.
$fieldnamestring = implode(', ', $selectoptions);
$formattedfieldnamestring = $this->str_last_replace(', ', ' ' . get_string('or', 'local_bulkenrol') . ' ', $fieldnamestring);
$formattedfieldnamestring = $this->str_last_replace(', ', ' ' .
get_string('or', 'local_bulkenrol') . ' ', $fieldnamestring);

// Infotext.
$msg = get_string('bulkenrol_form_intro', 'local_bulkenrol', $formattedfieldnamestring);
Expand Down Expand Up @@ -125,7 +127,7 @@ protected function definition() {
* or an empty array if everything is OK (true allowed for backwards compatibility too).
*/
public function validation($data, $files) {
$retval = array();
$retval = [];

if (empty($data['uservalues'])) {
$retval['uservalues'] = get_string('error_list_empty', 'local_bulkenrol');
Expand All @@ -134,19 +136,35 @@ public function validation($data, $files) {
return $retval;
}

/**
* Getter function.
*
* @param $fieldoption
* @return false|\lang_string|mixed|string
* @throws \coding_exception
* @throws \dml_exception
*/
private function get_fieldname($fieldoption) {
global $DB;
$fieldinfo = explode("_", $fieldoption, 2);
switch ($fieldinfo[0]) {
case "u":
return get_string($fieldinfo[1]);
case "c":
return $DB->get_field('user_info_field', 'name', array("id" => intval($fieldinfo[1])));
return $DB->get_field('user_info_field', 'name', ["id" => intval($fieldinfo[1])]);
default:
throw new \UnexpectedValueException("field is not from usertable (u_) or customfield (c_)");
}
}

/**
* Replace function.
*
* @param $search
* @param $replace
* @param $subject
* @return array|mixed|string|string[]
*/
private function str_last_replace($search, $replace, $subject) {
$pos = strrpos($subject, $search);

Expand Down
2 changes: 1 addition & 1 deletion classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class provider implements \core_privacy\local\metadata\null_provider {
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
14 changes: 7 additions & 7 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@

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

$capabilities = array(
'local/bulkenrol:enrolusers' => array(
$capabilities = [
'local/bulkenrol:enrolusers' => [
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'manager' => CAP_ALLOW
),
),
);
'archetypes' => [
'manager' => CAP_ALLOW,
],
],
];
Loading

0 comments on commit ba50ffe

Please sign in to comment.