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.

Provides tool_installaddon_installer class.

Copyright: 2013 David Mudrak <david@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 409 lines (13 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: tool_installaddon_installer  - X-Ref

Implements main plugin features.

instance()   X-Ref
Factory method returning an instance of this class.

return: tool_installaddon_installer

index_url(array $params = null)   X-Ref
Returns the URL to the main page of this admin tool

param: array optional parameters
return: moodle_url

get_addons_repository_url()   X-Ref
Returns URL to the repository that addons can be searched in and installed from

return: moodle_url

get_installfromzip_form()   X-Ref

return: tool_installaddon_installfromzip_form

make_installfromzip_storage()   X-Ref
Makes a unique writable storage for uploaded ZIP packages.

We need the saved ZIP to survive across multiple requests so that it can
be used by the plugin manager after the installation is confirmed. In
other words, we cannot use make_request_directory() here.

return: string full path to the directory

get_plugin_types_menu()   X-Ref
Returns localised list of available plugin types

return: array (string)plugintype => (string)plugin name

handle_remote_request(tool_installaddon_renderer $output, $request)   X-Ref
Hook method to handle the remote request to install an add-on

This is used as a callback when the admin picks a plugin version in the
Moodle Plugins directory and is redirected back to their site to install
it.

This hook is called early from admin/tool/installaddon/index.php page so that
it has opportunity to take over the UI and display the first confirmation screen.

param: tool_installaddon_renderer $output
param: string|null $request

detect_plugin_component($zipfilepath)   X-Ref
Detect the given plugin's component name

Only plugins that declare valid $plugin->component value in the version.php
are supported.

param: string $zipfilepath full path to the saved ZIP file
return: string|bool declared component name or false if unable to detect

__construct()   X-Ref


get_site_fullname()   X-Ref

return: string this site full name

get_site_url()   X-Ref

return: string this site URL

get_site_major_version()   X-Ref

return: string major version like 2.5, 2.6 etc.

encode_site_information(array $info)   X-Ref
Encodes the given array in a way that can be safely appended as HTTP GET param

Be ware! The recipient may rely on the exact way how the site information is encoded.
Do not change anything here unless you know what you are doing and understand all
consequences! (Don't you love warnings like that, too? :-p)

param: array $info
return: string

should_send_site_info()   X-Ref
Decide if the encoded site information should be sent to the add-ons repository site

For now, we just return true. In the future, we may want to implement some
privacy aware logic (based on site/user preferences for example).

return: bool

decode_remote_request($request)   X-Ref
Decode the request from the Moodle Plugins directory

param: string $request submitted via 'installaddonrequest' HTTP parameter
return: stdClass|bool false on error, object otherwise

extract_versionphp_file($zipfilepath, $targetdir)   X-Ref
Extracts the version.php from the given plugin ZIP file into the target directory

param: string $zipfilepath full path to the saved ZIP file
param: string $targetdir full path to extract the file to
return: string|bool path to the version.php within the $targetpath; false on error (e.g. not found)

detect_plugin_component_from_versionphp($code)   X-Ref
Return the plugin component declared in its version.php file

param: string $code the contents of the version.php file
return: string|bool declared plugin component or false if unable to detect