Skip to content

Commit

Permalink
Merge pull request #1 from catalyst/subplugin_refactor_rebase
Browse files Browse the repository at this point in the history
Subplugin refactor rebase
  • Loading branch information
tuanngocnguyen authored Aug 30, 2024
2 parents 66b8e09 + 1142d4b commit 7878b84
Show file tree
Hide file tree
Showing 127 changed files with 1,113 additions and 1,012 deletions.
87 changes: 27 additions & 60 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ jobs:

strategy:
matrix:
php: ['8.1']
moodle-branch: ['MOODLE_402_STABLE']
php: ['8.2']
moodle-branch: ['MOODLE_404_STABLE']
database: ['pgsql']

steps:
- name: Start PostgreSQL
run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14

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

Expand All @@ -28,29 +28,9 @@ jobs:
ini-values: max_input_vars=5000
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Composer cache
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: npm cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- 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
Expand Down Expand Up @@ -107,28 +87,21 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.0', '8.1']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE']
php: ['8.0', '8.1', '8.2']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE', 'MOODLE_404_STABLE']
database: ['mariadb', 'pgsql']
exclude:
- php: '8.0'
moodle-branch: 'MOODLE_404_STABLE'
- php: '8.2'
moodle-branch: 'MOODLE_401_STABLE'
include:
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'mariadb'
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
moodle-branch: 'MOODLE_401_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
- php: '7.4'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
database: 'pgsql'

steps:
- name: Start MariaDB
Expand All @@ -140,7 +113,7 @@ jobs:
run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14

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

Expand All @@ -151,24 +124,6 @@ jobs:
ini-values: max_input_vars=5000
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Composer cache
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: npm cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
Expand All @@ -191,3 +146,15 @@ jobs:
- name: Behat features
if: ${{ always() }}
run: moodle-plugin-ci behat --profile chrome --auto-rerun 0

# This step allows to upload Behat faildump (screenshots) as workflow artifact,
# so it can be downloaded and inspected. You don't need this step if you
# are not running Behat test. Artifact will be retained for 7 days.
- 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
9 changes: 5 additions & 4 deletions .github/workflows/moodle-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ jobs:
steps:
- name: Call the service function
id: add-version
env:
TAGNAME: ${{ github.event.release.tag_name }}
BODY: ${{ github.event.release.body }}
ZIPURL: ${{ github.event.release.zipball_url }}
run: |
TAGNAME="${{ github.event.release.tag_name }}"
BODY="${{ github.event.release.body }}"
ZIPURL="${{ github.event.release.zipball_url }}"
RESPONSE=$(${CURL} ${ENDPOINT} --data-urlencode "wstoken=${TOKEN}" \
--data-urlencode "wsfunction=${FUNCTION}" \
--data-urlencode "moodlewsrestformat=json" \
Expand All @@ -42,7 +43,7 @@ jobs:
--data-urlencode "vcstag=${TAGNAME}" \
--data-urlencode "changelogurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commits/${TAGNAME}" \
--data-urlencode "altdownloadurl=${ZIPURL}" \
--data-urlencode "releasenotes=${BODY}" \
--data-urlencode "releasenotes=${BODY@Q}" \
--data-urlencode "releasenotesformat=4")
echo "response=${RESPONSE}" >> $GITHUB_OUTPUT
- name: Evaluate the response
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ Possible use cases are (not limited to):

To be adaptable to the needs of different institutions the plugin provides two subplugin types:

**Trigger**: These subplugins control the conditions a course have to meet so that a specific process is started for it.
**Trigger**: These subplugins control the conditions a course must meet so that a specific process is started.

**Step**: These subplugins represent atomic, reusable tasks that should be executed for a specific course.

## Subplugins
Requirements that are specific to your institution can be added through additional subplugins.
For more information please have a look at the [wiki](https://github.com/learnweb/moodle-tool_lifecycle/wiki).
It provides instructions for administrators as well as for developers to implement own requirements into subplugins.
A list of all subplugins and more information can be found in the [Wiki](https://github.com/learnweb/moodle-tool_lifecycle/wiki/List-of-Additional-Subplugins) ([subpluginslist](https://github.com/learnweb/moodle-tool_lifecycle/wiki/List-of-Additional-Subplugins)).
It provides instructions for administrators as well as for developers to implement their own requirements into subplugins.

Installation
============
Expand All @@ -31,7 +32,7 @@ Moodle version
==============
The plugin is continously tested with all moodle versions, which are security supported by the moodle headquarter.
Therefore, Travis uses the most current release to build a test instance and run the behat and unit tests on them.
In addition to all stable branches the version is also tested against the master branch to support early adopters.
In addition to all stable branches the version is tested against the master branch to support early adopters.

Changelog
=========
Expand Down
1 change: 1 addition & 0 deletions activeprocesses.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_login();
Expand Down
2 changes: 1 addition & 1 deletion activeworkflows.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
'inputname' => 'search',
'extraclasses' => 'mb-3',
'inform' => false,
'searchstring' => 'Search for courses'
'searchstring' => 'Search for courses',
]);

