* 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 * } *
* $status = $cd->change_zip_file('en.zip'); //returns boolean false on error *
* $components = $cd->get_all_components_md5(); //returns boolean false on error, array instead *
* $status = $cd->need_upgrade(); //returns COMPONENT_(ERROR | UPTODATE | NEEDUPDATE) *
* $field = $cd->get_extra_md5_field(); //returns string (empty if not exists) *