function globallink_cron in GlobalLink Connect for Drupal 8.2
Same name and namespace in other branches
- 8 globallink.module \globallink_cron()
- 7.7 globallink.module \globallink_cron()
- 7.5 globallink.module \globallink_cron()
- 7.6 globallink.module \globallink_cron()
Implements hook_cron().
File
- ./
globallink.module, line 21
Code
function globallink_cron() {
$globallink_translators = \Drupal::entityTypeManager()
->getStorage('tmgmt_translator')
->loadByProperties([
'plugin' => 'globallink',
]);
/** @var \Drupal\tmgmt\TranslatorInterface $translator */
try {
foreach ($globallink_translators as $translator) {
if (empty($translator
->getSettings()['pd_projectid'])) {
$message = t('GlobalLink is missing connection credentials. Please fix it on TMGMT GlobalLink plugin page.');
\Drupal::logger('globallink')
->warning($message);
\Drupal::messenger()
->addWarning($message);
return;
}
/** @var \Drupal\globallink\Plugin\tmgmt\Translator\GlobalLinkTranslator $translator_plugin */
$translator_plugin = $translator
->getPlugin();
$completed_translations = $translator_plugin
->getCompletedTranslations($translator);
if (!empty($completed_translations)) {
foreach ($completed_translations as $completed_translation) {
$query = \Drupal::entityQuery('tmgmt_job')
->condition('uuid', $completed_translation->clientIdentifier);
$job_ids = $query
->execute();
if (!empty($job_ids)) {
/** @var \Drupal\tmgmt\JobInterface $job */
$job = Job::load(array_shift($job_ids));
$translator_plugin
->retrieveTranslation($completed_translation->ticket, $job);
}
}
}
}
} catch (Exception $ex) {
$message = t('GlobalLink: Unexpected error, ' . $ex
->getMessage());
\Drupal::logger('globallink')
->warning($message);
}
}