18. Command-line interfaces (CLI)

Command-line interfaces (CLI) allow you to interact with Mahara through the command line or terminal rather than through a graphical interface. That can speed up certain actions or make them easier to execute.

Bemerkung

You can view help information on the individual commands that are available for each script:

sudo -u www-data php htdocs/admin/cli/[file name of the script].php -h

18.1. new in Mahara 24.04 Active account holder information

You may wish to know if the people who have logged in during a specific time frame have engaged on the site, e.g. created or uploaded content. By knowing that, you could decide if you wanted to delete certain accounts if they only logged in but have not performed any actions.

Execute the script with the following command.

sudo -u www-data php htdocs/admin/cli/inactive_users.php --interval="1 YEAR"

Bemerkung

You can change the interval time and also display days or months. The interval always indicates the time period from now into the past by the interval. By choosing 1 year, for example, you see everyone who has logged into the site during the previous 365 days.

The resulting table shows the following information:

  • Mahara ID: The internal Mahara ID

  • Username: The username of the account

  • Last login: The last login date and time

  • Only has default pages: If ‚Yes‘ is displayed, the account holder only has the dashboard and the profile page, but has not created any portfolio pages. If ‚No‘ is displayed, they have at least one portfolio page.

  • New artefacts in time interval: If ‚Yes‘ is displayed, they created or uploaded content during the time interval. If ‚No‘ is displayed, they did not create any content during the selected time period.

  • New portfolios in time interval: If ‚Yes‘ is displayed, they created at least one portfolio page during the time interval. If ‚No‘ is displayed, they did not create any portfolio pages during the time interval.

  • Has joined groups: If ‚Yes‘ is displayed, they are a member of at least one group. If ‚No‘ is displayed, they have not joined any groups.

  • Quata used: The amount of the file quota is displayed in bytes.

  • Quota used percentage: The percentage of their used quota

18.2. Cron job monitor

Configure when you want to be alerted to failures in the cron job in an external monitoring software.

Siehe auch

Refer to the ‚Monitor‘ module in the Plugin administration.

18.3. Delete certain groups in bulk

If you have a large site and deleted a lot of accounts, you may also wish to clean up old groups in an efficient way. You can do the following with the bulk group deletion script:

  • delete all groups that have no members, e.g. after accounts were deleted;

  • and delete all groups that have only site administrators as members;

  • and / or delete only groups associated with a certain institution.

Execute the script with the following command. A dry run is made by default so that no data is deleted by accident.

sudo -u www-data php htdocs/admin/cli/delete_inactive_groups.php

18.4. Delete certain accounts in bulk

If you want to delete accounts in bulk from the site without needing to go to the administration screen, especially if you have more than 500 accounts to delete, you can use CLI. This script allows you to do the following:

  • delete all accounts that have never been logged into, i.e. that were created manually, via CSV file, or an automated process;

  • and / or delete all accounts that have not been logged in since a certain date;

  • and / or delete only those accounts from one or more specific institutions;

  • delete accounts that don’t belong to one or more specific institutions;

  • delete accounts that are members of a specific group.

Bemerkung

When specifying institutions or groups, use their shortnames.

Execute the script with the following command. A dry run is made by default so that no data is deleted by accident.

General dry run:

sudo -u www-data php htdocs/admin/cli/delete_inactive_users.php

View the help file:

sudo -u www-data php htdocs/admin/cli/delete_inactive_users.php -h

18.5. Export accounts in bulk

You can export all or certain accounts in bulk via CLI. You have the following options:

  • Export all accounts

  • Export some accounts based on filter criteria: first name, last name, email, username

  • Export some accounts based on CSV file

  • Choose the export format: HTML, Leap2A, PDF (if installed)

Execute the script with the following command. A dry run is made by default so that no data is deleted by accident.

General dry run:

sudo -u www-data php htdocs/admin/cli/portfolio_bulkexport.php

View the help file:

sudo -u www-data php htdocs/admin/cli/portfolio_bulkexport.php -h

18.6. Index sites running Elasticsearch faster

Bemerkung

Prerequisite: Elasticsearch is installed and set up to run on the site.

When a large site is indexed or re-indexed so that Elasticsearch can display results, this process can take a very long time because the indexing happens on cron runs. If the batch that was indexed finished before the end of the cron though, there is a lag between the next batch starting up again. The fast_index CLI script starts the next batch indexing right after the previous one finished.

You run the script with the following command:

sudo -u www-data php admin/cli/fast_index.php

18.7. Install and update language packs

Typically, if you want to update a language pack, you need to download the entire language pack manually and place it into the appropriate folder. This is cumbersome, especially when you want to update the language packs during minor point updates.

Using CLI, you can speed up the process.

Install or update language packs for your instance of Mahara by listing the language codes.

Example (de = German, fr = French):

sudo -u www-data php admin/cli/sync_langpacks.php -l=de,fr

This will make a backup of the existing languages if they exist into the dataroot’s langpacks_backup directory.

Bemerkung

The language codes that are used are the official international ones used for the Mahara language packs.

Don’t make backups: Add the -b=false flag

Example:

sudo -u www-data php admin/cli/sync_langpacks.php -l=de,fr -b=false

Restore a backup: Use the -r=true flag

Example:

sudo -u www-data php admin/cli/sync_langpacks.php -l=de,fr -r=true

This will ignore trying to update the English language as that is set within Mahara itself.

18.8. Populate outcomes portfolio tables

Theoutcomes portfolios require the configuration of outcome categories, types, and subjects. These are added directly into the database via the upload of CSV files through CLI.

Siehe auch

Refer to the outcomes portfolio types and subjects setup instructions to learn what the CSV files need to look like.

Upload the outcome types file, which also directly sets up the outcome categories:

sudo -u www-data php htdocs/admin/cli/populate_outcome_tables.php -t=path_to_categories.csv

The -t flag indicates that it is the file that contains the outcome types.

Upload the subjects file:

sudo -u www-data php htdocs/admin/cli/populate_outcome_tables.php -s=path_to_subjects.csv

The -s flag indicates that it is the file that contains the subjects.

new in Mahara 24.04 The -e flag allows you to enable the outcomes functionality for the institution for which you want to create the cateogries or subjects if you haven’t already enabled it.

For example, the following commands enables outcomes for the institution mentioned in the CSV file and creates the subjects:

sudo -u www-data php htdocs/admin/cli/populate_outcome_tables.php -s=path_to_subjects.csv -e=true