Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subplugin refactor rebase #1

Merged
merged 26 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ddb70d8
Add check if process exists. (#191)
melanietreitinger Dec 4, 2023
ff6e322
Update README.md
NinaHerrmann Dec 20, 2023
38d6dc7
Improve help text for integration of icons (manual trigger) (#193)
KerstinSc Jan 16, 2024
421cc45
Update for Moodle 4.3 (#190)
justusdieckmann Feb 20, 2024
a1166ed
Hide menu when there is no manual workflow (#195)
justusdieckmann Feb 20, 2024
2a33a60
Fix step and trigger reordering: only change the relevant workflow (#…
olivabigyo Mar 14, 2024
f1ef4a6
Reorder the remaining active workflows when disabling a workflow (#201)
olivabigyo Mar 14, 2024
33cbd05
Show menu entry when a manual or automatic workflow is active (#199)
justusdieckmann Mar 14, 2024
920d1f9
Check backup consistency before importing workflow (#196)
justusdieckmann Apr 26, 2024
0099ef6
CI: Update for Moodle 4.4
justusdieckmann Mar 22, 2024
f2181c4
Codestyle PHPCBF
justusdieckmann Mar 22, 2024
85a8755
Sort strings in lang files alphabetically
justusdieckmann Apr 4, 2024
28ba40a
Fix sortindex gaps in upgrade step
justusdieckmann Apr 24, 2024
3c74651
Bump version
justusdieckmann Apr 23, 2024
7c986c9
The columns in active_manual_workflows_table shouldn't be sortable
justusdieckmann Apr 26, 2024
ba1dc92
Merge pull request #206 from learnweb/fix/manual-workflow-table-sort
justusdieckmann Apr 26, 2024
42edc87
Merge pull request #204 from learnweb/update/m404
justusdieckmann Apr 26, 2024
e2ba531
Shell escape the release notes in the release workflow (#207)
NinaHerrmann May 2, 2024
ee73f9b
Fix mustache
justusdieckmann May 8, 2024
bd2aca6
Merge pull request #210 from learnweb/fix/mustache
justusdieckmann May 13, 2024
05ff0e2
added mtrace statement for logging failed mails (#214)
NinaHerrmann Jun 11, 2024
95a4b22
Shell escape release workflow for realsies this time (#208)
justusdieckmann Jun 11, 2024
933158b
Missing cachedef_application string (#220)
sharpchi Jun 25, 2024
f0c0fd9
fix moodle code checker issues
NinaHerrmann Jun 25, 2024
9640f15
issue#178 refactor subplugins calls
Sep 4, 2023
1142d4b
Merge branch 'subplugin_refactor' into subplugin_refactor_rebase
jay-oswald Aug 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading