Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
|
Defines classes used for plugins management. More...
Public Member Functions | |
all_plugins_ok ($moodleversion, &$failedplugins=array(), $branch=null) | |
Checks all dependencies for all installed plugins. | |
archive_plugin_version (\core\plugininfo\base $plugin) | |
Archive the current on-disk plugin code. | |
are_dependencies_satisfied ($dependencies) | |
Check a dependencies list against the list of installed plugins. | |
available_updates () | |
Returns a list of all available updates to be installed. | |
can_cancel_plugin_installation (\core\plugininfo\base $plugin) | |
Can the installation of the new plugin be cancelled? | |
can_cancel_plugin_upgrade (\core\plugininfo\base $plugin) | |
Can the upgrade of the existing plugin be cancelled? | |
can_uninstall_plugin ($component) | |
Is it possible to uninstall the given plugin? | |
cancel_plugin_installation ($component) | |
Removes the plugin code directory if it is not installed yet. | |
check_explicitly_supported ($plugin, $branch) | |
Helper method to determine whether a moodle version is explicitly supported. | |
filter_installable ($remoteinfos) | |
Given the list of remote plugin infos, return just those installable. | |
get_enabled_plugins ($type) | |
Get list of enabled plugins of given type, the result may contain missing plugins. | |
get_installed_plugins ($type) | |
Return list of installed plugins of given type. | |
get_parent_of_subplugin ($subplugintype) | |
Returns the name of the plugin that defines the given subplugin type. | |
get_plugin_info ($component) | |
Returns information about the known plugin, or null. | |
get_plugin_types () | |
Returns the result of core_component::get_plugin_types() ordered for humans. | |
get_plugin_zip_root_dir ($zipfilepath) | |
Detects the plugin's name from its ZIP file. | |
get_plugins () | |
Returns a tree of known plugins and information about them. | |
get_plugins_of_type ($type) | |
Returns list of known plugins of the given type. | |
get_plugintype_root ($plugintype) | |
Returns the full path of the root of the given plugin type. | |
get_present_plugins ($type) | |
Get list of present plugins of given type. | |
get_remote_plugin_info ($component, $version, $exactmatch) | |
Returns information about a plugin in the plugins directory. | |
get_remote_plugin_zip ($url, $md5) | |
Obtain the plugin ZIP file from the given URL. | |
get_subplugins () | |
Returns list of plugins that define their subplugins and the information about them from the db/subplugins.json file. | |
get_subplugins_of_plugin ($component) | |
Returns list of all known subplugins of the given plugin. | |
get_uninstall_url ($component, $return='overview') | |
Returns uninstall URL if exists. | |
install_plugins (array $plugins, $confirmed, $silent) | |
Perform the installation of plugins. | |
is_directory_removable ($fullpath) | |
Check if the given directory can be removed by the web server process. | |
is_plugin_folder_removable ($component) | |
Check to see if the given plugin folder can be removed by the web server process. | |
is_plugintype_writable ($plugintype) | |
Is it possible to create a new plugin directory for the given plugin type? | |
is_remote_plugin_available ($component, $version, $exactmatch) | |
Is the given plugin version available in the plugins directory? | |
is_remote_plugin_installable ($component, $version, &$reason=null, $checkremote=true) | |
Can the given plugin version be installed via the admin UI? | |
list_cancellable_installations () | |
Returns plugins, the installation of which can be cancelled. | |
list_restorable_archives () | |
Returns list of all archives that can be installed to cancel the plugin upgrade. | |
load_available_updates_for_plugin ($component) | |
Returns list of available updates for the given component. | |
missing_dependencies ($availableonly=false) | |
Return a list of missing dependencies. | |
other_plugins_that_require ($component) | |
Get a list of any other plugins that require this one. | |
plugin_external_source ($component) | |
Check to see if the current version of the plugin seems to be a checkout of an external repository. | |
plugin_name ($component) | |
Returns a localized name of a given plugin. | |
plugintype_name ($type) | |
Returns a localized name of a plugin typed in singular form. | |
plugintype_name_plural ($type) | |
Returns a localized name of a plugin type in plural form. | |
remove_plugin_folder (\core\plugininfo\base $plugin) | |
Remove the current plugin code from the dirroot. | |
resolve_requirements (\core\plugininfo\base $plugin, $moodleversion=null, $moodlebranch=null) | |
Resolve requirements and dependencies of a plugin. | |
some_plugins_updatable () | |
Checks if there are some plugins with a known available update. | |
uninstall_plugin ($component, progress_trace $progress) | |
Uninstall the given plugin. | |
unzip_plugin_file ($zipfilepath, $targetdir, $rootdir='') | |
Extracts the saved plugin ZIP file. | |
Static Public Member Functions | |
static | instance () |
Factory method for this class. | |
static | is_deleted_standard_plugin ($type, $name) |
Defines a list of all plugins that were originally shipped in the standard Moodle distribution, but are not anymore and are deleted during upgrades. | |
static | reset_caches ($phpunitreset=false) |
Reset all caches. | |
static | resolve_plugininfo_class ($type) |
Find the plugin info class for given type. | |
static | standard_plugins_list ($type) |
Defines a white list of all plugins shipped in the standard Moodle distribution. | |
Protected Member Functions | |
__construct () | |
Direct initiation not allowed, use the factory method self::instance(). | |
__clone () | |
Sorry, this is singleton. | |
common_uninstall_check (\core\plugininfo\base $pluginfo) | |
Helper method that implements common uninstall prerequisites. | |
get_code_manager () | |
Returns a code_manager instance to be used for the plugins code operations. | |
get_update_api_client () | |
Returns a client for https://download.moodle.org/api/. | |
init_pluginsinfo_property () | |
Init placeholder array for plugin infos. | |
load_enabled_plugins () | |
Load list of all enabled plugins, call before using $this->enabledplugins. | |
load_installed_plugins () | |
Load list of installed plugins, always call before using $this->installedplugins. | |
load_present_plugins () | |
Load list of all present plugins - call before using $this->presentplugins. | |
mtrace ($msg, $eol=PHP_EOL, $debug=null) | |
Outputs the given message via mtrace(). | |
reorder_plugin_types (array $types) | |
Reorders plugin types into a sequence to be displayed. | |
resolve_core_requirements (\core\plugininfo\base $plugin, $moodleversion, $moodlebranch) | |
Helper method to resolve plugin's requirements on the moodle core. | |
resolve_dependency_requirements (\core\plugininfo\base $plugin, $otherpluginname, $requiredversion, $moodlebranch) | |
Helper method to resolve plugin's dependecies on other plugins. | |
Static Protected Attributes | |
static core_plugin_manager | $singletoninstance |
holds the singleton instance | |
Defines classes used for plugins management.
This library provides a unified interface to various plugin types in Moodle. It is mainly used by the plugins management admin page and the plugins check page during the upgrade.
core_plugin_manager::all_plugins_ok | ( | $moodleversion, | |
& | $failedplugins = array(), | ||
$branch = null ) |
Checks all dependencies for all installed plugins.
This is used by install and upgrade. The array passed by reference as the second argument is populated with the list of plugins that have failed dependencies (note that a single plugin can appear multiple times in the $failedplugins).
int | $moodleversion | the version from version.php. |
array | $failedplugins | to return the list of plugins with non-satisfied dependencies |
int | $branch | the current moodle branch, null if not provided |
bool | true if all the dependencies are satisfied for all plugins. |
core_plugin_manager::archive_plugin_version | ( | \core\plugininfo\base | $plugin | ) |
Archive the current on-disk plugin code.
core\plugiinfo\base | $plugin |
bool |
core_plugin_manager::are_dependencies_satisfied | ( | $dependencies | ) |
Check a dependencies list against the list of installed plugins.
array | $dependencies | compenent name to required version or ANY_VERSION. |
bool | true if all the dependencies are satisfied. |
core_plugin_manager::available_updates | ( | ) |
Returns a list of all available updates to be installed.
This is used when "update all plugins" action is performed at the administration UI screen.
Returns array of remote info objects indexed by the plugin component. If there are multiple updates available (typically a mix of stable and non-stable ones), we pick the most mature most recent one.
Plugins without explicit maturity are considered more mature than release candidates but less mature than explicit stable (this should be pretty rare case).
array | (string)component => (core\update\remote_info)remoteinfo |
core_plugin_manager::can_cancel_plugin_installation | ( | \core\plugininfo\base | $plugin | ) |
Can the installation of the new plugin be cancelled?
Subplugins can be cancelled only via their parent plugin, not separately (they are considered as implicit requirements if distributed together with the main package).
core\plugininfo\base | $plugin |
bool |
core_plugin_manager::can_cancel_plugin_upgrade | ( | \core\plugininfo\base | $plugin | ) |
Can the upgrade of the existing plugin be cancelled?
Subplugins can be cancelled only via their parent plugin, not separately (they are considered as implicit requirements if distributed together with the main package).
core\plugininfo\base | $plugin |
bool |
core_plugin_manager::can_uninstall_plugin | ( | $component | ) |
Is it possible to uninstall the given plugin?
False is returned if the plugininfo subclass declares the uninstall should not be allowed via core::plugininfo::base::is_uninstall_allowed() or if the core vetoes it (e.g. becase the plugin or some of its subplugins is required by some other installed plugin).
string | $component | full frankenstyle name, e.g. mod_foobar |
bool |
core_plugin_manager::cancel_plugin_installation | ( | $component | ) |
Removes the plugin code directory if it is not installed yet.
This is intended for the plugins check screen to give the admin a chance to cancel the installation of just unzipped plugin before the database upgrade happens.
string | $component |
core_plugin_manager::check_explicitly_supported | ( | $plugin, | |
$branch ) |
Helper method to determine whether a moodle version is explicitly supported.
core\plugininfo\base | $plugin | the plugin we are checking |
int | $branch | the moodle branch to check support for |
string |
|
protected |
Helper method that implements common uninstall prerequisites.
core\plugininfo\base | $pluginfo |
bool |
core_plugin_manager::filter_installable | ( | $remoteinfos | ) |
Given the list of remote plugin infos, return just those installable.
This is typically used on lists returned by self::available_updates() or self::missing_dependencies() to perform bulk installation of remote plugins.
array | $remoteinfos | list of core::update::remote_info |
array |
|
protected |
Returns a code_manager instance to be used for the plugins code operations.
core\update\code_manager |
core_plugin_manager::get_enabled_plugins | ( | $type | ) |
Get list of enabled plugins of given type, the result may contain missing plugins.
string | $type |
array|null | list of enabled plugins of this type, null if unknown |
core_plugin_manager::get_installed_plugins | ( | $type | ) |
Return list of installed plugins of given type.
string | $type |
array\$name,=>$version |
core_plugin_manager::get_parent_of_subplugin | ( | $subplugintype | ) |
Returns the name of the plugin that defines the given subplugin type.
If the given subplugin type is not actually a subplugin, returns false.
string | $subplugintype | the name of subplugin type, eg. workshopform or quiz |
false|string | the name of the parent plugin, eg. mod_workshop |
core_plugin_manager::get_plugin_info | ( | $component | ) |
Returns information about the known plugin, or null.
string | $component | frankenstyle component name. |
core\plugininfo\base|null | the corresponding plugin information. |
core_plugin_manager::get_plugin_types | ( | ) |
Returns the result of core_component::get_plugin_types() ordered for humans.
array | (string)name => (string)location |
core_plugin_manager::get_plugin_zip_root_dir | ( | $zipfilepath | ) |
Detects the plugin's name from its ZIP file.
Plugin ZIP packages are expected to contain a single directory and the directory name would become the plugin name once extracted to the Moodle dirroot.
string | $zipfilepath | full path to the ZIP files |
string|bool | false on error |
core_plugin_manager::get_plugins | ( | ) |
Returns a tree of known plugins and information about them.
array | 2D array. The first keys are plugin type names (e.g. qtype); the second keys are the plugin local name (e.g. multichoice); and the values are the corresponding objects extending core::plugininfo::base |
core_plugin_manager::get_plugins_of_type | ( | $type | ) |
Returns list of known plugins of the given type.
This method returns the subset of the tree returned by self::get_plugins(). If the given type is not known, empty array is returned.
string | $type | plugin type, e.g. 'mod' or 'workshopallocation' |
core\plugininfo\base[] | (string)plugin name (e.g. 'workshop') => corresponding subclass of core\plugininfo\base |
core_plugin_manager::get_plugintype_root | ( | $plugintype | ) |
Returns the full path of the root of the given plugin type.
Null is returned if the plugin type is not known. False is returned if the plugin type root is expected but not found. Otherwise, string is returned.
string | $plugintype |
string|bool|null |
core_plugin_manager::get_present_plugins | ( | $type | ) |
Get list of present plugins of given type.
string | $type |
array|null | list of presnet plugins $name=>$diskversion, null if unknown |
core_plugin_manager::get_remote_plugin_info | ( | $component, | |
$version, | |||
$exactmatch ) |
Returns information about a plugin in the plugins directory.
This is typically used when checking for available dependencies (in which case the $version represents minimal version we need), or when installing an available update or a new plugin from the plugins directory (in which case the $version is exact version we are interested in). The interpretation of the $version is controlled by the $exactmatch argument.
If a plugin with the given component name is found, data about the plugin are returned as an object. The ->version property of the object contains the information about the particular plugin version that matches best the given critera. The ->version property is false if no suitable version of the plugin was found (yet the plugin itself is known).
See core::update::api::validate_pluginfo_format() for the returned data structure.
string | $component | plugin frankenstyle name |
string | int | $version | ANY_VERSION or the version number |
bool | $exactmatch | false if "given version or higher" is requested |
core\update\remote_info|bool |
core_plugin_manager::get_remote_plugin_zip | ( | $url, | |
$md5 ) |
Obtain the plugin ZIP file from the given URL.
The caller is supposed to know both downloads URL and the MD5 hash of the ZIP contents in advance, typically by using the API requests against the plugins directory.
string | $url | |
string | $md5 |
string|bool | full path to the file, false on error |
core_plugin_manager::get_subplugins | ( | ) |
Returns list of plugins that define their subplugins and the information about them from the db/subplugins.json file.
array | with keys like 'mod_quiz', and values the data from the corresponding db/subplugins.json file. |
core_plugin_manager::get_subplugins_of_plugin | ( | $component | ) |
Returns list of all known subplugins of the given plugin.
For plugins that do not provide subplugins (i.e. there is no support for it), empty array is returned.
string | $component | full component name, e.g. 'mod_workshop' |
array | (string) component name (e.g. 'workshopallocation_random') => subclass of core::plugininfo::base |
core_plugin_manager::get_uninstall_url | ( | $component, | |
$return = 'overview' ) |
Returns uninstall URL if exists.
string | $component | |
string | $return | either 'overview' or 'manage' |
moodle_url | uninstall URL, null if uninstall not supported |
|
protected |
Returns a client for https://download.moodle.org/api/.
core\update\api |
core_plugin_manager::install_plugins | ( | array | $plugins, |
$confirmed, | |||
$silent ) |
Perform the installation of plugins.
If used for installation of remote plugins from the Moodle Plugins directory, the $plugins must be list of core::update::remote_info object that represent installable remote plugins. The caller can use self::filter_installable() to prepare the list.
If used for installation of plugins from locally available ZIP files, the $plugins should be list of objects with properties ->component and ->zipfilepath.
The method uses mtrace() to produce direct output and can be used in both web and cli interfaces.
array | $plugins | list of plugins |
bool | $confirmed | should the files be really deployed into the dirroot? |
bool | $silent | perform without output |
bool | true on success |
|
static |
Factory method for this class.
static | the singleton instance |
|
static |
Defines a list of all plugins that were originally shipped in the standard Moodle distribution, but are not anymore and are deleted during upgrades.
The main purpose of this list is to hide missing plugins during upgrade.
string | $type | plugin type |
string | $name | plugin name |
bool |
core_plugin_manager::is_directory_removable | ( | $fullpath | ) |
Check if the given directory can be removed by the web server process.
This recursively checks that the given directory and all its contents it writable.
string | $fullpath |
boolean |
core_plugin_manager::is_plugin_folder_removable | ( | $component | ) |
Check to see if the given plugin folder can be removed by the web server process.
string | $component | full frankenstyle component |
bool |
core_plugin_manager::is_plugintype_writable | ( | $plugintype | ) |
Is it possible to create a new plugin directory for the given plugin type?
coding_exception | for invalid plugin types or non-existing plugin type locations |
string | $plugintype |
boolean |
core_plugin_manager::is_remote_plugin_available | ( | $component, | |
$version, | |||
$exactmatch ) |
Is the given plugin version available in the plugins directory?
See self::get_remote_plugin_info() for the full explanation of how the $version parameter is interpretted.
string | $component | plugin frankenstyle name |
string | int | $version | ANY_VERSION or the version number |
bool | $exactmatch | false if "given version or higher" is requested |
boolean |
core_plugin_manager::is_remote_plugin_installable | ( | $component, | |
$version, | |||
& | $reason = null, | ||
$checkremote = true ) |
Can the given plugin version be installed via the admin UI?
This check should be used whenever attempting to install a plugin from the plugins directory (new install, available update, missing dependency).
string | $component | |
int | $version | version number |
string | $reason | returned code of the reason why it is not |
bool | $checkremote | check this version availability on moodle server |
boolean |
core_plugin_manager::list_cancellable_installations | ( | ) |
Returns plugins, the installation of which can be cancelled.
array | [(string)component] => (core\plugininfo\base)plugin |
core_plugin_manager::list_restorable_archives | ( | ) |
Returns list of all archives that can be installed to cancel the plugin upgrade.
array | [(string)component] => {(string)->component, (string)->zipfilepath} |
core_plugin_manager::load_available_updates_for_plugin | ( | $component | ) |
Returns list of available updates for the given component.
This method should be considered as internal API and is supposed to be called by core::plugininfo::base::available_updates() only to lazy load the data once they are first requested.
string | $component | frankenstyle name of the plugin |
null|array | array of core\update\info objects or null |
|
protected |
Load list of all enabled plugins, call before using $this->enabledplugins.
This method is caching results from individual plugin info classes.
|
protected |
Load list of installed plugins, always call before using $this->installedplugins.
This method is caching results for all plugins.
core_plugin_manager::missing_dependencies | ( | $availableonly = false | ) |
Return a list of missing dependencies.
This should provide the full list of plugins that should be installed to fulfill the requirements of all plugins, if possible.
bool | $availableonly | return only available missing dependencies |
array | of core\update\remote_info|bool indexed by the component name |
|
protected |
Outputs the given message via mtrace().
If $debug is provided, then the message is displayed only at the given debugging level (e.g. DEBUG_DEVELOPER to display the message only if the site has developer debugging level selected).
string | $msg | message |
string | $eol | end of line |
null | int | $debug | null to display always, int only on given debug level |
core_plugin_manager::other_plugins_that_require | ( | $component | ) |
Get a list of any other plugins that require this one.
string | $component | frankenstyle component name. |
array | of frankensyle component names that require this one. |
core_plugin_manager::plugin_external_source | ( | $component | ) |
Check to see if the current version of the plugin seems to be a checkout of an external repository.
string | $component | frankenstyle component name |
false|string |
core_plugin_manager::plugin_name | ( | $component | ) |
Returns a localized name of a given plugin.
string | $component | name of the plugin, eg mod_workshop or auth_ldap |
string |
core_plugin_manager::plugintype_name | ( | $type | ) |
Returns a localized name of a plugin typed in singular form.
Most plugin types define their names in core_plugin lang file. In case of subplugins, we try to ask the parent plugin for the name. In the worst case, we will return the value of the passed $type parameter.
string | $type | the type of the plugin, e.g. mod or workshopform |
string |
core_plugin_manager::plugintype_name_plural | ( | $type | ) |
Returns a localized name of a plugin type in plural form.
Most plugin types define their names in core_plugin lang file. In case of subplugins, we try to ask the parent plugin for the name. In the worst case, we will return the value of the passed $type parameter.
string | $type | the type of the plugin, e.g. mod or workshopform |
string |
core_plugin_manager::remove_plugin_folder | ( | \core\plugininfo\base | $plugin | ) |
Remove the current plugin code from the dirroot.
If removing the currently installed version (which happens during updates), we archive the code so that the upgrade can be cancelled.
To prevent accidental data-loss, we also archive the existing plugin code if cancelling installation of it, so that the developer does not loose the only version of their work-in-progress.
core\plugininfo\base | $plugin |
|
protected |
Reorders plugin types into a sequence to be displayed.
For technical reasons, plugin types returned by core_component::get_plugin_types() are in a certain order that does not need to fit the expected order for the display. Particularly, activity modules should be displayed first as they represent the real heart of Moodle. They should be followed by other plugin types that are used to build the courses (as that is what one expects from LMS). After that, other supportive plugin types follow.
array | $types | associative array |
array | same array with altered order of items |
|
static |
Reset all caches.
bool | $phpunitreset |
|
protected |
Helper method to resolve plugin's requirements on the moodle core.
core\plugininfo\base | $plugin | the plugin we are checking |
string | int | double | $moodleversion | moodle core branch to check against |
stdObject |
|
protected |
Helper method to resolve plugin's dependecies on other plugins.
core\plugininfo\base | $plugin | the plugin we are checking |
string | $otherpluginname | |
string | int | $requiredversion | |
string | int | $moodlebranch | explicit moodle core branch to check against, defaults to $CFG->branch |
stdClass |
|
static |
Find the plugin info class for given type.
string | $type |
string | name of pluginfo class for give plugin type |
core_plugin_manager::resolve_requirements | ( | \core\plugininfo\base | $plugin, |
$moodleversion = null, | |||
$moodlebranch = null ) |
Resolve requirements and dependencies of a plugin.
Returns an array of objects describing the requirement/dependency, indexed by the frankenstyle name of the component. The returned array can be empty. The objects in the array have following properties:
->(numeric)hasver ->(numeric)reqver ->(string)status ->(string)availability
core\plugininfo\base | $plugin | the plugin we are checking |
null | string | int | double | $moodleversion | explicit moodle core version to check against, defaults to $CFG->version |
null | string | int | $moodlebranch | explicit moodle core branch to check against, defaults to $CFG->branch |
array | of objects |
core_plugin_manager::some_plugins_updatable | ( | ) |
Checks if there are some plugins with a known available update.
bool | true if there is at least one available update |
|
static |
Defines a white list of all plugins shipped in the standard Moodle distribution.
string | $type |
false|array | array of standard plugins or false if the type is unknown |
core_plugin_manager::uninstall_plugin | ( | $component, | |
progress_trace | $progress ) |
Uninstall the given plugin.
Automatically cleans-up all remaining configuration data, log records, events, files from the file pool etc.
In the future, the functionality of uninstall_plugin() function may be moved into this method and all the code should be refactored to use it. At the moment, we mimic this future behaviour by wrapping that function call.
string | $component | |
progress_trace | $progress | traces the process |
bool | true on success, false on errors/problems |
core_plugin_manager::unzip_plugin_file | ( | $zipfilepath, | |
$targetdir, | |||
$rootdir = '' ) |
Extracts the saved plugin ZIP file.
Returns the list of files found in the ZIP. The format of that list is array of (string)filerelpath => (bool|string) where the array value is either true or a string describing the problematic file.
string | $zipfilepath | full path to the saved ZIP file |
string | $targetdir | full path to the directory to extract the ZIP file to |
string | $rootdir | explicitly rename the root directory of the ZIP into this non-empty value |
array | list of extracted files as returned by zip_packer::extract_to_pathname() |