Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Contains the import_backup_helper class.

Copyright: 2020 Adrian Greeve <adrian@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 194 lines (8 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

import_backup_helper:: (5 methods):
  __construct()
  get_stored_file()
  size_exceeds_upload_limit()
  create_user_draft_stored_file()
  get_context_for_user()


Class: import_backup_helper  - X-Ref

The import_backup_helper class.

The import_backup_helper objects provide a means to prepare a backup for for restoration of a course or activity backup file.

__construct(remote_resource $remoteresource, \stdClass $user, \context $context)   X-Ref
Constructor for the import backup helper.

param: remote_resource $remoteresource A remote file resource
param: \stdClass       $user           The user importing a file.
param: \context        $context        Context to restore into.

get_stored_file()   X-Ref
Return a stored user draft file for processing.

return: \stored_file The imported file to ultimately be restored.

size_exceeds_upload_limit(int $sizeinbytes)   X-Ref
Does the size exceed the upload limit for the current import, taking into account user and core settings.

param: int $sizeinbytes
return: bool true if exceeded, false otherwise.

create_user_draft_stored_file(string $filename, string $path)   X-Ref
Create a file in the user drafts ready for use by plugins implementing dndupload_handle().

param: string $filename the name of the file on disk
param: string $path the path where the file is stored on disk
return: \stored_file

get_context_for_user(int $userid)   X-Ref
Looks for a context that this user has permission to upload backup files to.
This gets a list of roles that the user has, checks for the restore:uploadfile capability and then sends back a context
that has this permission if available.

This starts with the highest context level and moves down i.e. system -> category -> course.

param: int $userid The user ID that we are looking for a working context for.
return: \context A context that allows the upload of backup files.