diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index aba3fd0..6c15dac 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -502,15 +502,77 @@ function locale_themes_disabled($themes) { * Implements hook_cron(). */ function locale_cron() { - if ($frequency = config('locale.settings')->get('translation.update_interval_days')) { - module_load_include('compare.inc', 'locale'); - $result = locale_translation_update_cron(1, REQUEST_TIME - $frequency * 24 * 3600); - // @todo Use the code below for development. It reduces the cron threshold from days to minutes. - //$result = locale_translation_update_cron(1, REQUEST_TIME - $frequency * 60); - if ($result) { - watchdog('locale', 'Automatically updated @checked translations.', array('@checked' => $result)); + //if ($frequency = config('locale.settings')->get('translation.update_interval_days')) { + if (TRUE) { + module_load_include('inc', 'locale', 'locale.translation'); + $projects = array_keys(locale_translation_get_projects()); + $langcodes = array_keys(locale_translatable_language_list()); + + module_load_include('inc', 'locale', 'locale.compare'); + $operations = _locale_translation_batch_status_operations($projects, $langcodes); + + $queue = Drupal::queue('locale_translation_update'); + foreach($operations as $operation) { + $callback = $operation[0]; + list($projects, $langcodes) = $operation[1]; + //TODO: why are these arrays for local and not remote $callback? + if (!is_array($projects)) $projects = array($projects); + if (!is_array($langcodes)) $langcodes = array($langcodes); + + foreach($projects as $project) { + foreach($langcodes as $langcode) { + // transform $task into $item if necessary + $item = array( + 'callback' => $callback, + 'project' => $project, + 'langcode' => $langcode, + ); + watchdog('locale', 'Queued for !callback: !project (!langcode)', array('callback'=>$callback,'!project'=>$project, '!langcode'=>$langcode)); + $queue->createItem($item); + } + } + } + } +} + +/** + * Implements hook_queue_info(). + */ +function locale_queue_info() { + $queues['locale_translation_update'] = array( + 'title' => t('Updates the translations'), + 'worker callback' => 'locale_translation_update_worker', + 'cron' => array( + 'time' => 60, + ), + ); + return $queues; +} + +/** + * Process 1 file download + * + * TODO: define type for item: object or custom class or array. + * @param type $item + * + * @see locale_cron(). + */ +function locale_translation_update_worker($item) { + module_load_include('inc', 'locale', 'locale.batch'); + + $callback = $item['callback']; + $project = $item['project']; + $langcode = $item['langcode']; + $context = array(); + if (function_exists($callback)) { + if ($callback == 'locale_translation_batch_status_fetch_local') { + locale_translation_batch_status_fetch_local(array($project), array($langcode), $context); + } + else { + locale_translation_batch_status_fetch_remote($project, $langcode, $context); } } + watchdog('locale', 'Translation downloaded !callback: !project (!langcode)', array('callback'=>$callback,'!project'=>$project, '!langcode'=>$langcode)); } /**