Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
This library includes all the necessary stuff to use the one-click download and install feature of Moodle, used to keep updated some items like languages, pear, enviroment... i.e, components. More...
Classes | |
class | component_installer |
This class is used to check, download and install items from download.moodle.org to the moodledata directory. More... | |
class | lang_installer |
End of component_installer class. More... | |
class | lang_installer_exception |
Exception thrown by lang_installer. More... | |
Variables | |
global object | $CFG |
$CFG | |
const | COMPONENT_ERROR 0 |
const | COMPONENT_INSTALLED 3 |
const | COMPONENT_NEEDUPDATE 2 |
const | COMPONENT_UPTODATE 1 |
This library includes all the necessary stuff to use the one-click download and install feature of Moodle, used to keep updated some items like languages, pear, enviroment... i.e, components.
It has been developed harcoding some important limits that are explained below:
General Usage:
To install one component: require_once($CFG->libdir.'/componentlib.class.php'); if ($cd = new component_installer('https://download.moodle.org', 'langpack/2.0', 'es.zip', 'languages.md5', 'lang')) { $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED) switch ($status) { case COMPONENT_ERROR: if ($cd->get_error() == 'remotedownloaderror') { $a = new stdClass(); $a->url = 'https://download.moodle.org/langpack/2.0/es.zip'; $a->dest= $CFG->dataroot.'/lang'; print_error($cd->get_error(), 'error', '', $a); } else { print_error($cd->get_error(), 'error'); } break; case COMPONENT_UPTODATE: //Print error string or whatever you want to do break; case COMPONENT_INSTALLED: //Print/do whatever you want break; default: //We shouldn't reach this point } } else { //We shouldn't reach this point }
To switch of component (maintaining the rest of settings): $status = $cd->change_zip_file('en.zip'); //returns boolean false on error
To retrieve all the components in one remote md5 file $components = $cd->get_all_components_md5(); //returns boolean false on error, array instead
To check if current component needs to be updated $status = $cd->need_upgrade(); //returns COMPONENT_(ERROR | UPTODATE | NEEDUPDATE)
To get the 3rd field of the md5 file (optional) $field = $cd->get_extra_md5_field(); //returns string (empty if not exists)
For all the error situations the $cd->get_error() method should return always the key of the error to be retrieved by one standard get_string() call against the error.php lang file.
That's all!