Exemple #1
0
 public function test_component_installer()
 {
     global $CFG;
     $ci = new component_installer('http://download.moodle.org', 'unittest', 'downloadtests.zip');
     $this->assertTrue($ci->check_requisites());
     $destpath = $CFG->dataroot . '/downloadtests';
     //carefully remove component files to enforce fresh installation
     @unlink($destpath . '/' . 'downloadtests.md5');
     @unlink($destpath . '/' . 'test.html');
     @unlink($destpath . '/' . 'test.jpg');
     @rmdir($destpath);
     $this->assertEqual(COMPONENT_NEEDUPDATE, $ci->need_upgrade());
     $status = $ci->install();
     $this->assertEqual(COMPONENT_INSTALLED, $status);
     $this->assertEqual('9e94f74b3efb1ff6cf075dc6b2abf15c', $ci->get_component_md5());
     //it's already installed, so Moodle should detect it's up to date
     $this->assertEqual(COMPONENT_UPTODATE, $ci->need_upgrade());
     $status = $ci->install();
     $this->assertEqual(COMPONENT_UPTODATE, $status);
     //check if correct files were downloaded
     $this->assertEqual('2af180e813dc3f446a9bb7b6af87ce24', md5_file($destpath . '/' . 'test.jpg'));
     $this->assertEqual('47250a973d1b88d9445f94db4ef2c97a', md5_file($destpath . '/' . 'test.html'));
 }
