Skip to content

Commit

Permalink
Merge branch 'ngandrass:master' into MBS-8820_Add_pdf_coversheet_hand…
Browse files Browse the repository at this point in the history
…ling
  • Loading branch information
tholudwig authored Jul 18, 2024
2 parents e010f2a + e22f9d8 commit 7a394b6
Show file tree
Hide file tree
Showing 68 changed files with 5,595 additions and 1,633 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/moodle-plugin-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ jobs:
- {moodle-branch: 'MOODLE_403_STABLE', php: '8.2', database: 'pgsql'}
- {moodle-branch: 'MOODLE_403_STABLE', php: '8.2', database: 'mariadb'}

# Moodle 4.4, PHP 8.1 to 8.3, PostgreSQL and MariaDB
- {moodle-branch: 'MOODLE_404_STABLE', php: '8.1', database: 'pgsql'}
- {moodle-branch: 'MOODLE_404_STABLE', php: '8.1', database: 'mariadb'}
- {moodle-branch: 'MOODLE_404_STABLE', php: '8.2', database: 'pgsql'}
- {moodle-branch: 'MOODLE_404_STABLE', php: '8.2', database: 'mariadb'}
- {moodle-branch: 'MOODLE_404_STABLE', php: '8.3', database: 'pgsql'}
- {moodle-branch: 'MOODLE_404_STABLE', php: '8.3', database: 'mariadb'}
steps:
- name: Check out repository code
uses: actions/checkout@v3
Expand Down Expand Up @@ -99,10 +106,9 @@ jobs:
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpmd

# FIXME: Re-enable this step
#- name: Moodle Code Checker
# if: ${{ !cancelled() }}
# run: moodle-plugin-ci phpcs --max-warnings 0
- name: Moodle Code Checker
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpcs --max-warnings 0

- name: Moodle PHPDoc Checker
if: ${{ !cancelled() }}
Expand Down
61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
# Changelog

## Version 1.2.10 (2024070900)

