function locale_cron_fill_queue in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/locale/locale.translation.inc \locale_cron_fill_queue()
Populate a queue with project to check for translation updates.
1 call to locale_cron_fill_queue()
- locale_cron in core/
modules/ locale/ locale.module - Implements hook_cron().
File
- core/
modules/ locale/ locale.translation.inc, line 325 - Common API for interface translation.
Code
function locale_cron_fill_queue() {
$updates = array();
$config = \Drupal::config('locale.settings');
// Determine which project+language should be updated.
$last = REQUEST_TIME - $config
->get('translation.update_interval_days') * 3600 * 24;
$projects = \Drupal::service('locale.project')
->getAll();
$projects = array_filter($projects, function ($project) {
return $project['status'] == 1;
});
$files = db_select('locale_file', 'f')
->condition('f.project', array_keys($projects), 'IN')
->condition('f.last_checked', $last, '<')
->fields('f', array(
'project',
'langcode',
))
->execute()
->fetchAll();
foreach ($files as $file) {
$updates[$file->project][] = $file->langcode;
// Update the last_checked timestamp of the project+language that will
// be checked for updates.
db_update('locale_file')
->fields(array(
'last_checked' => REQUEST_TIME,
))
->condition('project', $file->project)
->condition('langcode', $file->langcode)
->execute();
}
// For each project+language combination a number of tasks are added to
// the queue.
if ($updates) {
module_load_include('fetch.inc', 'locale');
$options = _locale_translation_default_update_options();
$queue = \Drupal::queue('locale_translation', TRUE);
foreach ($updates as $project => $languages) {
$batch = locale_translation_batch_update_build(array(
$project,
), $languages, $options);
foreach ($batch['operations'] as $item) {
$queue
->createItem($item);
}
}
}
}