Exemple #2
0
 $rm2 = false;
 if (file_exists($dest1)) {
     if (!remove_dir($dest1)) {
         $notice_error[] = 'Could not delete old directory ' . $dest1 . ', update of ' . $pack . ' failed, please check permissions.';
         continue;
     }
 }
 if (file_exists($dest2)) {
     if (!remove_dir($dest2)) {
         $notice_error[] = 'Could not delete old directory ' . $dest2 . ', update of ' . $pack . ' failed, please check permissions.';
         continue;
     }
 }
 //2. copy & unzip into new
 if ($cd = new component_installer('http://download.moodle.org', 'lang16', $pack . '.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 = 'http://download.moodle.org/lang16/' . $pack . '.zip';
                 $a->dest = $CFG->dataroot . '/lang';
                 print_error($cd->get_error(), 'error', "", $a);
                 // not probable
             } else {
                 print_error($cd->get_error(), 'error');
                 // not probable
             }
             break;
         case COMPONENT_UPTODATE:
 /**
  * Perform the actual language pack installation
  *
  * @uses component_installer
  * @param string $langcode
  * @return int return status
  */
 protected function install_language_pack($langcode)
 {
     // initialise new component installer to process this language
     $installer = new component_installer('http://download.moodle.org', 'download.php/direct/langpack/' . $this->version, $langcode . '.zip', 'languages.md5', 'lang');
     if (!$installer->requisitesok) {
         throw new lang_installer_exception('installer_requisites_check_failed');
     }
     $status = $installer->install();
     if ($status == COMPONENT_ERROR) {
         if ($installer->get_error() === 'remotedownloaderror') {
             return self::RESULT_DOWNLOADERROR;
         } else {
             throw new lang_installer_exception($installer->get_error(), $langcode);
         }
     } else {
         if ($status == COMPONENT_UPTODATE) {
             return self::RESULT_UPTODATE;
         } else {
             if ($status == COMPONENT_INSTALLED) {
                 return self::RESULT_INSTALLED;
             } else {
                 throw new lang_installer_exception('unexpected_installer_result', $status);
             }
         }
     }
 }
Exemple #4
0
if ($CFG->lang != 'en') {
    if ($cd = new component_installer('http://download.moodle.org', 'langpack/2.0', $CFG->lang . '.zip', 'languages.md5', 'lang')) {
        if ($cd->install() == COMPONENT_ERROR) {
            if ($cd->get_error() == 'remotedownloaderror') {
                $a = new stdClass();
                $a->url = 'http://download.moodle.org/langpack/2.0/' . $CFG->lang . '.zip';
                $a->dest = $CFG->dataroot . '/lang';
                cli_problem(get_string($cd->get_error(), 'error', $a));
            } else {
                cli_problem(get_string($cd->get_error(), 'error'));
            }
        } else {
            // install parent lang if defined
            if ($parentlang = get_parent_language()) {
                if ($cd = new component_installer('http://download.moodle.org', 'langpack/2.0', $parentlang . '.zip', 'languages.md5', 'lang')) {
                    $cd->install();
                }
            }
        }
    }
}
// switch the string_manager instance to stop using install/lang/
$CFG->early_install_lang = false;
$CFG->langotherroot = $CFG->dataroot . '/lang';
$CFG->langlocalroot = $CFG->dataroot . '/lang';
get_string_manager(true);
// make sure we are installing stable release or require a confirmation
if (isset($maturity)) {
    if ($maturity < MATURITY_STABLE and !$options['allow-unstable']) {
        $maturitylevel = get_string('maturity' . $maturity, 'admin');
        if ($interactive) {
Exemple #5
0
/**
 * Try to upgrade the given language pack (or current language)
 * If it doesn't work, fail silently and return false
 */
function upgrade_language_pack($lang = '')
{
    global $CFG;
    if (empty($lang)) {
        $lang = current_language();
    }
    if ($lang == 'en_utf8') {
        return true;
        // Nothing to do
    }
    notify(get_string('langimport', 'admin') . ': ' . $lang . ' ... ', 'notifysuccess');
    @mkdir($CFG->dataroot . '/temp/');
    //make it in case it's a fresh install, it might not be there
    @mkdir($CFG->dataroot . '/lang/');
    require_once $CFG->libdir . '/componentlib.class.php';
    if ($cd = new component_installer('http://download.moodle.org', 'lang16', $lang . '.zip', 'languages.md5', 'lang')) {
        $status = $cd->install();
        //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
        if ($status == COMPONENT_INSTALLED) {
            debugging('Downloading successful: ' . $lang);
            @unlink($CFG->dataroot . '/cache/languages');
            return true;
        }
    }
    return false;
}
Exemple #6
0
/**
 * Try to upgrade the given language pack (or current language)
 * @global object
 */
function upgrade_language_pack($lang = '')
{
    global $CFG, $OUTPUT;
    if (empty($lang)) {
        $lang = current_language();
    }
    if ($lang == 'en_utf8') {
        return true;
        // Nothing to do
    }
    upgrade_started(false);
    echo $OUTPUT->heading(get_string('langimport', 'admin') . ': ' . $lang);
    @mkdir($CFG->dataroot . '/temp/');
    //make it in case it's a fresh install, it might not be there
    @mkdir($CFG->dataroot . '/lang/');
    require_once $CFG->libdir . '/componentlib.class.php';
    if ($cd = new component_installer('http://download.moodle.org', 'lang16', $lang . '.zip', 'languages.md5', 'lang')) {
        $status = $cd->install();
        //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
        if ($status == COMPONENT_INSTALLED) {
            @unlink($CFG->dataroot . '/cache/languages');
            if ($parentlang = get_parent_language($lang)) {
                if ($cd = new component_installer('http://download.moodle.org', 'lang16', $parentlang . '.zip', 'languages.md5', 'lang')) {
                    $cd->install();
                }
            }
            echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
        }
    }
    print_upgrade_separator();
}
 public function installLangPack($pack)
 {
     global $CFG;
     require_once $CFG->libdir . '/adminlib.php';
     require_once $CFG->libdir . '/filelib.php';
     require_once $CFG->libdir . '/componentlib.class.php';
     $thisversion = '2.0';
     // TODO this information should be taken from version.php or similar source
     make_upload_directory('lang');
     if (is_array($pack)) {
         $packs = $pack;
     } else {
         $packs = array($pack);
     }
     foreach ($packs as $pack) {
         if ($cd = new component_installer('http://download.moodle.org', 'langpack/' . $thisversion, $pack . '.zip', 'languages.md5', 'lang')) {
             $status = $cd->install();
             switch ($status) {
                 case COMPONENT_ERROR:
                     if ($cd->get_error() == 'remotedownloaderror') {
                         $a = new stdClass();
                         $a->url = 'http://download.moodle.org/langpack/' . $thisversion . '/' . $pack . '.zip';
                         $a->dest = $CFG->dataroot . '/lang';
                         print_error($cd->get_error(), 'error', 'langimport.php', $a);
                     } else {
                         print_error($cd->get_error(), 'error', 'langimport.php');
                     }
                     break;
                 case COMPONENT_INSTALLED:
                     if ($parentlang = get_parent_language($pack)) {
                         // install also parent pack if specified
                         if ($cd = new component_installer('http://download.moodle.org', 'langpack/' . $thisversion, $parentlang . '.zip', 'languages.md5', 'lang')) {
                             $cd->install();
                         }
                     }
                     break;
             }
         } else {
             echo $OUTPUT->notification('Had an unspecified error with the component installer, sorry.');
         }
     }
 }