Пример #1
0
 /**
  * Updated all install language packs with the latest found on servre
  *
  * @return bool true if languages succesfully updated.
  */
 public function update_all_installed_languages()
 {
     global $CFG;
     if (!($availablelangs = $this->installer->get_remote_list_of_languages())) {
         $this->errors[] = get_string('cannotdownloadlanguageupdatelist', 'error');
         return false;
     }
     $md5array = array();
     // Convert to (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)) {
             $this->info[] = 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;
         }
     }
     // Filter out packs that have the same md5 key.
     $neededlangs = array();
     foreach ($updateablelangs as $ulang) {
         if (!$this->is_installed_lang($ulang, $md5array[$ulang])) {
             $neededlangs[] = $ulang;
         }
     }
     try {
         $updated = $this->install_languagepacks($neededlangs, true);
     } catch (\moodle_exception $e) {
         $this->errors[] = 'An exception occurred while installing language packs: ' . $e->getMessage();
         return false;
     }
     if ($updated) {
         $this->info[] = get_string('langupdatecomplete', 'tool_langimport');
         // The strings have been changed so we need to purge their cache to ensure users see the changes.
         get_string_manager()->reset_caches();
     } else {
         $this->info[] = get_string('nolangupdateneeded', 'tool_langimport');
     }
     return true;
 }
Пример #2
0
get_string_manager()->reset_caches();
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('langimport', 'tool_langimport'));
$installedlangs = get_string_manager()->get_list_of_translations(true);
$missingparents = array();
foreach ($installedlangs as $installedlang => $unused) {
    $parent = get_parent_language($installedlang);
    if (empty($parent)) {
        continue;
    }
    if (!isset($installedlangs[$parent])) {
        $missingparents[$installedlang] = $parent;
    }
}
$installer = new lang_installer();
if ($availablelangs = $installer->get_remote_list_of_languages()) {
    $remote = true;
} else {
    $remote = false;
    $availablelangs = array();
    echo $OUTPUT->box_start();
    print_string('remotelangnotavailable', 'tool_langimport', $CFG->dataroot . '/lang/');
    echo $OUTPUT->box_end();
}
if ($notice_ok) {
    $info = implode('<br />', $notice_ok);
    echo $OUTPUT->notification($info, 'notifysuccess');
}
if ($notice_error) {
    $info = implode('<br />', $notice_error);
    echo $OUTPUT->notification($info, 'notifyproblem');
Пример #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
 /**
  * Updated all install language packs with the latest found on servre
  *
  * @return bool true if languages succesfully updated.
  */
 public function update_all_installed_languages()
 {
     global $CFG;
     if (!($availablelangs = $this->installer->get_remote_list_of_languages())) {
         $this->errors[] = get_string('cannotdownloadlanguageupdatelist', 'error');
         return false;
     }
     $md5array = array();
     // Convert to (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)) {
             $noticeok[] = 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;
         }
     }
     // Filter out packs that have the same md5 key.
     $neededlangs = array();
     foreach ($updateablelangs as $ulang) {
         if (!$this->is_installed_lang($ulang, $md5array[$ulang])) {
             $neededlangs[] = $ulang;
         }
     }
     // 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;
         if (file_exists($dest1)) {
             if (!remove_dir($dest1)) {
                 $noticeerror[] = '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)) {
                 $noticeerror[] = 'Could not delete old directory ' . $dest2 . ', update of ' . $pack . ' failed, please check permissions.';
                 unset($neededlangs[$packindex]);
                 continue;
             }
         }
     }
     try {
         $updated = $this->install_languagepacks($neededlangs, true);
     } catch (\moodle_exception $e) {
         return false;
     }
     if ($updated) {
         $this->info[] = get_string('langupdatecomplete', 'tool_langimport');
     } else {
         $this->info[] = get_string('nolangupdateneeded', 'tool_langimport');
     }
     return true;
 }