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

Mecontract 240 #303

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions assets/adminer/plugins/001-tables-filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
require_once('plugins/tables-filter.php');

return new AdminerTablesFilter();
4 changes: 4 additions & 0 deletions assets/adminer/plugins/002-readable-dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
require_once('plugins/readable-dates.php');

return new AdminerReadableDates();
4 changes: 4 additions & 0 deletions assets/adminer/plugins/003-table-header-scroll.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
require_once('plugins/table-header-scroll.php');

return new AdminerTableHeaderScroll();
4 changes: 4 additions & 0 deletions assets/adminer/plugins/004-pretty-json-column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
require_once('plugins/pretty-json-column.php');
$adminer = new AdminerPlugin([]);
return new AdminerPrettyJsonColumn($adminer);
40 changes: 40 additions & 0 deletions assets/adminer/plugins/pretty-json-column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/** Pretty print JSON values in edit
*/
class AdminerPrettyJsonColumn {
/** @var AdminerPlugin */
protected $adminer;

public function __construct($adminer) {
$this->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 <<<HTML
<textarea $attrs cols="50" rows="20">$jsonText</textarea>
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));
}
}
49 changes: 49 additions & 0 deletions assets/adminer/plugins/readable-dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/** This plugin replaces UNIX timestamps with human-readable dates in your local format.
* Mouse click on the date field reveals timestamp back.
*
* @link https://www.adminer.org/plugins/#use
* @author Anonymous
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerReadableDates {
/** @access protected */
var $prepend;

function __construct() {
$this->prepend = <<<EOT

document.addEventListener('DOMContentLoaded', function(event) {
var date = new Date();
var tds = document.querySelectorAll('td[id^="val"]');
for (var i = 0; i < tds.length; i++) {
var text = tds[i].innerHTML.trim();
if (text.match(/^\d{10}$/)) {
date.setTime(parseInt(text) * 1000);
tds[i].oldDate = text;

// tds[i].newDate = date.toUTCString().substr(5); // UTC format
tds[i].newDate = date.toLocaleString(); // Local format
// tds[i].newDate = date.toLocaleFormat('%e %b %Y %H:%M:%S'); // Custom format - works in Firefox only

tds[i].newDate = '<span style="color: #009900">' + tds[i].newDate + '</span>';
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);
}
}
75 changes: 75 additions & 0 deletions assets/adminer/plugins/table-header-scroll.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* Adminer Table header scroll plugin.
*
* Copyright (C) 2016 Jonathan Vollebregt <[email protected]>.
*
* 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 <http://www.gnu.org/licenses/>.
*/
class AdminerTableHeaderScroll
{
public function head()
{
?>

<script<?php echo nonce(); ?>>
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);
}
</script>

<?php
return true;
}
}
13 changes: 13 additions & 0 deletions assets/php/10-docker-php-moodle.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; CONFIGURATION SETTINGS REQUIRED BY MOODLE

; How many GET/POST/COOKIE input variables may be accepted
; See MDL-71390 for more info. This is the recommended / required
; value to support sites having 1000 courses, activities, users....
max_input_vars = 5000

; Increase the maximum filesize to 200M, which is a more realistic figure.
upload_max_filesize = 2G

; Increase the maximum post size to accomodate the increased upload_max_filesize.
; The default value is 6MB more than the default upload_max_filesize.
post_max_size = 2G
1 change: 1 addition & 0 deletions base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
volumes:
- "${MOODLE_DOCKER_WWWROOT}:/var/www/html"
- "${ASSETDIR}/web/apache2_faildumps.conf:/etc/apache2/conf-enabled/apache2_faildumps.conf"
- "${ASSETDIR}/php/10-docker-php-moodle.ini:/usr/local/etc/php/conf.d/10-docker-php-moodle.ini"
environment:
MOODLE_DOCKER_RUNNING: 1
MOODLE_DOCKER_DBNAME: moodle
Expand Down
155 changes: 155 additions & 0 deletions bin/k1run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#!/bin/bash

thisfile=$( readlink "${BASH_SOURCE[0]}" ) || thisfile="${BASH_SOURCE[0]}"
basedir="$( cd "$( dirname "$thisfile" )/../" && pwd -P )"
#SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /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: [email protected] 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: [email protected] 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="[email protected]"
echo "Run install_database.php with default credentials: [email protected] 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="[email protected]"

# 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="[email protected]"

# 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
Loading