123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <?php
- require_once __DIR__ . '/l10n_update.translation.inc';
- function l10n_update_batch_status_check($project, $langcode, $options = array(), &$context) {
- $failure = $checked = FALSE;
- $options += array(
- 'finish_feedback' => TRUE,
- 'use_remote' => TRUE,
- );
- $source = l10n_update_get_status(array($project), array($langcode));
- $source = $source[$project][$langcode];
-
- if (isset($source->files[L10N_UPDATE_LOCAL])) {
- if ($file = l10n_update_source_check_file($source)) {
- l10n_update_status_save($source->name, $source->langcode, L10N_UPDATE_LOCAL, $file);
- }
- $checked = TRUE;
- }
-
- if ($options['use_remote'] && isset($source->files[L10N_UPDATE_REMOTE])) {
- $remote_file = $source->files[L10N_UPDATE_REMOTE];
- module_load_include('http.inc', 'l10n_update');
- if ($result = l10n_update_http_check($remote_file->uri)) {
-
-
- if (!empty($result->updated)) {
- $remote_file->uri = isset($result->redirect_url) ? $result->redirect_url : $remote_file->uri;
- $remote_file->timestamp = $result->updated;
- l10n_update_status_save($source->name, $source->langcode, L10N_UPDATE_REMOTE, $remote_file);
- }
-
-
-
- $checked = TRUE;
- }
- else {
- $failure = TRUE;
- }
- }
-
-
- if ($options['finish_feedback'] && $checked) {
- $context['results']['files'][] = $source->name;
- }
- if ($failure && !$checked) {
- $context['results']['failed_files'][] = $source->name;
- }
- $context['message'] = t('Checked translation for %project.', array('%project' => $source->project));
- }
- function l10n_update_batch_status_finished($success, $results) {
- if ($success) {
- if (isset($results['failed_files'])) {
- if (module_exists('dblog')) {
- $message = format_plural(count($results['failed_files']), 'One translation file could not be checked. <a href="@url">See the log</a> for details.', '@count translation files could not be checked. <a href="@url">See the log</a> for details.', array('@url' => url('admin/reports/dblog')));
- }
- else {
- $message = format_plural(count($results['failed_files']), 'One translation files could not be checked. See the log for details.', '@count translation files could not be checked. See the log for details.');
- }
- drupal_set_message($message, 'error');
- }
- if (isset($results['files'])) {
- drupal_set_message(format_plural(
- count($results['files']),
- 'Checked available interface translation updates for one project.',
- 'Checked available interface translation updates for @count projects.'
- ));
- }
- if (!isset($results['failed_files']) && !isset($results['files'])) {
- drupal_set_message(t('Nothing to check.'));
- }
- variable_set('l10n_update_last_check', REQUEST_TIME);
- }
- else {
- drupal_set_message(t('An error occurred trying to check available interface translation updates.'), 'error');
- }
- }
- function l10n_update_batch_fetch_download($project, $langcode, &$context) {
- $sources = l10n_update_get_status(array($project), array($langcode));
- if (isset($sources[$project][$langcode])) {
- $source = $sources[$project][$langcode];
- if (isset($source->type) && $source->type == L10N_UPDATE_REMOTE) {
- if ($file = l10n_update_download_source($source->files[L10N_UPDATE_REMOTE], 'translations://')) {
- $context['message'] = t('Downloaded translation for %project.', array('%project' => $source->project));
- l10n_update_status_save($source->name, $source->langcode, L10N_UPDATE_LOCAL, $file);
- }
- else {
- $context['results']['failed_files'][] = $source->files[L10N_UPDATE_REMOTE];
- }
- }
- }
- }
- function l10n_update_batch_fetch_import($project, $langcode, $options, &$context) {
- $sources = l10n_update_get_status(array($project), array($langcode));
- if (isset($sources[$project][$langcode])) {
- $source = $sources[$project][$langcode];
- if (isset($source->type)) {
- if ($source->type == L10N_UPDATE_REMOTE || $source->type == L10N_UPDATE_LOCAL) {
- $file = $source->files[L10N_UPDATE_LOCAL];
- module_load_include('bulk.inc', 'l10n_update');
- $options += array(
- 'message' => t('Importing translation for %project.', array('%project' => $source->project)),
- );
-
-
- l10n_update_batch_import($file, $options, $context);
-
- if (isset($context['finished']) && $context['finished'] == 1) {
-
- if (isset($context['results']['files'][$file->uri])) {
- $context['message'] = t('Imported translation for %project.', array('%project' => $source->project));
-
-
- l10n_update_status_save($project, $langcode, L10N_UPDATE_CURRENT, $source->files[L10N_UPDATE_LOCAL]);
- }
- }
- }
- }
- }
- }
- function l10n_update_batch_fetch_finished($success, $results) {
- module_load_include('bulk.inc', 'l10n_update');
- if ($success) {
- variable_set('l10n_update_last_check', REQUEST_TIME);
- }
- l10n_update_batch_finished($success, $results);
- }
- function l10n_update_download_source($source_file, $directory = 'temporary://') {
- if ($uri = system_retrieve_file($source_file->uri, $directory)) {
- $file = clone($source_file);
- $file->type = L10N_UPDATE_LOCAL;
- $file->uri = $uri;
- $file->directory = $directory;
- $file->timestamp = filemtime($uri);
- return $file;
- }
- watchdog('l10n_update', 'Unable to download translation file @uri.', array('@uri' => $source_file->uri), WATCHDOG_ERROR);
- return FALSE;
- }
|