Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Implementation of .mbz packer. This packer supports .mbz files which can be either .zip or .tar.gz format internally. A suitable format is chosen depending on system option when creating new files.

Copyright: 2013 The Open University
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 175 lines (7 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: mbz_packer  - X-Ref

Utility class - handles all packing/unpacking of .mbz files.

archive_to_storage(array $files, $contextid,$component, $filearea, $itemid, $filepath, $filename,$userid = null, $ignoreinvalidfiles = true, file_progress $progress = null)   X-Ref
Archive files and store the result in file storage.

Any existing file at that location will be overwritten.

return: stored_file|bool false if error stored_file instance if ok
param: array $files array from archive path => pathname or stored_file
param: int $contextid context ID
param: string $component component
param: string $filearea file area
param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
param: int $userid user ID
param: bool $ignoreinvalidfiles true means ignore missing or invalid files, false means abort on any error
param: file_progress $progress Progress indicator callback or null if not required

archive_to_pathname(array $files, $archivefile,$ignoreinvalidfiles=true, file_progress $progress = null)   X-Ref
Archive files and store the result in an OS file.

return: bool true if file created, false if not
param: array $files array from archive path => pathname or stored_file
param: string $archivefile path to target zip file
param: bool $ignoreinvalidfiles true means ignore missing or invalid files, false means abort on any error
param: file_progress $progress Progress indicator callback or null if not required

extract_to_pathname($archivefile, $pathname,array $onlyfiles = null, file_progress $progress = null, $returnbool = false)   X-Ref
Extract file to given file path (real OS filesystem), existing files are overwritten.

return: array list of processed files (name=>true)
param: stored_file|string $archivefile full pathname of zip file or stored_file instance
param: string $pathname target directory
param: array $onlyfiles only extract files present in the array
param: file_progress $progress Progress indicator callback or null if not required
param: bool $returnbool Whether to return a basic true/false indicating error state, or full per-file error

extract_to_storage($archivefile, $contextid,$component, $filearea, $itemid, $pathbase, $userid = null,file_progress $progress = null)   X-Ref
Extract file to given file path (real OS filesystem), existing files are overwritten.

return: array list of processed files (name=>true)
param: string|stored_file $archivefile full pathname of zip file or stored_file instance
param: int $contextid context ID
param: string $component component
param: string $filearea file area
param: int $itemid item ID
param: string $pathbase file path
param: int $userid user ID
param: file_progress $progress Progress indicator callback or null if not required

list_files($archivefile)   X-Ref
Returns array of info about all files in archive.

return: array of file infos
param: string|stored_file $archivefile

get_packer_for_archive_operation()   X-Ref
Selects appropriate packer for new archive depending on system option
and whether required extension is available.

return: file_packer Suitable packer

get_packer_for_read_operation($archivefile)   X-Ref
Selects appropriate packer for existing archive depending on file contents.

return: file_packer Suitable packer
param: string|stored_file $archivefile full pathname of zip file or stored_file instance