echo $OUTPUT->heading(get_string('active_automatic_workflows_heading', 'tool_lifecycle'));
Expand Down
10 changes: 5 additions & 5 deletions classes/event/process_proceeded.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ class process_proceeded extends \core\event\base {
* @throws \dml_exception
*/
public static function event_from_process($process) {
$data = array(
$data = [
'context' => \context_system::instance(),
'other' => array(
'other' => [
'processid' => $process->id,
'workflowid' => $process->workflowid,
'stepindex' => $process->stepindex,
'courseid' => $process->courseid
)
);
'courseid' => $process->courseid,
],
];
return self::create($data);
}

Expand Down
10 changes: 5 additions & 5 deletions classes/event/process_rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ class process_rollback extends \core\event\base {
* @throws \dml_exception
*/
public static function event_from_process($process) {
$data = array(
$data = [
'context' => \context_system::instance(),
'other' => array(
'other' => [
'processid' => $process->id,
'workflowid' => $process->workflowid,
'stepindex' => $process->stepindex,
'courseid' => $process->courseid
)
);
'courseid' => $process->courseid,
],
];
return self::create($data);
}

Expand Down
10 changes: 5 additions & 5 deletions classes/event/process_triggered.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ class process_triggered extends \core\event\base {
* @throws \dml_exception
*/
public static function event_from_process($process) {
$data = array(
$data = [
'context' => \context_system::instance(),
'other' => array(
'other' => [
'processid' => $process->id,
'workflowid' => $process->workflowid,
'courseid' => $process->courseid
)
);
'courseid' => $process->courseid,
],
];
return self::create($data);
}

Expand Down
50 changes: 47 additions & 3 deletions classes/local/backup/restore_lifecycle_workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use tool_lifecycle\local\entity\step_subplugin;
use tool_lifecycle\local\entity\trigger_subplugin;
use tool_lifecycle\local\entity\workflow;
use tool_lifecycle\local\manager\lib_manager;
use tool_lifecycle\local\manager\workflow_manager;
use tool_lifecycle\local\manager\step_manager;
use tool_lifecycle\local\manager\trigger_manager;
Expand Down Expand Up @@ -65,20 +66,29 @@ public function __construct($xmldata) {
* Executes the restore process. It loads the workflow with all steps and triggers from the xml data.
* If all data is valid, it restores the workflow with all subplugins and settings.
* Otherwise an array with error strings is returned.
* @param bool $force force import, even if there are errors.
* @return string[] Errors, which occurred during the restore process.
* @throws \coding_exception
* @throws \moodle_exception
*/
public function execute() {
public function execute(bool $force = false) {
$this->reader->read();

$this->load_workflow();
// If the workflow could be loaded continue with the subplugins.
if ($this->workflow) {
$this->load_subplugins();

if (!$this->all_subplugins_installed()) {
return $this->errors;
}

// Validate the subplugin data.
if (empty($this->errors) && $this->all_subplugins_installed()) {
$this->check_subplugin_validity();
if (empty($this->errors) || $force) {
// If all loaded data is valid, the new workflow and the steps can be stored in the database.
// If we force the import, we empty the errors.
$this->errors = [];
$this->persist();
}
}
Expand All @@ -101,7 +111,6 @@ private function load_workflow() {
$this->workflow->timeactive = null;
$this->workflow->timedeactive = null;
$this->workflow->sortindex = null;
workflow_manager::insert_or_update($this->workflow);
}

/**
Expand Down Expand Up @@ -174,6 +183,41 @@ private function all_subplugins_installed() {
return true;
}

/**
* Calls the subplugins to check the consistency and validity of the step and trigger settings.
*/
private function check_subplugin_validity() {
foreach ($this->steps as $step) {
$steplib = lib_manager::get_step_lib($step->subpluginname);
$filteredsettings = [];
foreach ($this->settings as $setting) {
if ($setting->pluginid === $step->id) {
$filteredsettings[$setting->name] = $setting->value;
}
}
$errors = array_map(
fn($x) => get_string('restore_error_in_step', 'tool_lifecycle', $step->instancename) . $x,
$steplib->ensure_validity($filteredsettings)
);
$this->errors = array_merge($this->errors, $errors);
}

foreach ($this->trigger as $trigger) {
$steplib = lib_manager::get_trigger_lib($trigger->subpluginname);
$filteredsettings = [];
foreach ($this->settings as $setting) {
if ($setting->pluginid === $trigger->id) {
$filteredsettings[$setting->name] = $setting->value;
}
}
$errors = array_map(
fn($x) => get_string('restore_error_in_trigger', 'tool_lifecycle', $trigger->instancename) . $x,
$steplib->ensure_validity($filteredsettings)
);
$this->errors = array_merge($this->errors, $errors);
}
}

/**
* Stores all loaded data in the database.
* @throws \moodle_exception
Expand Down
4 changes: 2 additions & 2 deletions classes/local/form/form_courses_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public function definition() {
$mform->setType('fullname', PARAM_TEXT);

// Edited from $this->add_action_buttons to allow custom cancel text.
$buttonarray = array();
$buttonarray = [];
$buttonarray[] = &$mform->createElement('submit', 'submitbutton',
get_string('apply', 'tool_lifecycle'));
$buttonarray[] = &$mform->createElement('cancel', 'cancel', get_string('reset'));
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
$mform->closeHeaderBefore('buttonar');
}

Expand Down
2 changes: 1 addition & 1 deletion classes/local/form/form_delays_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function definition() {
$activeworkflows = workflow_manager::get_active_workflows();
$workflowoptions = [
'' => get_string('all_delays', 'tool_lifecycle'),
'global' => get_string('globally', 'tool_lifecycle')
'global' => get_string('globally', 'tool_lifecycle'),
];
foreach ($activeworkflows as $activeworkflow) {
// Only show non-static workflows.
Expand Down
4 changes: 2 additions & 2 deletions classes/local/form/form_step_instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ private function add_cancel_button() {
$mform =& $this->_form;

// Add a group 'buttonar' to allow excluding it from freezing.
$buttonarray = array();
$buttonarray = [];
$buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
$mform->closeHeaderBefore('buttonar');
}

Expand Down
Loading

0 comments on commit 7878b84

Please sign in to comment.