Search moodle.org's
Developer Documentation


/ -> mdeploy.php (summary)

Moodle deployment utility

Copyright: 2012 David Mudrak <david@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Version: 1.1
File Size: 1574 lines (53 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 0 files

Defines 18 classes

invalid_coding_exception:: (0 methods):

missing_option_exception:: (0 methods):

invalid_option_exception:: (0 methods):

unauthorized_access_exception:: (0 methods):

download_file_exception:: (0 methods):

backup_folder_exception:: (0 methods):

zip_exception:: (0 methods):

filesystem_exception:: (0 methods):

checksum_exception:: (0 methods):

invalid_setting_exception:: (4 methods):
  instance()
  initialize()
  __construct()
  __clone()

input_manager:: (11 methods):
  get_option()
  get_option_info()
  cast_value()
  initialize()
  validate_option_name()
  get_required_option()
  get_optional_option()
  get_option()
  has_option()
  initialize()
  populate_options()

input_cli_provider:: (1 method):
  parse_raw_options()

input_http_provider:: (1 method):
  parse_raw_options()

output_manager:: (2 methods):
  __call()
  initialize()

output_cli_provider:: (2 methods):
  help()
  outln()

output_http_provider:: (4 methods):
  help()
  exception()
  start_output()
  end_output()

worker:: (21 methods):
  execute()
  log_exception()
  initialize()
  done()
  authorize()
  log_location()
  target_location()
  backup_location()
  download_file()
  get_env()
  get_cacert()
  log()
  format_log_message()
  move_directory_source_precheck()
  move_directory_target_precheck()
  create_directory_precheck()
  move_directory()
  move_directory_into()
  remove_directory()
  unzip_plugin()
  redirect()

exception_handlers:: (4 methods):
  set_handler()
  format_exception_info()
  bootstrap_exception_handler()
  default_exception_handler()


Class: zip_exception  - X-Ref

Class: invalid_setting_exception  - X-Ref

instance()   X-Ref
Factory method returning the singleton instance.

Subclasses may want to override the {@link self::initialize()} method that is
called right after their instantiation.

return: mixed the singleton instance

initialize()   X-Ref
Optional post-instantiation code.


__construct()   X-Ref
Direct instantiation not allowed, use the factory method {@link instance()}


__clone()   X-Ref
Sorry, this is singleton.


Class: input_manager  - X-Ref

Provides access to the script options.

Implements the delegate pattern by dispatching the calls to appropriate
helper class (CLI or HTTP).

get_option($name, $default = 'provide_default_value_explicitly')   X-Ref
Returns the value of an option passed to the script.

If the caller passes just the $name, the requested argument is considered
required. The caller may specify the second argument which then
makes the argument optional with the given default value.

If the type of the $name option is TYPE_FLAG (switch), this method returns
true if the flag has been passed or false if it was not. Specifying the
default value makes no sense in this case and leads to invalid coding exception.

The array options are not supported.

return: mixed
param: string $name

get_option_info($name=null)   X-Ref
Returns the meta-information about the given option.

return: array|object|false array with all, object with the specific option meta-information or false of no such an option
param: string|null $name short or long option name, defaults to returning the list of all

cast_value($raw, $type)   X-Ref
Casts the value to the given type.

return: mixed
param: mixed $raw the raw value
param: string $type the expected value type, e.g. {@link input_manager::TYPE_INT}

initialize()   X-Ref
Picks the appropriate helper class to delegate calls to.


validate_option_name($name)   X-Ref
Validates the parameter name.

param: string $name

get_required_option($name)   X-Ref
Returns cleaned option value or throws exception.

return: mixed
param: string $name the name of the parameter
param: string $type the parameter type, e.g. {@link input_manager::TYPE_INT}

get_optional_option($name, $default)   X-Ref
Returns cleaned option value or the default value

return: mixed
param: string $name the name of the parameter
param: string $type the parameter type, e.g. {@link input_manager::TYPE_INT}
param: mixed $default the default value.

get_option($name)   X-Ref
Returns the casted value of the option.

return: mixed casted value of the option
param: string $name option name

has_option($name)   X-Ref
Was the given option passed?

return: bool
param: string $name optionname

initialize()   X-Ref
Initializes the input provider.


populate_options()   X-Ref
Parses and validates all supported options passed to the script.


Class: input_cli_provider  - X-Ref

Provides access to the script options passed via CLI.

parse_raw_options()   X-Ref
Parses raw options passed to the script.

return: array as returned by getopt()

Class: input_http_provider  - X-Ref

Provides access to the script options passed via HTTP request.

parse_raw_options()   X-Ref
Parses raw options passed to the script.

return: array of raw values passed via HTTP request

Class: output_manager  - X-Ref

Provides output operations.

__call($name, array $arguments = array()   X-Ref
Magic method triggered when invoking an inaccessible method.

param: string $name method name
param: array $arguments method arguments

initialize()   X-Ref
Picks the appropriate helper class to delegate calls to.


Class: output_cli_provider  - X-Ref

Provides output to the command line.

help()   X-Ref
Prints help information in CLI mode.


outln($text='')   X-Ref
Writes a text to the STDOUT followed by a new line character.

param: string $text text to print

Class: output_http_provider  - X-Ref

Provides HTML output as a part of HTTP response.

help()   X-Ref
Prints help on the script usage.


exception(Exception $e)   X-Ref
Display the information about uncaught exception

param: Exception $e uncaught exception

start_output()   X-Ref
Produce the HTML page header


end_output()   X-Ref
Produce the HTML page footer


Class: worker  - X-Ref

The actual worker class implementing the main functionality of the script.

execute()   X-Ref
Main - the one that actually does something


log_exception(Exception $e)   X-Ref
Attempts to log a thrown exception

param: Exception $e uncaught exception

initialize()   X-Ref
Initialize the worker class.


done($exitcode = self::EXIT_OK)   X-Ref
Finish this script execution.

param: int $exitcode

authorize()   X-Ref
Authorize access to the script.

In CLI mode, the access is automatically authorized. In HTTP mode, the
passphrase submitted via the request params must match the contents of the
file, the name of which is passed in another parameter.


log_location()   X-Ref
Returns the full path to the log file.

return: string

target_location($source)   X-Ref
Choose the target location for the given ZIP's URL.

return: string
param: string $source URL

backup_location($path)   X-Ref
Choose the location of the current plugin folder backup

return: string
param: string $path full path to the current folder

download_file($source, $target)   X-Ref
Downloads the given file into the given destination.

This is basically a simplified version of {@link download_file_content()} from
Moodle itself, tuned for fetching files from moodle.org servers.

return: bool true on success, false otherwise
param: string $source file url starting with http(s)://
param: string $target store the downloaded content to this file (full path)

get_env($key)   X-Ref
Fetch environment settings.

return: mixed The value of the key if found.
param: string $key The key to fetch

get_cacert()   X-Ref
Get the location of ca certificates.

return: string absolute file path or empty if default used

log($message)   X-Ref
Log a message

param: string $message

format_log_message($msg)   X-Ref
Prepares the log message for writing into the file

return: string
param: string $msg

move_directory_source_precheck($source)   X-Ref
Checks to see if the given source could be safely moved into a new location

return: bool
param: string $source full path to the existing directory

move_directory_target_precheck($target)   X-Ref
Checks to see if a source folder could be safely moved into the given new location

return: bool
param: string $destination full path to the new expected location of a folder

create_directory_precheck($path)   X-Ref
Make sure the given directory can be created (and removed)

return: bool
param: string $path full path to the folder

move_directory($source, $target, $keepsourceroot = false)   X-Ref
Moves the given source into a new location recursively

The target location can not exist.

return: bool
param: string $source full path to the existing directory
param: string $destination full path to the new location of the folder
param: bool $keepsourceroot should the root of the $source be kept or removed at the end

move_directory_into($source, $target, $keepsourceroot = false)   X-Ref
Moves the given source into a new location recursively

If the target already exists, files are moved into it. The target is created otherwise.

return: bool
param: string $source full path to the existing directory
param: string $destination full path to the new location of the folder
param: bool $keepsourceroot should the root of the $source be kept or removed at the end

remove_directory($path, $keeppathroot = false)   X-Ref
Deletes the given directory recursively

return: bool
param: string $path full path to the directory
param: bool $keeppathroot should the root of the $path be kept (i.e. remove the content only) or removed too

unzip_plugin($ziplocation, $plugintyperoot, $expectedlocation, $backuplocation)   X-Ref
Unzip the file obtained from the Plugins directory to this site

param: string $ziplocation full path to the ZIP file
param: string $plugintyperoot full path to the plugin's type location
param: string $expectedlocation expected full path to the plugin after it is extracted
param: string|bool $backuplocation location of the previous version of the plugin or false for no backup

redirect($url)   X-Ref
Redirect the browser

param: string $url

Class: exception_handlers  - X-Ref

Provides exception handlers for this script

set_handler($handler)   X-Ref
Sets the exception handler

param: string $handler name

format_exception_info(Exception $e)   X-Ref
Returns the text describing the thrown exception

By default, PHP displays full path to scripts when the exception is thrown. In order to prevent
sensitive information leak (and yes, the path to scripts at a web server _is_ sensitive information)
the path to scripts is removed from the message.

return: string
param: Exception $e thrown exception

bootstrap_exception_handler(Exception $e)   X-Ref
Very basic exception handler

param: Exception $e uncaught exception

default_exception_handler(Exception $e)   X-Ref
Default exception handler

When this handler is used, input_manager and output_manager singleton instances already
exist in the memory and can be used.

param: Exception $e uncaught exception

Search This Site: