Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main' into PM-43593…
Browse files Browse the repository at this point in the history
…-grading
  • Loading branch information
mk-kialo committed Oct 14, 2024
2 parents 3d93be4 + d54e08e commit de350d5
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 125 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
name: Moodle Plugin CI

on: [ push, pull_request ]
on: [ push, pull_request, workflow_dispatch ]

jobs:
test:
Expand Down Expand Up @@ -45,15 +45,19 @@ jobs:
- '7.4' # minimum support version by Moodle 4.1
- '8.0'
- '8.1'
- '8.3' # max. supported version by Moodle 4.4 (as of writing)
moodle-branch: [ 'MOODLE_401_STABLE', 'MOODLE_404_STABLE' ] # LTS & latest.
- '8.3' # max. supported version by Moodle 4.5 (as of writing)
moodle-branch: [ 'MOODLE_401_STABLE', 'MOODLE_405_STABLE', 'main' ] # LTS & latest.
database: [ pgsql ] # We don't use any database specific features, and our test sites run mariadb already.
exclude:
# Moodle 4.4+ requires PHP 8.1+
- php: '8.0'
moodle-branch: 'MOODLE_404_STABLE'
moodle-branch: 'MOODLE_405_STABLE'
- php: '8.0'
moodle-branch: 'main'
- php: '7.4'
moodle-branch: 'MOODLE_405_STABLE'
- php: '7.4'
moodle-branch: 'MOODLE_404_STABLE'
moodle-branch: 'main'
# Moodle 4.1 does not support PHP 8.3
- php: '8.3'
moodle-branch: 'MOODLE_401_STABLE'
Expand Down
3 changes: 3 additions & 0 deletions classes/admin/kialo_configcheckbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class kialo_configcheckbox extends admin_setting_configcheckbox {
*/
public function force_readonly(bool $forcereadonly) {
$this->forcereadonly = $forcereadonly;

// If the checkbox is read-only, it should not be saved. It would be reset to its default otherwise when saving.
$this->nosave = $forcereadonly;
}

/**
Expand Down
21 changes: 18 additions & 3 deletions classes/kialo_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,27 @@ public static function get_release(): string {
* @return array|string
*/
public function get_tool_url() {
$targeturlfromconfig = get_config('mod_kialo', 'kialourl'); // See settings.php.
$targeturlfromenv = getenv('TARGET_KIALO_URL');
if (!empty($targeturlfromenv)) {
return $targeturlfromenv;

if (!empty($targeturlfromconfig)) {
$kialourl = $targeturlfromconfig;

// Is the URL valid?
if (!filter_var($kialourl, FILTER_VALIDATE_URL)) {
throw new \dml_exception("Invalid Kialo URL: $kialourl");
}
} else if (!empty($targeturlfromenv)) {
$kialourl = $targeturlfromenv;
} else {
return "https://www.kialo-edu.com";
$kialourl = "https://www.kialo-edu.com";
}

// Ensure $kialourl is a proper URL and does not have a trailing slash.
if (!preg_match('/^https?:\/\//', $kialourl)) {
$kialourl = "https://" . $kialourl;
}
return rtrim($kialourl, '/');
}

/**
Expand Down
7 changes: 7 additions & 0 deletions development/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ MOODLE_HOST=192.168.X.X:8080
# and use that, since `moodle` is the hostname of the Moodle Docker container,
# which is accessible from within the Kialo Docker container.
# MOODLE_HOST=moodle:8080

# Moodle branch to use. By default we use the latest version (the `main` branch).
# If you want to use a specific other version, use the corresponding branch name.
# For example MOODLE_405_STABLE for Moodle 4.5. See https://github.com/moodle/moodle/branches.
# Note: If you change your Moodle branch, the Docker image needs to be rebuilt,
# by running `docker compose up --build`.
MOODLE_BRANCH=main
1 change: 1 addition & 0 deletions development/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
moodle/
moodle_mod/
.env

## Bundle
Expand Down
8 changes: 7 additions & 1 deletion development/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ This also enables web services for mobile (required for the mobile app) and enab
By default there is only one user with the username "user" and password "kialo1234". This is the admin user.

The folder `moodle` is mounted locally in the `development` folder. To test changes to the plugin code,
you can use `development/sync.sh` to copy over the code into the `moodle/mod/kialo` folder.
you can use `development/sync.sh` to copy over the code into the `moodle/mod/kialo` folder.A

### Moodle versions

The Docker setup is configured to run the latest moodle version (`main` branch) by default.
If you want to run a specific version, like one of the LTS versions, you can change the `MOODLE_VERSION` in the `.env` file.
See `.env.example` for details.

### Using the Moodle Mobile app

Expand Down
84 changes: 0 additions & 84 deletions development/config/config.php

This file was deleted.

32 changes: 21 additions & 11 deletions development/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
# https://hub.docker.com/r/bitnami/moodle
version: '2'
name: mod_kialo
services:
mariadb:
image: docker.io/bitnami/mariadb:10.6
image: docker.io/bitnami/mariadb:10.7
ports:
- '8833:3306'
- '8443:443'
environment:
# ALLOW_EMPTY_PASSWORD is recommended only for development.
- ALLOW_EMPTY_PASSWORD=yes
- MARIADB_USER=bn_moodle
- MARIADB_DATABASE=bitnami_moodle
- MARIADB_USER=moodle
- MARIADB_DATABASE=moodle
- MARIADB_CHARACTER_SET=utf8mb4
- MARIADB_COLLATE=utf8mb4_unicode_ci
# liveness probe
healthcheck:
test: ["CMD", "mysqladmin", "status", "-uroot"]
interval: 2s
timeout: 1s
retries: 10
moodle:
image: docker.io/bitnami/moodle:4.4
build:
dockerfile: Dockerfile
context: moodleimage
args:
# main (latest), MOODLE_405_STABLE etc, see https://github.com/moodle/moodle/branches
MOODLE_BRANCH: ${MOODLE_BRANCH:-main}
# 7.4, 8.0, 8.1, 8.3 etc., see https://moodledev.io/general/development/policies/php
PHP_VERSION: ${PHP_VERSION:-8.1}
ports:
- '8080:8080'
- '8080:80'
environment:
- MOODLE_DATABASE_HOST=mariadb
- MOODLE_DATABASE_PORT_NUMBER=3306
- MOODLE_DATABASE_USER=bn_moodle
- MOODLE_DATABASE_NAME=bitnami_moodle
- ALLOW_EMPTY_PASSWORD=yes
- MOODLE_PASSWORD=kialo1234
# you can override the following by creating a .env file in the same directory as this file
- TARGET_KIALO_URL=${TARGET_KIALO_URL:-http://localhost:5000}
- MOODLE_HOST=${MOODLE_HOST:-localhost:8080}
- MOODLE_HOST=http://${MOODLE_HOST:-localhost:8080}
volumes:
- './moodle:/bitnami/moodle'
- './moodle_mod:/var/www/html/mod/kialo'
depends_on:
- mariadb
moodleapp:
Expand Down
20 changes: 20 additions & 0 deletions development/moodleimage/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# See https://moodledev.io/general/development/policies/php for the list of available PHP versions.
# Different versions of Moodle require different versions of PHP.
ARG PHP_VERSION="8.1"

FROM moodlehq/moodle-php-apache:${PHP_VERSION}

# See https://moodledev.io/general/releases for the list of available versions.
# See https://github.com/moodle/moodle/branches for the available branches.
# Branch names follow the pattern MOODLE_XYZ_STABLE, e.g. MOODLE_404_STABLE for Moodle 4.4.
# main is the default and most up-to-date branch, it includes upcoming versions before they are stable.
ARG MOODLE_BRANCH="main"
ENV MOODLE_BRANCH=${MOODLE_BRANCH}

RUN git clone git://git.moodle.org/moodle.git /var/www/html --depth=1 --branch ${MOODLE_BRANCH}

COPY entrypoint.sh /usr/local/bin/entrypoint.sh
COPY config.php /var/www/html/config_kialo.php

ENTRYPOINT ["entrypoint.sh"]
CMD ["apache2-foreground"]
39 changes: 39 additions & 0 deletions development/moodleimage/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

// phpcs:ignoreFile
// Custom Moodle configuration. Is appended to Moodle's own config.php.

global $CFG;

// Allow arbitrary hostname (by default it's hardcoded).
if (empty($_SERVER['HTTP_HOST'])) {
$_SERVER['HTTP_HOST'] = '127.0.0.1:8080';
}
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$CFG->wwwroot = 'https://' . $_SERVER['HTTP_HOST'];
} else {
$CFG->wwwroot = 'http://' . $_SERVER['HTTP_HOST'];
}

//=========================================================================
// PHPUNIT SUPPORT
//=========================================================================
$CFG->phpunit_prefix = 'phpu_';
$CFG->phpunit_dataroot = '/var/www/moodledata/phpunit';
$CFG->phpunit_directorypermissions = 02777; // optional
$CFG->phpunit_profilingenabled = true; // optional to profile PHPUnit runs.

//=========================================================================
// Custom settings for development
//=========================================================================

// Force a debugging mode regardless the settings in the site administration
@error_reporting(E_ALL | E_STRICT); // NOT FOR PRODUCTION SERVERS!
@ini_set('display_errors', '1'); // NOT FOR PRODUCTION SERVERS!
$CFG->debug = (E_ALL | E_STRICT); // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS!
$CFG->debugdisplay = 1; // NOT FOR PRODUCTION SERVERS!

// Make sure that the temp directories are not deleted during the backup process. Allows easier testing of the backup process.
$CFG->keeptempdirectoriesonbackup = true;

require_once(__DIR__ . '/lib/setup.php');
11 changes: 11 additions & 0 deletions development/moodleimage/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Install Moodle. See https://docs.moodle.org/404/en/Installing_Moodle#Command_line_installer
chown -R www-data /var/www/html
su - www-data -s /bin/bash -c "php /var/www/html/admin/cli/install.php --non-interactive --agree-license --allow-unstable --wwwroot=$MOODLE_HOST --dataroot=/var/www/moodledata --dbtype=mariadb --dbhost=$MOODLE_DATABASE_HOST --dbname=moodle --dbuser=moodle --dbport=$MOODLE_DATABASE_PORT_NUMBER --fullname=Moodle --shortname=moodle --adminuser=user --adminpass=$MOODLE_PASSWORD [email protected] [email protected]"

# Amend the config.php file to include our own config for development.
# The line should be added before the last line "require_once(__DIR__ . '/lib/setup.php');".
sed -i '/require_once/i\require_once(__DIR__ . "/config_kialo.php");' /var/www/html/config.php

exec /usr/local/bin/moodle-docker-php-entrypoint "$@"
8 changes: 1 addition & 7 deletions development/sync.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# Ensure this script is executed in the same folder
cd "$(dirname "$0")"

# Ensure the directory exists
mkdir -p ./moodle/mod/kialo

# syncs the content of the development version of this plugin to the copy in the docker moodle installation (/moodle/mod/kialo)
rsync -atm --delete --delete-excluded --exclude={'/development','/.[!.]*'} .. ./moodle/mod/kialo
rsync -atm --delete --delete-excluded --exclude={'/development','/.[!.]*'} .. ./moodle_mod
echo "Synced plugin."

cp config/config.php moodle/config.php
echo "Synced config.php"
2 changes: 1 addition & 1 deletion development/tests-init.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# needs to run once initially and again whenever new tests are added
docker exec -i development-moodle-1 /bin/bash -c "cd /bitnami/moodle; php admin/tool/phpunit/cli/init.php"
docker exec -i mod_kialo-moodle-1 /bin/bash -c "cd /var/www/html; php admin/tool/phpunit/cli/init.php"
5 changes: 4 additions & 1 deletion development/tests-privacy.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Ensure files are up-to-date
./sync.sh

# Run the tests
docker exec -i development-moodle-1 /bin/bash -c "cd /bitnami/moodle; vendor/bin/phpunit --testsuite core_privacy_testsuite --filter kialo"
docker exec -i mod_kialo-moodle-1 /bin/bash -c "cd /var/www/html; vendor/bin/phpunit --testsuite core_privacy_testsuite --filter kialo"
5 changes: 4 additions & 1 deletion development/tests-run-all.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Ensure files are up-to-date
./sync.sh

# Run the tests
docker exec -i development-moodle-1 /bin/bash -c "cd /bitnami/moodle; vendor/bin/phpunit --testsuite mod_kialo_testsuite"
docker exec -i mod_kialo-moodle-1 /bin/bash -c "cd /var/www/html; vendor/bin/phpunit --testsuite mod_kialo_testsuite"
5 changes: 4 additions & 1 deletion development/tests-run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Ensure files are up-to-date
./sync.sh

# Run a specific test file (path relative to mod/kialo/tests)
# Example: ./tests-run.sh classes/mod_kialo_test.php
docker exec -i development-moodle-1 /bin/bash -c "cd /bitnami/moodle; vendor/bin/phpunit mod/kialo/tests/$1"
docker exec -i mod_kialo-moodle-1 /bin/bash -c "cd /var/www/html; vendor/bin/phpunit mod/kialo/tests/$1"
2 changes: 2 additions & 0 deletions lang/en/kialo.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
$string['kialofieldset'] = 'Kialo Fieldset';
$string['kialoname'] = 'Activity Name';
$string['kialosettings'] = 'Settings';
$string['kialourl'] = 'Kialo URL';
$string['kialourl_desc'] = 'The URL of the Kialo instance to use.';
$string['modulename'] = 'Kialo Discussion';
$string['modulename_help'] = 'The Kialo Discussion activity allows you to include a Kialo discussion in your Moodle course. Students can participate in the discussion directly from Moodle, without having to manually create Kialo accounts. Kialo discussions are a great way to teach and train critical thinking, argumentation and to facilitate thoughtful classroom discussions.';
$string['modulename_link'] = 'https://support.kialo-edu.com/en/hc/moodle';
Expand Down
Loading

0 comments on commit de350d5

Please sign in to comment.