- Full code overhaul to comply with the [Moodle Coding Style](https://moodledev.io/general/development/policies/codingstyle)
- Enforce strict coding style checks during CI runs / prior to any new releases
- Improve English and German translations


## Version 1.2.9 (2024070800)

- Synchronize default job timeout setting with quiz archive worker and add hint about the additional timeout inside the
archive worker config
- Describe different job timeout settings inside the "Known Pitfalls" section of
the README file.
- Fix display of variables in archive / report names help texts in Moodle <= 4.2

_Note: Keep in mind to update your
[Quiz Archive Worker](https://github.com/ngandrass/moodle-quiz-archive-worker) too!_


## Version 1.2.8 (2024052900)

- Fix autoinstall admin UI form for Moodle 4.1 (LTS)
- Fix edge case during GDPR exports via the Moodle privacy API when using PHP 7.4
- Fix webservice token generation on Moodle 4.1 (LTS)
- Largely extend the test coverage. Now almost everything is tested automatically
for all combinations of:
- Moodle version: 4.1 - 4.4
- PHP versions: 7.4 - 8.3
- Database backends: mariadb, pgsql
- Cleanup attempt report generation code
- Provide documentation how to run tests locally
- Fix typos

_Note: Keep in mind to update your
[Quiz Archive Worker](https://github.com/ngandrass/moodle-quiz-archive-worker) too!_


## Version 1.2.7 (2024051300)

- Fix inlining of images with filenames that contains URL encoded characters (e.g., `image (1).jpg`)
- Fix inlining of Moodle theme icons (e.g., drag and drop markers)
- Fix PHP warning on quiz_archiver_generate_attempt_report webservice call
- Fix quiz header / summary table injection in Moodle 4.4+
- Replace deprecated Moodle 4.4+ language strings


## Version 1.2.6 (2024042900)

- Extend automated tests to cover Moodle 4.4 with PHP 8.1 to 8.3 using PostgreSQL and MariaDB
- Removal of deprecated function use for Moodle 4.4 (See MDL-67667)


## Version 1.2.5 (2024040900)

- Add an automatic plugin configuration feature, to simplify the setup process (#15 - Thanks to @melanietreitinger)
- Display a welcome message with setup instructions during plugin installation
- Add support for automated configuration using a CLI script
- Add error message during job creation, when plugin is not fully configured yet
- Create quizzes with 100, 250, 500, and 1000 attempts in the reference course `res/backup-moodle2-course-qa-ref.mbz`
- Update installation instructions in README.md to reflect the new setup process


## Version 1.2.4 (2024021901)

Expand Down
90 changes: 85 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ permissions, setup a webservice for the archive worker, and set configuration
options for the Moodle plugin.


### 1. Prerequisites
### Prerequisites

Installation of the additional [quiz archive worker service](https://github.com/ngandrass/moodle-quiz-archive-worker)
is mandatory for this plugin to work.
Expand All @@ -137,7 +137,81 @@ is mandatory for this plugin to work.
[Quiz Archive Worker: Installation](https://github.com/ngandrass/moodle-quiz-archive-worker#installation)**


### 2. Create Moodle User and Role
### Automatic Configuration

Creation of the dedicated Moodle user and role, as well as the setup of the
webservice for the archive worker, can be done automatically.

The easiest way is to use the automatic configuration feature provided via the
Moodle admin interface.

1. Navigate to _Site Administration_ > _Plugins_ (1) > _Activity modules_ >
_Quiz_ > _Quiz Archiver_ (2)
2. Click the _Automatic configuration_ button (3)
3. Enter the URL under which the quit archive worker can be reached (4)
4. (Optional) Change the configuration defaults (5)
5. Execute the automatic configuration (6)
6. Close the window (7)
7. (Optional) Adjust the default plugin setting on the plugin settings page

[![Screenshot: Configuration - Automatic Configuration 1](doc/configuration/configuration_plugin_settings_1_thumb.png)](doc/configuration/configuration_plugin_settings_1.png)
[![Screenshot: Configuration - Automatic Configuration 2](doc/configuration/configuration_plugin_autoinstall_2_thumb.png)](doc/configuration/configuration_plugin_autoinstall_2.png)
[![Screenshot: Configuration - Automatic Configuration 3](doc/configuration/configuration_plugin_autoinstall_3_thumb.png)](doc/configuration/configuration_plugin_autoinstall_3.png)
[![Screenshot: Configuration - Automatic Configuration 4](doc/configuration/configuration_plugin_autoinstall_4_thumb.png)](doc/configuration/configuration_plugin_autoinstall_4.png)


#### Using the Command Line Interface (CLI)

<details>
<summary><b>Expand here to show CLI configuration instructions</b></summary>

If you want to configure this plugin in an automated fashion, you can use the
provided CLI script. The script is located at
`{$CFG->wwwroot}/mod/quiz/report/archiver/cli/autoinstall.php`.

To execute the script:

1. Open a terminal and navigate to the quiz archiver CLI directory:
```bash
cd /path/to/moodle/mod/quiz/report/archiver/cli
```
2. Execute the CLI script using PHP:
```bash
php autoinstall.php --help
```

Usage:
```text
Automatically configures Moodle for use with the quiz archiver plugin.
ATTENTION: This CLI script ...
- Enables web services and REST protocol
- Creates a quiz archiver service role and a corresponding user
- Creates a new web service with all required webservice functions
- Authorises the user to use the webservice.
Usage:
$ php autoinstall.php
$ php autoinstall.php --username="my-custom-archive-user"
$ php autoinstall.php [--help|-h]
Options:
--help, -h Show this help message
--force, -f Force the autoinstall, regardless of the current state of the system
--workerurl=<value> Sets the URL of the worker (default: http://localhost:8080)
--wsname=<value> Sets a custom name for the web service (default: quiz_archiver_webservice)
--rolename=<value> Sets a custom name for the web service role (default: quiz_archiver)
--username=<value> Sets a custom username for the web service user (default: quiz_archiver_serviceaccount)
```
</details>


### Manual Configuration

<details>
<summary><b>Expand here to show manual configuration instructions</b></summary>

### 1. Create Moodle User and Role

1. Create a designated Moodle user for the quiz archiver webservice
1. Navigate to _Site Administration_ > _Users_ (1) > _Accounts_ > _Add a new user_ (2)
Expand Down Expand Up @@ -174,8 +248,7 @@ is mandatory for this plugin to work.
[![Screenshot: Configuration - Assign Role 2](doc/configuration/configuration_assign_role_2_thumb.png)](doc/configuration/configuration_assign_role_2.png)
[![Screenshot: Configuration - Assign Role 3](doc/configuration/configuration_assign_role_3_thumb.png)](doc/configuration/configuration_assign_role_3.png)


### 3. Setup Webservice
### 2. Setup Webservice

1. Enable webservices globally
1. Navigate to _Site Administration_ > _Server_ (1) > _Web services_ > _Overview_ (2)
Expand Down Expand Up @@ -215,7 +288,7 @@ is mandatory for this plugin to work.
[![Screenshot: Configuration - Assign Webservice Functions 4](doc/configuration/configuration_assign_webservice_functions_4_thumb.png)](doc/configuration/configuration_assign_webservice_functions_4.png)


### 4. Configure Plugin Settings
### 3. Configure Plugin Settings

1. Navigate to _Site Administration_ > _Plugins_ (1) > _Activity modules_ >
_Quiz_ > _Quiz Archiver_ (2)
Expand All @@ -238,9 +311,16 @@ is mandatory for this plugin to work.
[![Screenshot: Configuration - Plugin Settings 1](doc/configuration/configuration_plugin_settings_1_thumb.png)](doc/configuration/configuration_plugin_settings_1.png)
[![Screenshot: Configuration - Plugin Settings 2](doc/configuration/configuration_plugin_settings_2_thumb.png)](doc/configuration/configuration_plugin_settings_2.png)

</details>

### Known Pitfalls

- **Job timeout prior to configured value**
- Be aware that there is a configurable job timeout within the Moodle plugin
settings (`quiz_archiver | job_timeout_min`) as well as one within the quiz
archive worker service (`QUIZ_ARCHIVER_REQUEST_TIMEOUT_SEC`). Since the
shortest timeout always takes precedence, make sure to adjust both settings
as required.
- **Access to (some) webservice functions fails**
- Ensure that webservices and the REST protocol are enabled globally.
- Ensure that all required webservice functions are enabled for the
Expand Down
71 changes: 71 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Testing

**ATTENTION:** The following notes are meant **for developers only**. If you only want
to use this plugin you can fully ignore this file.


## Creating a PHPUnit test environment

See: https://moodledev.io/general/development/tools/phpunit

1. Spawn a shell inside your Moodle/php-fpm container and navigate to your
Moodle root directory:
```bash
docker exec -it my-moodle-container sh
cd /usr/share/nginx/www/moodle/
```
2. Prepare PHPUnit configuration. Add the following lines to your `config.php`:
```php
$CFG->phpunit_prefix = 'phpu_';
$CFG->phpunit_dataroot = '/path/to/your/phpunit_moodledata';
```
3. Download composer and install dev dependencies:
```bash
wget https://getcomposer.org/download/latest-stable/composer.phar
php composer.phar install
```
4. Bootstrap test environment:
```bash
php admin/tool/phpunit/cli/init.php --disable-composer
```


## Running tests

- Run all tests:
```bash
vendor/bin/phpunit --colors --testdox
```
- Run all tests for a single component:
```bash
vendor/bin/phpunit --colors --testdox --filter quiz_archiver/*
```
- Run a single test suite:
```bash
vendor/bin/phpunit --colors --testdox mod/quiz/report/archiver/tests/Report_test.php
```

### Automatic test execution for all supported software configurations

The configuration for automated test execution via GitHub CI can be found in
`.github/workflows/moodle-plugin-ci.yml`. It holds a matrix of all supported
software configurations and runs the tests for each of them.


## Generating code coverage reports

**You need to have xdebug installed and enabled in order to generate coverage
reports!**

1. Run PHPUnit with coverage report:
```bash
XDEBUG_MODE=coverage vendor/bin/phpunit --colors --testdox --coverage-html /tmp/coverage --filter quiz_archiver/*
```
2. Copy the generated report to your machin:
```bash
docker cp my-moodle-container:/tmp/coverage /tmp/coverage
```
3. Open the report in your browser:
```bash
xdg-open /tmp/coverage/index.html
```
94 changes: 94 additions & 0 deletions adminui/autoinstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Handler for autoinstall feature from the admin UI of the quiz archiver plugin.
*
* @package quiz_archiver
* @copyright 2024 Niels Gandraß <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(__DIR__.'/../../../../../config.php');
require_once("{$CFG->libdir}/moodlelib.php");
require_once("{$CFG->dirroot}/mod/quiz/report/archiver/classes/form/autoinstall_form.php");

use quiz_archiver\form\autoinstall_form;
use quiz_archiver\local\autoinstall;

/** @var bool Disables output buffering */
const NO_OUTPUT_BUFFERING = true;

// Ensure user has permissions.
require_login();
$ctx = context_system::instance();
require_capability('moodle/site:config', $ctx);

// Setup page.
$PAGE->set_context($ctx);
$PAGE->set_url('/mod/quiz/report/archiver/adminui/autoinstall.php');
$title = get_string('autoinstall_plugin', 'quiz_archiver');
$PAGE->set_title($title);

$returnlink = html_writer::link(
new moodle_url('/admin/settings.php', ['section' => 'quiz_archiver_settings']),
get_string('back')
);

echo $OUTPUT->header();
echo $OUTPUT->heading($title);

// Content.
if (autoinstall::plugin_is_unconfigured()) {
$form = new autoinstall_form();

if ($form->is_cancelled()) {
// Cancelled.
echo '<p>'.get_string('autoinstall_cancelled', 'quiz_archiver').'</p>';
echo '<p>'.$returnlink.'</p>';
} else if ($data = $form->get_data()) {
// Perform autoinstall.
list($success, $log) = autoinstall::execute(
$data->workerurl,
$data->wsname,
$data->rolename,
$data->username
);

// Show result.
echo '<p>'.get_string('autoinstall_started', 'quiz_archiver').'</p>';
echo '<p>'.get_string('logs').'</p>';
echo "<pre>{$log}</pre><br/>";

if ($success) {
echo '<p>'.get_string('autoinstall_success', 'quiz_archiver').'</p>';
} else {
echo '<p>'.get_string('autoinstall_failure', 'quiz_archiver').'</p>';
}

echo '<p>'.$returnlink.'</p>';
} else {
echo '<p>'.get_string('autoinstall_explanation', 'quiz_archiver').'</p>';
echo '<p>'.get_string('autoinstall_explanation_details', 'quiz_archiver').'</p>';
$form->display();
}
} else {
echo '<p>'.get_string('autoinstall_already_configured_long', 'quiz_archiver').'</p>';
echo '<p>'.$returnlink.'</p>';
}

// End page.
echo $OUTPUT->footer();
Loading

0 comments on commit 7a394b6

Please sign in to comment.