Moodle ships with several administration tools that have not been allocated to a particular topic; some are not even directly accessible via the familiar admin web interface.
Figure 17.1 – Moodle admin tools
We have grouped the admin tools into the following categories, each presented in a separate section:
Before we cover these admin tools in detail, let’s explore how they are organized in Moodle.
Moodle’s classification of what constitutes an admin tool is a little vague. When you navigate to Site administration | Plugins | Admin tools | Manage admin tools, a long list of plugins is shown:
Figure 17.2 – Moodle admin tools
We can group admin tools into the following categories:
Many tools of the first four categories are hidden from the Moodle admin web interface and can only be accessed by calling them directly via the URL: <yoursite>/admin/tool/<tool>. All core admin tools are located in subdirectories in $CFG->dirroot/admin/tool. For details of mostly non-standard admin tools, refer to docs.moodle.org/en/Admin_tools.
We are not covering any admin tools classified as standard Moodle features, since they are either dealt with elsewhere in the book or are irrelevant in the administrator context. However, one exception are site admin presets, the only feature that does not belong to any category in the site administration menu. So, let’s get started with our first admin tool.
Presets allow you to create backups of site settings that can then be restored. There are several use cases where this facility comes in handy:
The workflow of Moodle admin presets is illustrated in the following diagram – a straightforward but very powerful tool:
Figure 17.3 – Site admin presets workflow
You find the Site admin presets tool in the General section of the Site administration area. It is the only Moodle feature that has not been placed in a menu category, hence its coverage in this chapter.
Moodle ships with two preconfigured presets that have been labelled Starter and Full. Details about its content are provided in the respective descriptions, as shown in the following screenshot, which contains a third preset that we will create in this section.
Figure 17.4 – Site admin presets
To make your first preset, click the Create preset button, and then you have to provide a name, an optional description, and an author, which is pre-populated with your name:
Figure 17.5 – Creating a site admin preset
The Include settings with passwords option will add any sensitive information – passwords, keys, and IPs – of your site to the preset, so ensure that this will only be applied internally. You can view and modify the list of fields to be excluded in the Settings with password field in Site administration | General | Security | Site security settings.
Once the preset has been created, it will appear in the list alongside the two default presets. The following actions are available for each preset:
Figure 17.6 – Applying a site admin preset
Site admin presets is a powerful tool during setup, maintenance, and when experimenting with new features.
Tip
It is good practice to store the presets of your production site as part of your system documentation.
Admin presets deal with your site’s configuration, stored in the underlying database. A number of dedicated database tools are discussed in the following section.
Moodle’s database tools transfer databases from one server to another, perform search-and-replace operations on text strings in the entire database, and let you view or change any data in the database itself.
If you have to move the database of a Moodle instance from one server to another or migrate to another Moodle system, you have two broad options. You can either create a database dump manually (or via the Adminer tool, which is covered later) or use the built-in database transfer facility.
The database migration tool is available at <yoursite>/admin/tool/dbtransfer. At the time of writing, the feature can also be accessed via Site administration | Development | Experimental | Database migration. As the category name suggests, the tool is experimental and might make it into core or might disappear again from the admin interface in future releases.
Figure 17.7 – Database transfer
You must provide the details of the database to which the content of the current database will be copied. These settings are identical to the ones applied during installation (see Chapter 1, Installing Moodle).
You further have the Enable maintenance mode option, which will turn on maintenance mode during and after migration. If used, you will have to remove the $CFG->dataroot/climaintenance.html file afterwards manually or via Site administration | Server | Server | Maintenance mode.
A tool related to the database migration facility is DB search and replace. After you have moved or copied your system to another location, your URL might have changed. Any user using fixed URLs anywhere in their content now faces dead links. As an administrator, you have a script at hand where you can replace any text in the underlying database, except a few tables, as noted in the second warning. You can find the script at <yoursite>/admin/tool/replace.
Figure 17.8 – Database search and replace
The last option, labeled I understand the risks of this operation, indicates the potential risk of the execution – unless you are 100% certain that the replacements will not have any impact on the system, you had better stay away from it. Once completed, the script will display all executed SQL queries.
Adminer is an open source tool to administer different types of SQL databases. A wrapper has been created that lets you access the tool directly from within Moodle. Moodle Adminer must be installed in your local plugins section (see Chapter 8, Understanding Moodle Plugins for details). You will find the installer at moodle.org/plugins/local_adminer.
Once installed, you access the database management console via Site administration | Server | Moodle Adminer, which opens the tool in a modal window:
Figure 17.9 – The Moodle Adminer interface
By default, you must select a database. However, you can skip this step if you enable the Start adminer with current database setting in Site administration | Plugins | Local plugins | Moodle Adminer.
Once a (Moodle) database has been opened, you can perform operations (such as querying, altering data, or creating an SQL dump) without any SQL knowledge.
Important note
Ensure you only change data if you know what you are doing; otherwise, you might introduce database inconsistencies, and Moodle will not work as expected.
We will not go into using Adminer in detail since this is beyond the scope of this chapter. You can find all the information you are looking for at www.adminer.org.
This concludes the database tools section, where we covered database transfer, database search and replace, and Moodle Adminer. We ignored one tool that only applies to MySQL/MariaDB and is only needed when migrating a database still using the legacy MyISAM format. This tool can be found at <yoursite>/admin/tool/innodb, which converts any tables from MyISAM to the InnoDB storage engine.
There are also CLI scripts supporting database-related operations, such as mysql_engine and check_database_schema. What’s a CLI script? Find out in the following section.
We already encountered the CLI selectively throughout the book and during Chapter 1, Installing Moodle, when we dealt with Moodle upgrades. However, the CLI has a few more tricks up its sleeve, which we will deal with in this section.
First, let’s look at how you call CLI scripts, which are either located in admin/cli/* or in the sub-folder of plugins that offer a CLI option – for example, auth/ldap/cli. To call a CLI script, follow the following notation:
sudo –u <apache_user> /usr/bin/php admin/cli/<script>.php [--params]
Your <apache_user> is usually www-data, httpd, or apache.
Important note
Always run Moodle CLI scripts under the identity of the web server user.
Every CLI script has a --help parameter that offers additional information and also describes calling options and parameters. The following is a list of some useful CLI commands and chapter numbers in which they have been covered. Look in their respective CLI directories or at docs.moodle.org/en/Administration_via_command_line for all other commands. We do not list any parameters here, as these are explained well in the --help options.
Figure 17.10 – A selection of Moodle CLI scripts
The real power of the CLI lies in the ability to embed CLI commands in shell scripts, which allows for powerful automation of otherwise time-consuming or error-prone routines. We presented a small installation script in Chapter 1, Installing Moodle. Here is another sample script that kills all user sessions and clears caches, utilizing some CLI scripts:
Figure 17.11 – A sample Bash script utilizing the Moodle CLI
While useful for the supported operations, the CLI provides a relatively restricted set of commands. Moosh, which we will cover next, overcomes this limitation.
Moosh stands for Moodle Shell and is a command-line tool that allows you to perform the most common Moodle tasks.
Before you can make use of Moosh, you have to install it (see Chapter 8, Understanding Moodle Plugins). Once installed, you will have a vast number of commands (at the time of writing, over 150!) at your disposal.
The general syntax of Moosh is as follows:
moosh <-params> <command> <options>
To give you an idea of the types of things you can do with Moosh, here are a few examples:
Once you combine Moosh commands with standard shell commands via pipes and streams, you have a powerful arsenal of commands at hand. For example, you might want to find all backups that are larger than 10 GB, archive them, and reclaim the space.
The following example demonstrates the execution and output of three Moosh commands:
Figure 17.12 – Playing with Moosh
The first (moosh course-list) shows the information on all courses; the second (moosh category-list) does the same for categories; the last (moosh user-create test{1..10}) shows the IDs of the 10 user accounts after they have been created.
For a complete list of over 150 commands and hundreds of options, refer to the Moosh website at moosh-online.com/commands. The list is constantly growing, so ensure you have installed the latest version.
This concludes the section on Moosh and the chapter on Moodle admin tools. Hopefully, some facilities will streamline your day-to-day job and optimize some of the routine tasks you need to carry out.
In this chapter, we have covered a range of admin tools, some hidden and unsupported but nonetheless very useful. We first explored how admin tools are organized, before we covered site admin presets and some database tools, including the external Adminer, the Moodle CLI, and the powerful third-party Moosh tool.
Other ways to extend the reach of Moodle are web services, which we will cover in the following chapter.
18.216.27.251