Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]
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.
Copyright: | 2011 David Mudrak <david@moodle.com> |
License: | http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
File Size: | 2389 lines (87 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 1 file version.php |
core_plugin_manager:: (63 methods):
__construct()
__clone()
instance()
reset_caches()
get_plugin_types()
load_installed_plugins()
get_installed_plugins()
load_enabled_plugins()
get_enabled_plugins()
load_present_plugins()
get_present_plugins()
get_plugins()
get_plugins_of_type()
init_pluginsinfo_property()
resolve_plugininfo_class()
get_subplugins_of_plugin()
get_subplugins()
get_parent_of_subplugin()
plugin_name()
plugintype_name()
plugintype_name_plural()
get_plugin_info()
plugin_external_source()
other_plugins_that_require()
are_dependencies_satisfied()
all_plugins_ok()
resolve_requirements()
resolve_core_requirements()
resolve_dependency_requirements()
check_explicitly_supported()
is_remote_plugin_available()
is_remote_plugin_installable()
filter_installable()
get_remote_plugin_info()
get_remote_plugin_zip()
unzip_plugin_file()
get_plugin_zip_root_dir()
missing_dependencies()
can_uninstall_plugin()
install_plugins()
mtrace()
get_uninstall_url()
uninstall_plugin()
some_plugins_updatable()
load_available_updates_for_plugin()
available_updates()
is_plugin_folder_removable()
is_plugintype_writable()
get_plugintype_root()
is_deleted_standard_plugin()
standard_plugins_list()
remove_plugin_folder()
can_cancel_plugin_installation()
can_cancel_plugin_upgrade()
cancel_plugin_installation()
list_cancellable_installations()
archive_plugin_version()
list_restorable_archives()
reorder_plugin_types()
is_directory_removable()
common_uninstall_check()
get_code_manager()
get_update_api_client()
Class: core_plugin_manager - X-Ref
Singleton class providing general plugins management functionality.__construct() X-Ref |
Direct initiation not allowed, use the factory method {@link self::instance()} |
__clone() X-Ref |
Sorry, this is singleton |
instance() X-Ref |
Factory method for this class return: core_plugin_manager the singleton instance |
reset_caches($phpunitreset = false) X-Ref |
Reset all caches. param: bool $phpunitreset |
get_plugin_types() X-Ref |
Returns the result of {@link core_component::get_plugin_types()} ordered for humans return: array (string)name => (string)location |
load_installed_plugins() X-Ref |
Load list of installed plugins, always call before using $this->installedplugins. This method is caching results for all plugins. |
get_installed_plugins($type) X-Ref |
Return list of installed plugins of given type. param: string $type return: array $name=>$version |
load_enabled_plugins() X-Ref |
Load list of all enabled plugins, call before using $this->enabledplugins. This method is caching results from individual plugin info classes. |
get_enabled_plugins($type) X-Ref |
Get list of enabled plugins of given type, the result may contain missing plugins. param: string $type return: array|null list of enabled plugins of this type, null if unknown |
load_present_plugins() X-Ref |
Load list of all present plugins - call before using $this->presentplugins. |
get_present_plugins($type) X-Ref |
Get list of present plugins of given type. param: string $type return: array|null list of presnet plugins $name=>$diskversion, null if unknown |
get_plugins() X-Ref |
Returns a tree of known plugins and information about them return: array 2D array. The first keys are plugin type names (e.g. qtype); |
get_plugins_of_type($type) X-Ref |
Returns list of known plugins of the given type. This method returns the subset of the tree returned by {@link self::get_plugins()}. If the given type is not known, empty array is returned. param: string $type plugin type, e.g. 'mod' or 'workshopallocation' return: \core\plugininfo\base[] (string)plugin name (e.g. 'workshop') => corresponding subclass of {@link \core\plugininfo\base} |
init_pluginsinfo_property() X-Ref |
Init placeholder array for plugin infos. |
resolve_plugininfo_class($type) X-Ref |
Find the plugin info class for given type. param: string $type return: string name of pluginfo class for give plugin type |
get_subplugins_of_plugin($component) X-Ref |
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. param: string $component full component name, e.g. 'mod_workshop' return: array (string) component name (e.g. 'workshopallocation_random') => subclass of {@link \core\plugininfo\base} |
get_subplugins() X-Ref |
Returns list of plugins that define their subplugins and the information about them from the db/subplugins.json file. return: array with keys like 'mod_quiz', and values the data from the |
get_parent_of_subplugin($subplugintype) X-Ref |
Returns the name of the plugin that defines the given subplugin type If the given subplugin type is not actually a subplugin, returns false. param: string $subplugintype the name of subplugin type, eg. workshopform or quiz return: false|string the name of the parent plugin, eg. mod_workshop |
plugin_name($component) X-Ref |
Returns a localized name of a given plugin param: string $component name of the plugin, eg mod_workshop or auth_ldap return: string |
plugintype_name($type) X-Ref |
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. param: string $type the type of the plugin, e.g. mod or workshopform return: string |
plugintype_name_plural($type) X-Ref |
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. param: string $type the type of the plugin, e.g. mod or workshopform return: string |
get_plugin_info($component) X-Ref |
Returns information about the known plugin, or null param: string $component frankenstyle component name. return: \core\plugininfo\base|null the corresponding plugin information. |
plugin_external_source($component) X-Ref |
Check to see if the current version of the plugin seems to be a checkout of an external repository. param: string $component frankenstyle component name return: false|string |
other_plugins_that_require($component) X-Ref |
Get a list of any other plugins that require this one. param: string $component frankenstyle component name. return: array of frankensyle component names that require this one. |
are_dependencies_satisfied($dependencies) X-Ref |
Check a dependencies list against the list of installed plugins. param: array $dependencies compenent name to required version or ANY_VERSION. return: bool true if all the dependencies are satisfied. |
all_plugins_ok($moodleversion, &$failedplugins = array() X-Ref |
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). param: int $moodleversion the version from version.php. param: array $failedplugins to return the list of plugins with non-satisfied dependencies param: int $branch the current moodle branch, null if not provided return: bool true if all the dependencies are satisfied for all plugins. |
resolve_requirements(\core\plugininfo\base $plugin, $moodleversion=null, $moodlebranch=null) X-Ref |
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 param: \core\plugininfo\base $plugin the plugin we are checking param: null|string|int|double $moodleversion explicit moodle core version to check against, defaults to $CFG->version param: null|string|int $moodlebranch explicit moodle core branch to check against, defaults to $CFG->branch return: array of objects |
resolve_core_requirements(\core\plugininfo\base $plugin, $moodleversion, $moodlebranch) X-Ref |
Helper method to resolve plugin's requirements on the moodle core. param: \core\plugininfo\base $plugin the plugin we are checking param: string|int|double $moodleversion moodle core branch to check against return: stdObject |
resolve_dependency_requirements(\core\plugininfo\base $plugin, $otherpluginname,$requiredversion, $moodlebranch) X-Ref |
Helper method to resolve plugin's dependecies on other plugins. param: \core\plugininfo\base $plugin the plugin we are checking param: string $otherpluginname param: string|int $requiredversion param: string|int $moodlebranch explicit moodle core branch to check against, defaults to $CFG->branch return: stdClass |
check_explicitly_supported($plugin, $branch) X-Ref |
Helper method to determine whether a moodle version is explicitly supported. param: \core\plugininfo\base $plugin the plugin we are checking param: int $branch the moodle branch to check support for return: string |
is_remote_plugin_available($component, $version, $exactmatch) X-Ref |
Is the given plugin version available in the plugins directory? See {@link self::get_remote_plugin_info()} for the full explanation of how the $version parameter is interpretted. param: string $component plugin frankenstyle name param: string|int $version ANY_VERSION or the version number param: bool $exactmatch false if "given version or higher" is requested return: boolean |
is_remote_plugin_installable($component, $version, &$reason = null, $checkremote = true) X-Ref |
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). param: string $component param: int $version version number param: string $reason returned code of the reason why it is not param: bool $checkremote check this version availability on moodle server return: boolean |
filter_installable($remoteinfos) X-Ref |
Given the list of remote plugin infos, return just those installable. This is typically used on lists returned by {@link self::available_updates()} or {@link self::missing_dependencies()} to perform bulk installation of remote plugins. param: array $remoteinfos list of {@link \core\update\remote_info} return: array |
get_remote_plugin_info($component, $version, $exactmatch) X-Ref |
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 {@link \core\update\api::validate_pluginfo_format()} for the returned data structure. param: string $component plugin frankenstyle name param: string|int $version ANY_VERSION or the version number param: bool $exactmatch false if "given version or higher" is requested return: \core\update\remote_info|bool |
get_remote_plugin_zip($url, $md5) X-Ref |
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. param: string $url param: string $md5 return: string|bool full path to the file, false on error |
unzip_plugin_file($zipfilepath, $targetdir, $rootdir = '') X-Ref |
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. param: string $zipfilepath full path to the saved ZIP file param: string $targetdir full path to the directory to extract the ZIP file to param: string $rootdir explicitly rename the root directory of the ZIP into this non-empty value return: array list of extracted files as returned by {@link zip_packer::extract_to_pathname()} |
get_plugin_zip_root_dir($zipfilepath) X-Ref |
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. param: string $zipfilepath full path to the ZIP files return: string|bool false on error |
missing_dependencies($availableonly=false) X-Ref |
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. param: bool $availableonly return only available missing dependencies return: array of \core\update\remote_info|bool indexed by the component name |
can_uninstall_plugin($component) X-Ref |
Is it possible to uninstall the given plugin? False is returned if the plugininfo subclass declares the uninstall should not be allowed via {@link \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). param: string $component full frankenstyle name, e.g. mod_foobar return: bool |
install_plugins(array $plugins, $confirmed, $silent) X-Ref |
Perform the installation of plugins. If used for installation of remote plugins from the Moodle Plugins directory, the $plugins must be list of {@link \core\update\remote_info} object that represent installable remote plugins. The caller can use {@link 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 {@link mtrace()} to produce direct output and can be used in both web and cli interfaces. param: array $plugins list of plugins param: bool $confirmed should the files be really deployed into the dirroot? param: bool $silent perform without output return: bool true on success |
mtrace($msg, $eol=PHP_EOL, $debug=null) X-Ref |
Outputs the given message via {@link 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). param: string $msg message param: string $eol end of line param: null|int $debug null to display always, int only on given debug level |
get_uninstall_url($component, $return = 'overview') X-Ref |
Returns uninstall URL if exists. param: string $component param: string $return either 'overview' or 'manage' return: moodle_url uninstall URL, null if uninstall not supported |
uninstall_plugin($component, progress_trace $progress) X-Ref |
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 {@link 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. param: string $component param: progress_trace $progress traces the process return: bool true on success, false on errors/problems |
some_plugins_updatable() X-Ref |
Checks if there are some plugins with a known available update return: bool true if there is at least one available update |
load_available_updates_for_plugin($component) X-Ref |
Returns list of available updates for the given component. This method should be considered as internal API and is supposed to be called by {@link \core\plugininfo\base::available_updates()} only to lazy load the data once they are first requested. param: string $component frankenstyle name of the plugin return: null|array array of \core\update\info objects or null |
available_updates() X-Ref |
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). return: array (string)component => (\core\update\remote_info)remoteinfo |
is_plugin_folder_removable($component) X-Ref |
Check to see if the given plugin folder can be removed by the web server process. param: string $component full frankenstyle component return: bool |
is_plugintype_writable($plugintype) X-Ref |
Is it possible to create a new plugin directory for the given plugin type? param: string $plugintype return: boolean |
get_plugintype_root($plugintype) X-Ref |
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. param: string $plugintype return: string|bool|null |
is_deleted_standard_plugin($type, $name) X-Ref |
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. param: string $type plugin type param: string $name plugin name return: bool |
standard_plugins_list($type) X-Ref |
Defines a white list of all plugins shipped in the standard Moodle distribution param: string $type return: false|array array of standard plugins or false if the type is unknown |
remove_plugin_folder(\core\plugininfo\base $plugin) X-Ref |
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. param: \core\plugininfo\base $plugin |
can_cancel_plugin_installation(\core\plugininfo\base $plugin) X-Ref |
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). param: \core\plugininfo\base $plugin return: bool |
can_cancel_plugin_upgrade(\core\plugininfo\base $plugin) X-Ref |
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). param: \core\plugininfo\base $plugin return: bool |
cancel_plugin_installation($component) X-Ref |
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. param: string $component |
list_cancellable_installations() X-Ref |
Returns plugins, the installation of which can be cancelled. return: array [(string)component] => (\core\plugininfo\base)plugin |
archive_plugin_version(\core\plugininfo\base $plugin) X-Ref |
Archive the current on-disk plugin code. param: \core\plugiinfo\base $plugin return: bool |
list_restorable_archives() X-Ref |
Returns list of all archives that can be installed to cancel the plugin upgrade. return: array [(string)component] => {(string)->component, (string)->zipfilepath} |
reorder_plugin_types(array $types) X-Ref |
Reorders plugin types into a sequence to be displayed For technical reasons, plugin types returned by {@link 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. param: array $types associative array return: array same array with altered order of items |
is_directory_removable($fullpath) X-Ref |
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. param: string $fullpath return: boolean |
common_uninstall_check(\core\plugininfo\base $pluginfo) X-Ref |
Helper method that implements common uninstall prerequisites param: \core\plugininfo\base $pluginfo return: bool |
get_code_manager() X-Ref |
Returns a code_manager instance to be used for the plugins code operations. return: \core\update\code_manager |
get_update_api_client() X-Ref |
Returns a client for https://download.moodle.org/api/ return: \core\update\api |