function tome_static_cron_cron in Tome 8
Implements hook_cron().
File
- modules/
tome_static/ modules/ tome_static_cron/ tome_static_cron.module, line 14 - Contains hook implementations for the tome_static_cron module.
Code
function tome_static_cron_cron() {
$base_url = \Drupal::config('tome_static_cron.settings')
->get('base_url');
if (empty($base_url)) {
return;
}
if (\Drupal::queue('tome_static_cron')
->numberOfItems() > 0) {
return;
}
if ($current_request = \Drupal::requestStack()
->getCurrentRequest()) {
$original_params = TomeStaticHelper::setBaseUrl($current_request, $base_url);
}
\Drupal::state()
->set(TomeStaticQueueWorker::STATE_KEY_INVOKE_PATHS, []);
\Drupal::state()
->set(TomeStaticQueueWorker::STATE_KEY_OLD_PATHS, []);
/** @var \Drupal\tome_static\StaticGeneratorInterface $static */
$static = \Drupal::service('tome_static.generator');
$static
->cleanupStaticDirectory();
$static
->prepareStaticDirectory();
_tome_static_cron_queue_paths($static
->exportPaths($static
->getPaths()), $base_url);
if ($current_request) {
TomeStaticHelper::restoreBaseUrl($current_request, $original_params);
}
}