entity_share_cron.module in Entity Share Cron 8.2
File
entity_share_cron.module
View source
<?php
declare (strict_types=1);
function entity_share_cron_cron() {
$config = \Drupal::config('entity_share_cron.settings');
$state = \Drupal::state();
$now = time();
$interval = $config
->get('cron_interval');
$last_run = $state
->get('entity_share_cron.cron_last_run') ? $state
->get('entity_share_cron.cron_last_run') : -99999;
if ($last_run + $interval < $now) {
$service = \Drupal::service('entity_share_cron');
$logger = \Drupal::logger('entity_share_cron');
$remotes_config = $config
->get('remotes');
foreach ($remotes_config as $remote_id => $remote_config) {
if (!empty($remote_config['enabled'])) {
$channels_config = isset($remote_config['channels']) ? $remote_config['channels'] : [];
foreach ($channels_config as $channel_id => $channel_config) {
if (!empty($channel_config['enabled']) && !empty($channel_config['url'])) {
$logger
->info('Enqueuing channel %channel_id from remote %remote_id for synchronization.', [
'%channel_id' => $channel_id,
'%remote_id' => $remote_id,
]);
$service
->enqueue($remote_id, $channel_id, $channel_config);
}
}
}
}
$state
->set('entity_share_cron.cron_last_run', $now);
}
}