Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402]

Helper functions for asynchronous backups and restores.

Copyright: 2019 Matt Porritt <mattp@catalyst-au.net>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 439 lines (16 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: async_helper  - X-Ref

Helper functions for asynchronous backups and restores.

__construct($type, $id)   X-Ref
Class constructor.

param: string $type The type of async operation.
param: string $id The id of the backup or restore.

get_backup_record($id)   X-Ref
Given a backup id return a the record from the database.
We use this method rather than 'load_controller' as the controller may
not exist if this backup/restore has completed.

param: int $id The backup id to get.
return: object $backuprec The backup controller record.

get_user()   X-Ref
Given a user id return a user object.

return: object $user The limited user record.

get_operation_description()   X-Ref
Return appropriate description for current async operation {@see async_helper::type}

return: string

lookup_message_variables($matches)   X-Ref
Callback for preg_replace_callback.
Replaces message placeholders with real values.

param: array $matches The match array from from preg_replace_callback.
return: string $match The replaced string.

get_resource_link()   X-Ref
Get the link to the resource that is being backuped or restored.

return: moodle_url $url The link to the resource.

send_message()   X-Ref
Sends a confirmation message for an aynchronous process.

return: int $messageid The id of the sent message.

is_async_enabled()   X-Ref
Check if asynchronous backup and restore mode is
enabled at system level.

return: bool $async True if async mode enabled false otherwise.

is_async_pending($id, $type, $operation)   X-Ref
Check if there is a pending async operation for given details.

param: int $id The item id to check in the backup record.
param: string $type The type of operation: course, activity or section.
param: string $operation Operation backup or restore.
return: boolean $asyncpedning Is there a pending async operation.

get_backup_file_info($filename, $filearea, $contextid)   X-Ref
Get the size, url and restore url for a backup file.

param: string $filename The name of the file to get info for.
param: string $filearea The file area for the file.
param: int $contextid The context ID of the file.
return: array $results The result array containing the size, url and restore url of the file.

get_restore_url($backupid)   X-Ref
Get the url of a restored backup item based on the backup ID.

param: string $backupid The backup ID to get the restore location url.
return: array $urlarray The restored item URL as an array.

get_async_backups($filearea, $instanceid)   X-Ref
Get markup for in progress async backups,
to use in backup table UI.

param: string $filearea The filearea to get backup data for.
param: integer $instanceid The context id to get backup data for.
return: array $tabledata the rows of table data.

get_userdata_backup_settings(\backup_controller $backupcontroller)   X-Ref
Get the user data settings for backups.

param: \backup_controller $backupcontroller The backup controller object.
return: array Array of user data settings.

get_restore_name(\context $context)   X-Ref
Get the course name of the resource being restored.

param: \context $context The Moodle context for the restores.
return: string $coursename The full name of the course.

get_async_restores($userid)   X-Ref
Get all the current in progress async restores for a user.

param: int $userid Moodle user id.
return: array $restores List of current restores in progress.