function LocaleFetch::batchStatusCheck
Same name and namespace in other branches
- 11.x core/modules/locale/src/LocaleFetch.php \Drupal\locale\LocaleFetch::batchStatusCheck()
Implements callback_batch_operation().
Checks the presence and creation time po translation files in located at remote server location and local file system.
Parameters
string $project: Machine name of the project for which to check the translation status.
string $langcode: Language code of the language for which to check the translation.
array $options: An array with options that can have the following elements:
- 'finish_feedback': Whether or not to give feedback to the user when the batch is finished. Optional, defaults to TRUE.
- 'use_remote': Whether or not to check the remote translation file. Optional, defaults to TRUE.
array|\ArrayAccess $context: The batch context.
File
-
core/
modules/ locale/ src/ LocaleFetch.php, line 324
Class
- LocaleFetch
- Provides the locale fetch services.
Namespace
Drupal\localeCode
public function batchStatusCheck(string $project, string $langcode, array $options, array|\ArrayAccess &$context) : void {
$failure = $checked = FALSE;
$options += [
'finish_feedback' => TRUE,
'use_remote' => TRUE,
];
$source = locale_translation_get_status([
$project,
], [
$langcode,
]);
$source = $source[$project][$langcode];
// Check the status of local translation files.
if (isset($source->files[LOCALE_TRANSLATION_LOCAL])) {
if ($file = $this->localeSource
->sourceCheckFile($source)) {
locale_translation_status_save($source->name, $source->langcode, LOCALE_TRANSLATION_LOCAL, $file);
}
$checked = TRUE;
}
// Check the status of remote translation files.
if ($options['use_remote'] && isset($source->files[LOCALE_TRANSLATION_REMOTE])) {
$remote_file = $source->files[LOCALE_TRANSLATION_REMOTE];
if ($langcode === 'en') {
// drupal.org does not support english as translation.
$uri = $this->localeSource
->buildServerPattern($source, strtr(\Drupal::TRANSLATION_DEFAULT_SERVER_PATTERN, [
'%language' => $langcode,
]));
if ($uri === $remote_file->uri) {
$failure = TRUE;
}
}
$remoteFileInfo = $this->localeFileManager
->checkRemoteFileStatus($remote_file->uri);
if (!$failure && $remoteFileInfo->status !== RemoteFileStatus::Error) {
// Update the file object with the result data. In case of a redirect we
// store the resulting uri.
if ($remoteFileInfo->lastModified) {
$remote_file->uri = $remoteFileInfo->location ?? $remote_file->uri;
$remote_file->timestamp = $remoteFileInfo->lastModified;
locale_translation_status_save($source->name, $source->langcode, LOCALE_TRANSLATION_REMOTE, $remote_file);
}
// @todo What to do with when the file is not found (404)? To prevent
// re-checking within the TTL (1day, 1week) we can set a last_checked
// timestamp or cache the result.
$checked = TRUE;
}
else {
$failure = TRUE;
}
}
// Provide user feedback and record success or failure for reporting at the
// end of the batch.
if ($options['finish_feedback'] && $checked) {
$context['results']['files'][] = $source->name;
}
if ($failure && !$checked) {
$context['results']['failed_files'][] = $source->name;
}
$context['message'] = $this->t('Checked %langcode translation for %project.', [
'%langcode' => $langcode,
'%project' => $source->project,
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.