Пример #1
0
 /**
  * Install language packs provided
  *
  * @param string|array $langs array of langcodes or individual langcodes
  * @param bool $updating true if updating the langpacks
  * @return int false if an error encountered or
  * @throws \moodle_exception when error is encountered installing langpack
  */
 public function install_languagepacks($langs, $updating = false)
 {
     global $CFG;
     $this->installer->set_queue($langs);
     $results = $this->installer->run();
     $updatedpacks = 0;
     foreach ($results as $langcode => $langstatus) {
         switch ($langstatus) {
             case \lang_installer::RESULT_DOWNLOADERROR:
                 $a = new \stdClass();
                 $a->url = $this->installer->lang_pack_url($langcode);
                 $a->dest = $CFG->dataroot . '/lang';
                 $this->errors[] = get_string('remotedownloaderror', 'error', $a);
                 throw new \moodle_exception('remotedownloaderror', 'error', $a);
                 break;
             case \lang_installer::RESULT_INSTALLED:
                 $updatedpacks++;
                 if ($updating) {
                     event\langpack_updated::event_with_langcode($langcode)->trigger();
                     $this->info[] = get_string('langpackupdated', 'tool_langimport', $langcode);
                 } else {
                     $this->info[] = get_string('langpackinstalled', 'tool_langimport', $langcode);
                     event\langpack_imported::event_with_langcode($langcode)->trigger();
                 }
                 break;
             case \lang_installer::RESULT_UPTODATE:
                 $this->info[] = get_string('langpackuptodate', 'tool_langimport', $langcode);
                 break;
         }
     }
     return $updatedpacks;
 }
Пример #2
0
    if (!empty($distro->dbtype)) {
        $config->stage = INSTALL_DATABASE;
    }
}


if ($config->stage == INSTALL_DOWNLOADLANG) {
    $downloaderror = '';

    // download and install required lang packs, the lang dir has already been created in install_init_dataroot
    $installer = new lang_installer($CFG->lang);
    $results = $installer->run();
    foreach ($results as $langcode => $langstatus) {
        if ($langstatus === lang_installer::RESULT_DOWNLOADERROR) {
            $a       = new stdClass();
            $a->url  = $installer->lang_pack_url($langcode);
            $a->dest = $CFG->dataroot.'/lang';
            $downloaderror = get_string('remotedownloaderror', 'error', $a);
        }
    }

    if ($downloaderror !== '') {
        install_print_header($config, get_string('language'), get_string('langdownloaderror', 'install', $CFG->lang), $downloaderror);
        install_print_footer($config);
        die;
    } else {
        if (empty($distro->dbtype)) {
            $config->stage = INSTALL_DATABASETYPE;
        } else {
            $config->stage = INSTALL_DATABASE;
        }
Пример #3
0
 private function update_all_languages($lang)
 {
     // TODO: Use above $lang to update a single language pack.
     global $CFG;
     require_once $CFG->libdir . '/filelib.php';
     require_once $CFG->libdir . '/componentlib.class.php';
     \core_php_time_limit::raise();
     $installer = new \lang_installer();
     if (!($availablelangs = $installer->get_remote_list_of_languages())) {
         print_error('cannotdownloadlanguageupdatelist', 'error');
     }
     $md5array = array();
     // (string)langcode => (string)md5
     foreach ($availablelangs as $alang) {
         $md5array[$alang[0]] = $alang[1];
     }
     // filter out unofficial packs
     $currentlangs = array_keys(get_string_manager()->get_list_of_translations(true));
     $updateablelangs = array();
     foreach ($currentlangs as $clang) {
         if (!array_key_exists($clang, $md5array)) {
             $notice_ok[] = get_string('langpackupdateskipped', 'tool_langimport', $clang);
             continue;
         }
         $dest1 = $CFG->dataroot . '/lang/' . $clang;
         $dest2 = $CFG->dirroot . '/lang/' . $clang;
         if (file_exists($dest1 . '/langconfig.php') || file_exists($dest2 . '/langconfig.php')) {
             $updateablelangs[] = $clang;
         }
     }
     // then filter out packs that have the same md5 key
     $neededlangs = array();
     // all the packs that needs updating
     foreach ($updateablelangs as $ulang) {
         if (!$this->is_installed_lang($ulang, $md5array[$ulang])) {
             $neededlangs[] = $ulang;
         }
     }
     make_temp_directory('');
     make_upload_directory('lang');
     // clean-up currently installed versions of the packs
     foreach ($neededlangs as $packindex => $pack) {
         if ($pack == 'en') {
             continue;
         }
         // delete old directories
         $dest1 = $CFG->dataroot . '/lang/' . $pack;
         $dest2 = $CFG->dirroot . '/lang/' . $pack;
         $rm1 = false;
         $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.';
                 unset($neededlangs[$packindex]);
                 continue;
             }
         }
         if (file_exists($dest2)) {
             if (!remove_dir($dest2)) {
                 $notice_error[] = 'Could not delete old directory ' . $dest2 . ', update of ' . $pack . ' failed, please check permissions.';
                 unset($neededlangs[$packindex]);
                 continue;
             }
         }
     }
     // install all needed language packs
     $installer->set_queue($neededlangs);
     $results = $installer->run();
     $updated = false;
     // any packs updated?
     foreach ($results as $langcode => $langstatus) {
         switch ($langstatus) {
             case \lang_installer::RESULT_DOWNLOADERROR:
                 $a = new stdClass();
                 $a->url = $installer->lang_pack_url($langcode);
                 $a->dest = $CFG->dataroot . '/lang';
                 print_error('remotedownloaderror', 'error', 'index.php', $a);
                 break;
             case \lang_installer::RESULT_INSTALLED:
                 $updated = true;
                 $notice_ok[] = get_string('langpackinstalled', 'tool_langimport', $langcode);
                 break;
             case \lang_installer::RESULT_UPTODATE:
                 $notice_ok[] = get_string('langpackuptodate', 'tool_langimport', $langcode);
                 break;
         }
     }
     if ($updated) {
         $notice_ok[] = get_string('langupdatecomplete', 'tool_langimport');
     } else {
         $notice_ok[] = get_string('nolangupdateneeded', 'tool_langimport');
     }
     unset($installer);
     get_string_manager()->reset_caches();
 }
Пример #4
0
 /**
  * Returns the URL where a given language pack can be downloaded
  *
  * Alternatively, if the parameter is empty, returns URL of the page with the
  * list of all available language packs.
  *
  * @param string $langcode language code like 'cs' or empty for unknown
  * @return string URL
  */
 public function lang_pack_url($langcode = '')
 {
     return $this->installer->lang_pack_url($langcode);
 }