Moodle Development kit

Jump to: navigation, search

Every developer creates simple tools to avoid repeating cumbersome and/or boring tasks, and that is precisely why MDK has been created: to pack all those useful tools in a portable way across systems. Initially developed in Bash, the project moved to Python to avoid dealing with inconsistencies between Unix platforms, and eventually to support Windows.

Key concept

The most important concept of MDK is that it works with Moodle instances. An instance of Moodle is a directory in which you have checked out a particular version together with a database using a specific database engine. This means that if you want to work on Moodle 2.3 and 2.4, using both MySQL and PostgreSQL, you will have four separate instance directories. This choice was made because it is the safest, clearest, and most straightforward solution.

Typical workflows using MDK

To discover what MDK can do for you, here are a few common tasks it can achieve. More on MDK's wiki.

Installing a new instance

Say we need to create a new instance of Moodle 2.4 and install it with PostgreSQL. We also want the instance to be ready for development with appropriate config settings. We also want to create a bunch of user accounts.

mdk create -i -v 24 -e pgsql -r dev users

This is equivalent to doing:

mkdir /dir/to/stable_24/moodle
mkdir /dir/to/stable_24/moodledata
ln -s /dir/to/stable_24/moodle /var/www/stable_24
git clone git:// /dir/to/moodle
cd /dir/to/stable_24/moodle
php admin/cli/install.php --wwwroot="http://localhost/stable_24" --dataroot=/dir/to/stable_24/moodledata --dbtype=pgsql --dbname=stable24 --dbuser=root --dbpass=root --dbhost=localhost --fullname="Stable 24 PostgreSQL" --shortname=stable_24 --adminuser=admin --adminpass=test --allow-unstable --agree-license --non-interactive
vim config.php
# Add the following settings:
# - $CFG->sessioncookiepath: /stable_24/
# - $CFG->debugdisplay: 1
# - $CFG->passwordpolicy: 0
# - $CFG->perfdebug: 15
# - $CFG->debugpageinfo: 1
# - $CFG->allowthemechangeonurl: 1
# - $CFG->cachejs: 0
# - $CFG->yuicomboloading: 0
# Include FirePHP Core
# Login to Moodle
# Create 10 students, 3 teachers and 3 managers

Fixing an issue

mdk fix 12345
# Committing your patch
mdk push -t

This is equivalent to doing:

git branch --track MDL-12345-24 origin/MOODLE_24_STABLE
git checkout MDL-12345-24
# Committing your patch
git push github MDL-12345-24
# Editing the tracker issue to add
# - Git repository URL
# - Git branch for 2.4
# - Git compare URL for 2.4

Peer reviewing a patch

Here we want to pull a patch from a tracker issue into a new testing branch, and then run the PHPUnit tests.

mdk pull 12345 -t
mdk phpunit -r

This is the equivalent to doing:

cd /dir/to/stable_24/moodle
git branch --tracker MDL-12345-24-test MOODLE_24_STABLE
git checkout MDL-12345-24-test
git pull git:// MDL-12345-24
# And now the PHPUnit part
mkdir /dir/to/stable_24/moodledata_phpu
vim config.php
# To add
# - $CFG->phpunit_dataroot = '/dir/to/stable_24/moodledata_phpu';
# - $CFG->phpunit_prefix = 'phpu_';
php admin/tool/phpunit/cli/init.php

Upgrading the instances

Say we need to upgrade our instances, as a new weekly release has just been made available.

mdk upgrade -u --all

This is the equivalent to doing:

# For each instance of Moodle...
cd /dir/to/stable_24/moodle
git checkout MOODLE_24_STABLE
git fetch origin
git reset --hard origin/MOODLE_24_STABLE
php admin/cli/upgrade.php --non-interactive --allow-unstable


For a complete list of the commands MDK has to offer, read through the MDK README file. For more detail about each command, simply run them with the flag '--help'.


Please follow the instructions from the README file.

The MDK Suite

Some other tools have been developed using the name MDK as they are considered as part of the development kit but are often mistaken with the real MDK. The real MDK is the command line tool described above.

MDK Browser Extension

Available for both Firefox and Chrome, this is a browser extension that allows quick access to useful user-scripts. The scripts add functionality to, Moodle Tracker and your Moodle instances. You can find more information about it on its public repository.

MDK Authentication

This is an authentication plugin for Moodle 2.x, which not only creates the user if it does not exist in the database yet, but also enrols it as a student, teacher or manager in all the available courses. More information about this plugin is available on the public repository.