diff --git a/assets/adminer/plugins/001-tables-filter.php b/assets/adminer/plugins/001-tables-filter.php new file mode 100644 index 00000000000..c2265a32e97 --- /dev/null +++ b/assets/adminer/plugins/001-tables-filter.php @@ -0,0 +1,4 @@ +adminer = $adminer; + } + + private function _testJson($value) { + if ((substr($value, 0, 1) == '{' || substr($value, 0, 1) == '[') && ($json = json_decode($value, true))) { + return $json; + } + return $value; + } + + function editInput($table, $field, $attrs, $value) { + $json = $this->_testJson($value); + if ($json !== $value) { + $jsonText = json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + return <<$jsonText +HTML; + } + return ''; + } + + function processInput($field, $value, $function = '') { + if ($function === '') { + $json = $this->_testJson($value); + if ($json !== $value) { + $value = json_encode($json); + } + } + return $this->adminer->_callParent('processInput', array($field, $value, $function)); + } +} diff --git a/assets/adminer/plugins/readable-dates.php b/assets/adminer/plugins/readable-dates.php new file mode 100644 index 00000000000..d9ca75ac16d --- /dev/null +++ b/assets/adminer/plugins/readable-dates.php @@ -0,0 +1,49 @@ +prepend = <<'; + tds[i].innerHTML = tds[i].newDate; + tds[i].dateIsNew = true; + + tds[i].addEventListener('click', function(event) { + this.innerHTML = (this.dateIsNew ? this.oldDate : this.newDate); + this.dateIsNew = !this.dateIsNew; + }); + } + } +}); + +EOT; + } + + function head() { + echo script($this->prepend); + } +} diff --git a/assets/adminer/plugins/table-header-scroll.php b/assets/adminer/plugins/table-header-scroll.php new file mode 100644 index 00000000000..69eace5c3ac --- /dev/null +++ b/assets/adminer/plugins/table-header-scroll.php @@ -0,0 +1,75 @@ +. + * + * LICENSE: + * This program 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. + * + * This program 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 this program. If not, see . + */ +class AdminerTableHeaderScroll +{ + public function head() + { + ?> + +> +function tableHeaderPositionUpdate(){ + // If your theme has a fixed position header, change these for compatibility + var offset = -1; + var zindex = 10000; + + // Find tables in the content + var tables = document.getElementById('content').getElementsByTagName('table'); + for (var i = 0; i < tables.length; i++) { + var table = tables[i]; + + // Find the table header + var tableHeader = table.getElementsByTagName('thead'); + if (tableHeader.length) { + tableHeader = tableHeader[0]; + } else { + continue; + } + + // Calculate the distance from the top and bottom + var tableTop = table.getBoundingClientRect().top - offset; + var tableBottom = table.getBoundingClientRect().bottom - offset - tableHeader.offsetHeight; + + // Set the relative position based on the distance + if (tableTop < 0 && tableBottom > 0){ + tableHeader.style['z-index'] = zindex; + tableHeader.style.position = 'relative'; + + if (typeof tableHeader.style.transform === 'undefined') { + tableHeader.style.top = -tableTop + 'px'; + } else { + tableHeader.style.transform = 'translateY(' + -tableTop + 'px)'; + } + } else { + tableHeader.style.position = 'static'; + tableHeader.style.transform = 'none'; + } + } +} + +if (window.addEventListener) { + window.addEventListener('scroll', tableHeaderPositionUpdate); +} + + + /dev/null && pwd ) + +SWITCH1=$1 +SWITCH2=$2 +SWITCH3=$3 + +echo "== K1Run ==" +echo + +# make sure that env MOODLE_DOCKER_WWWROOT is set. +if [[ -z "${MOODLE_DOCKER_WWWROOT}" ]]; then + echo "Environment variable MOODLE_DOCKER_WWWROOT has not been set." + echo "Please set it before proceeding # k1run.sh --root /var/www/html" + echo "Exiting." + exit 1 +else + echo "MOODLE_DOCKER_WWWROOT=$MOODLE_DOCKER_WWWROOT. ✔" +fi + +# check if MOODLE_DOCKER_DB is set. +if [[ -z "${MOODLE_DOCKER_DB}" ]]; then + # Always use mariadb as a database. + export MOODLE_DOCKER_DB=mariadb + echo "Setting MOODLE_DOCKER_DB=${MOODLE_DOCKER_DB}. ✔" +else + echo "MOODLE_DOCKER_DB=${MOODLE_DOCKER_DB}. ✔" +fi + +echo "Script path= $basedir." +echo +echo "== == == == == == == == == == == ==" +echo + +# if no argument passed, defaults to --start +if [[ -z "${SWITCH1}" ]]; then + echo "No argument(s) passed, defaulting to --start." + SWITCH1="--start" +fi + +# Help +if [ "$SWITCH1" = "--help" ]; then + echo "Usage: sh run.sh --[command] [argument1] [argument2]" + echo "Script that automates managing docker. See: https://jira.knowledgeone.ca:9443/x/3wCnCQ" + echo "Command --root must be run first to set the Moodle path." + echo + echo "If no parameter is passed then boot and initialize the site." + echo + echo "--start Boot and initialize the site. (default)" + echo "--root Pass absolute path to MOODLE_DOCKER_WWWROOT to set ENV variable." + echo "--build Start the site and initialize the site." + echo "--initdb Drop and re-initialize the Moodle database, with new credential." + echo " With two arguments: [email] [password]" + echo " With no arguments: admin@example.com m@0dl3ing (defaults)" + echo "--reload Reload the site, use existing data" + echo "--down Stop the site. Keep data" + echo "--destroy Stop the site, destory data" + echo "--reboot Restart the site - destroy all containers and re-initialize" + echo "--php Reload php config in assets/php/10-docker-php-moodle.ini" + echo "--phpunit Initialize for phpunit tests" + echo "--behat Initialize for behat tests" + echo "--help Print this message" + +# Root +elif [ "$SWITCH1" = "--root" ]; then + echo "--root : Attempting to set Moodle root directory." + if [[ -d "${SWITCH2}" ]]; then + export MOODLE_DOCKER_WWWROOT=$SWITCH2 + echo "Set MOODLE_DOCKER_WWWROOT=${SWITCH2}" + else + echo "This isn't a valid path: ${SWITCH2}. Exiting." + fi + +# Start +elif [ "$SWITCH1" = "--start" ]; then + # ... + ${basedir}/bin/moodle-docker-compose up -d + +# Init +elif [ "$SWITCH1" = "--initdb" ]; then + if [[ -z "${SWITCH2}" ]] || [[ -z "${SWITCH3}" ]] ; then + # Defaults: admin@example.com m@0dl3ing + ${basedir}/bin/moodle-docker-compose exec webserver php admin/cli/install_database.php --agree-license --fullname="moodle" --shortname="moodle" --summary="K1 Moodle dev" --adminpass="m@0dl3ing" --adminemail="admin@example.com" + echo "Run install_database.php with default credentials: admin@example.com m@0dl3ing." + else + ${basedir}/bin/moodle-docker-compose exec webserver php admin/cli/install_database.php --agree-license --fullname="moodle" --shortname="moodle" --summary="K1 Moodle dev" --adminpass="${SWITCH2}" --adminemail="${SWITCH3}" + echo "Run install_database.php with provided credentials." + fi + +# Build +elif [ "$SWITCH1" = "--build" ]; then + # Start up containers + ${basedir}/bin/moodle-docker-compose up -d + # Wait for DB to come up + ${basedir}/bin/moodle-docker-wait-for-db + # Initialize the database + ${basedir}/bin/moodle-docker-compose exec webserver php admin/cli/install_database.php --agree-license --fullname="K1MOODLE" --shortname="K1MOODLE" --summary="K1 Moodle dev" --adminpass="test" --adminemail="admin@example.com" + +# Down +elif [ "$SWITCH1" = "--down" ]; then + # Stop the containers + ${basedir}/bin/moodle-docker-compose stop + +# Reboot +elif [ "$SWITCH1" = "--reboot" ]; then + # Stop the containers + ${basedir}/bin/moodle-docker-compose down + echo "Wait for it..." + sleep 3 + # Start up containers + ${basedir}/bin/moodle-docker-compose up -d + ${basedir}/bin/moodle-docker-compose exec webserver php admin/cli/install_database.php --agree-license --fullname="K1MOODLE" --shortname="K1MOODLE" --summary="K1 Moodle dev" --adminpass="test" --adminemail="admin@example.com" + +# Load +elif [ "$SWITCH1" = "--reload" ]; then + # Reloads all docker images + ${basedir}/bin/moodle-docker-compose start + +# Reload php setting in webserver image +elif [ "$SWITCH1" = "--php" ]; then + # reloads + ${basedir}/bin/moodle-docker-compose restart webserver + echo "Reloading PHP configuration by restarting webserver image." + +# Behat +elif [ "$SWITCH1" = "--behat" ]; then + # Add in unit tests initialization. + ${basedir}/bin/moodle-docker-compose exec webserver php admin/tool/behat/init.php + +# Destroy +elif [ "$SWITCH1" = "--destroy" ]; then + bin/moodle-docker-compose down + +# PHPUnit +elif [ "$SWITCH1" = "--phpunit" ]; then + # Start up containers + bin/moodle-docker-compose up -d + # Wait for DB to come up + bin/moodle-docker-wait-for-db + bin/moodle-docker-compose exec webserver php admin/tool/phpunit/cli/init.php + +# Behat +elif [ "$SWITCH1" = "--behat" ]; then + # Start up containers + bin/moodle-docker-compose up -d + # Wait for DB to come up + bin/moodle-docker-wait-for-db + bin/moodle-docker-compose exec webserver php admin/tool/behat/cli/init.php + +fi + +exit 1 \ No newline at end of file diff --git a/k1run.sh b/k1run.sh new file mode 100644 index 00000000000..23e124ff963 --- /dev/null +++ b/k1run.sh @@ -0,0 +1,183 @@ +#!/bin/bash + +adminer_plugins () { + # Add in Adminer plugins + docker cp assets/adminer/plugins/readable-dates.php docker-Adminer:/var/www/html/plugins/readable-dates.php + docker cp assets/adminer/plugins/table-header-scroll.php docker-Adminer:/var/www/html/plugins/table-header-scroll.php + docker cp assets/adminer/plugins/pretty-json-column.php docker-Adminer:/var/www/html/plugins/pretty-json-column.php + docker cp assets/adminer/plugins/002-readable-dates.php docker-Adminer:/var/www/html/plugins-enabled/002-readable-dates.php + docker cp assets/adminer/plugins/003-table-header-scroll.php docker-Adminer:/var/www/html/plugins-enabled/003-table-header-scroll.php + docker cp assets/adminer/plugins/004-pretty-json-column.php docker-Adminer:/var/www/html/plugins-enabled/004-pretty-json-column.php +} + +help_messages () { + echo "Usage: sh k1run.sh [folder] [option] [option2]" + echo "Script that automate managing docker." + echo + echo "If no parameter is passed then boot and initialize the site." + echo + echo "--build Start the site and initialize the site." + echo "--down Stop the site. Keep data" + echo "--destroy Stop the site, destory data" + echo "--reboot Restart the site - destroy all containers and re-initialize" + echo "--load Reload the site, use existing data" + echo "--phpunit Initialize for phpunit tests" + echo "--behat Initialize for behat tests" +} + +exists_in_list() { + LIST=$1 + DELIMITER=$2 + VALUE=$3 + LIST_WHITESPACES=`echo $LIST | tr "$DELIMITER" " "` + for x in $LIST_WHITESPACES; do + if [ "$x" = "$VALUE" ]; then + return 1 + fi + done + return 0 +} + +if [ $# -eq 0 ]; then + echo "No arguments supplied" + help_messages + return +fi +#Count the variables passed in. +variablecount=$# +if [ $# -lt 2 ] || [ $# -gt 3 ] ; then + echo "Invalid number of arguments passed in. Must be between 2 and 3 arguments" + help_messages + return +fi + +cwd=$( dirname "$PWD" ) + +folder="${1}" + +folder="${cwd}/${folder}" +if [ ! -d "${folder}" ]; then + echo "${folder} is not valid" + return +fi + +SWITCH=$2 +SWITCH2=$3 + +# Variables +# MOODLE_DOCKER_DB - database used by Moodle - default maria db +# MOODLE_DOCKER_WWWROOT - folder where the Moodle code is located; + +if [ "$SWITCH" = "--help" ]; then + help_messages +fi + +# Check to see if the options are valied. + +list_of_options="--build --down --destroy --reboot --load --phpunit --behat" + +if exists_in_list "$list_of_options" " " $SWITCH; then + echo "Invalid option $SWITCH" + help_messages + return +fi + +if [ "$variablecount" -eq 3 ]; then + if exists_in_list "$list_of_options" " " $SWITCH2; then + echo "Invalid option $SWITCH2" + help_messages + return + fi +fi + +# Always use mariadb as a database. + +export MOODLE_DOCKER_DB=mariadb +export MOODLE_DOCKER_WWWROOT=${folder} +#export MOODLE_DOCKER_PHP_VERSION=8.3 + +# Use the local.yml_single for one site - includes adminer.. +cp local.yml_single local.yml +cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php + +# Build +if [ "$SWITCH" = "--build" ]; then + # Start up containers + bin/moodle-docker-compose up -d + # Wait for DB to come up + bin/moodle-docker-wait-for-db + # Initialize the database + bin/moodle-docker-compose exec webserver php admin/cli/install_database.php --agree-license --fullname="K1MOODLE" --shortname="K1MOODLE" --summary="K1 Moodle dev" --adminpass="test" --adminemail="admin@example.com" + if [ "$SWITCH2" = "--phpunit" ]; then + # Add in unit tests initialization. + bin/moodle-docker-compose exec webserver php admin/tool/phpunit/cli/init.php + fi + if [ "$SWITCH2" = "--behat" ]; then + # Add in unit tests initialization. + bin/moodle-docker-compose exec webserver php admin/tool/behat/init.php + fi + adminer_plugins +fi + +# DESTROY +if [ "$SWITCH" = "--destroy" ]; then + bin/moodle-docker-compose down +fi + +# PNPUNIT ONLY +if [ "$SWITCH" = "--phpunit" ]; then + # Start up containers + bin/moodle-docker-compose up -d + # Wait for DB to come up + bin/moodle-docker-wait-for-db + bin/moodle-docker-compose exec webserver php admin/tool/phpunit/cli/init.php + adminer_plugins +fi + +# PNPUNIT ONLY +if [ "$SWITCH" = "--behat" ]; then + # Start up containers + bin/moodle-docker-compose up -d + # Wait for DB to come up + bin/moodle-docker-wait-for-db + bin/moodle-docker-compose exec webserver php admin/tool/behat/cli/init.php + +fi + +# REBOOT +if [ "$SWITCH" = "--reboot" ]; then + # Stop the containers + bin/moodle-docker-compose down + sleep 3 + # Start up containers + bin/moodle-docker-compose up -d + bin/moodle-docker-compose exec webserver php admin/cli/install_database.php --agree-license --fullname="K1MOODLE" --shortname="K1MOODLE" --summary="K1 Moodle dev" --adminpass="test" --adminemail="admin@example.com" +fi + +# PHPUNIT +if [ "$SWITCH" = "--phpunit" ]; then + # Add in unit tests initialization. + bin/moodle-docker-compose exec webserver php admin/tool/phpunit/cli/init.php + adminer_plugins +fi + +# BEHAT +if [ "$SWITCH" = "--behat" ]; then + # Add in unit tests initialization. + bin/moodle-docker-compose exec webserver php admin/tool/behat/init.php +fi + +# DOWN +if [ "$SWITCH" = "--down" ]; then + # Stop the containers + bin/moodle-docker-compose stop +fi + +# DOWN +if [ "$SWITCH" = "--load" ]; then + # Start the containers + bin/moodle-docker-compose start + adminer_plugins +fi + +return diff --git a/local.yml b/local.yml new file mode 100644 index 00000000000..8c1286fd046 --- /dev/null +++ b/local.yml @@ -0,0 +1,31 @@ +version: "2" +services: + webserver: + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: + - "${ASSETDIR}/php/10-docker-php-moodle.ini:/usr/local/etc/php/conf.d/10-docker-php-moodle.ini" + environment: + XDEBUG_MODE: debug,develop + XDEBUG_CONFIG: + client_host=host.docker.internal + start_with_request=yes + log=./tmp/xdebug.log + log_level=10 + idekey=VSCODE + discover_client_host=1 + + adminer: + image: adminer:latest + container_name: "${COMPOSE_PROJECT_NAME}-Adminer" + environment: + ADMINER_DEFAULT_SERVER: db + ADMINER_PLUGINS: tables-filter + MYSQL_DATABASE: moodle + MYSQL_USER: moodle + MYSQL_PASSWORD: m@0dl3ing + build: + context: "./bin/Adminer/" + ports: + - 8089:8080 + diff --git a/local.yml_many b/local.yml_many new file mode 100644 index 00000000000..91187ff3fc0 --- /dev/null +++ b/local.yml_many @@ -0,0 +1,18 @@ +version: "2" +services: + webserver: + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: + - "${ASSETDIR}/php/10-docker-php-moodle.ini:/usr/local/etc/php/conf.d/10-docker-php-moodle.ini" + environment: + XDEBUG_MODE: debug,develop + XDEBUG_CONFIG: + client_host=host.docker.internal + start_with_request=yes + log=./tmp/xdebug.log + log_level=10 + idekey=VSCODE + discover_client_host=1 + + \ No newline at end of file diff --git a/local.yml_single b/local.yml_single new file mode 100644 index 00000000000..8c1286fd046 --- /dev/null +++ b/local.yml_single @@ -0,0 +1,31 @@ +version: "2" +services: + webserver: + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: + - "${ASSETDIR}/php/10-docker-php-moodle.ini:/usr/local/etc/php/conf.d/10-docker-php-moodle.ini" + environment: + XDEBUG_MODE: debug,develop + XDEBUG_CONFIG: + client_host=host.docker.internal + start_with_request=yes + log=./tmp/xdebug.log + log_level=10 + idekey=VSCODE + discover_client_host=1 + + adminer: + image: adminer:latest + container_name: "${COMPOSE_PROJECT_NAME}-Adminer" + environment: + ADMINER_DEFAULT_SERVER: db + ADMINER_PLUGINS: tables-filter + MYSQL_DATABASE: moodle + MYSQL_USER: moodle + MYSQL_PASSWORD: m@0dl3ing + build: + context: "./bin/Adminer/" + ports: + - 8089:8080 + diff --git a/nico.sh b/nico.sh new file mode 100644 index 00000000000..d5b3e82a649 --- /dev/null +++ b/nico.sh @@ -0,0 +1,137 @@ +#!/bin/bash + +adminer_plugins () { + # Add in Adminer plugins + docker cp assets/adminer/plugins/readable-dates.php docker2-Adminer:/var/www/html/plugins/readable-dates.php + docker cp assets/adminer/plugins/table-header-scroll.php docker2-Adminer:/var/www/html/plugins/table-header-scroll.php + docker cp assets/adminer/plugins/002-readable-dates.php docker2-Adminer:/var/www/html/plugins-enabled/002-readable-dates.php + docker cp assets/adminer/plugins/003-table-header-scroll.php docker2-Adminer:/var/www/html/plugins-enabled/003-table-header-scroll.php +} + +if [ $# -eq 0 ]; then + echo "No arguments supplied" + return +fi + + +if [ $# -lt 2 ] || [ $# -gt 3 ] ; then + echo "Invalid number of arguments passed in. Must be between 2 and 3 arguments" + return +fi + +cwd=$( dirname "$PWD" ) + +folder="${1}" + +folder="${cwd}/${folder}" +if [ ! -d "${folder}" ]; then + echo "${folder} is not valid" + return +fi + +SWITCH=$2 +SWITCH2=$3 + +# Variables +# MOODLE_DOCKER_DB - database used by Moodle - default maria db +# MOODLE_DOCKER_WWWROOT - folder where the Moodle code is located; + +if [ "$SWITCH" = "--help" ]; then + echo "Usage: sh run.sh [folder] [option] [option2]" + echo "Script that automate managing docker." + echo + echo "If no parameter is passed then boot and initialize the site." + echo + echo "--build Start the site and initialize the site." + echo "--down Stop the site. Keep data" + echo "--destroy Stop the site, destory data" + echo "--reboot Restart the site - destroy all containers and re-initialize" + echo "--load Reload the site, use existing data" + echo "--phpunit Initialize for phpunit tests" + echo "--behat Initialize for behat tests" +fi + +# Always use mariadb as a database. + +export MOODLE_DOCKER_DB=mariadb +export MOODLE_DOCKER_WWWROOT=${folder} + +# Build +if [ "$SWITCH" = "--build" ]; then + # Start up containers + bin/moodle-docker-compose up -d + # Wait for DB to come up + bin/moodle-docker-wait-for-db + # Initialize the database + bin/moodle-docker-compose exec webserver php admin/cli/install_database.php --agree-license --fullname="K1MOODLE" --shortname="K1MOODLE" --summary="K1 Moodle dev" --adminpass="test" --adminemail="admin@example.com" + if [ "$SWITCH2" = "--phpunit" ]; then + # Add in unit tests initialization. + bin/moodle-docker-compose exec webserver php admin/tool/phpunit/cli/init.php + fi + if [ "$SWITCH2" = "--behat" ]; then + # Add in unit tests initialization. + bin/moodle-docker-compose exec webserver php admin/tool/behat/init.php + fi + adminer_plugins +fi + +# DESTROY +if [ "$SWITCH" = "--destroy" ]; then + bin/moodle-docker-compose down +fi + +# PNPUNIT ONLY +if [ "$SWITCH" = "--phpunit" ]; then + # Start up containers + bin/moodle-docker-compose up -d + # Wait for DB to come up + bin/moodle-docker-wait-for-db + bin/moodle-docker-compose exec webserver php admin/tool/phpunit/cli/init.php + +fi + +# PNPUNIT ONLY +if [ "$SWITCH" = "--behat" ]; then + # Start up containers + bin/moodle-docker-compose up -d + # Wait for DB to come up + bin/moodle-docker-wait-for-db + bin/moodle-docker-compose exec webserver php admin/tool/behat/cli/init.php + +fi + +# REBOOT +if [ "$SWITCH" = "--reboot" ]; then + # Stop the containers + bin/moodle-docker-compose down + sleep 3 + # Start up containers + bin/moodle-docker-compose up -d + bin/moodle-docker-compose exec webserver php admin/cli/install_database.php --agree-license --fullname="K1MOODLE" --shortname="K1MOODLE" --summary="K1 Moodle dev" --adminpass="test" --adminemail="admin@example.com" +fi + +# PHPUNIT +if [ "$SWITCH" = "--phpunit" ]; then + # Add in unit tests initialization. + bin/moodle-docker-compose exec webserver php admin/tool/phpunit/cli/init.php +fi + +# BEHAT +if [ "$SWITCH" = "--behat" ]; then + # Add in unit tests initialization. + bin/moodle-docker-compose exec webserver php admin/tool/behat/init.php +fi + +# DOWN +if [ "$SWITCH" = "--down" ]; then + # Stop the containers + bin/moodle-docker-compose stop +fi + +# DOWN +if [ "$SWITCH" = "--load" ]; then + # Start the containers + bin/moodle-docker-compose start +fi + +return