public function CronHookHandler::process in Entity Share Cron 3.0.x
Enqueue channels for import if the new execution interval is reached.
File
- src/
HookHandler/ CronHookHandler.php, line 93
Class
- CronHookHandler
- Hook handler for the cron() hook.
Namespace
Drupal\entity_share_cron\HookHandlerCode
public function process() {
$config = $this->configFactory
->get('entity_share_cron.settings');
$now = time();
$interval = $config
->get('cron_interval');
$last_run = $this->state
->get(self::STATE_ID) ? $this->state
->get(self::STATE_ID) : -99999;
// Checks the interval since the last synchronization.
if ($now < $last_run + $interval) {
return;
}
// Enqueues enabled remotes and channels for synchronization.
$remotes_config = $config
->get('remotes');
if (is_array($remotes_config)) {
foreach ($remotes_config as $remote_id => $remote_config) {
// Checks if synchronization of this remote is enabled.
if (empty($remote_config['enabled'])) {
continue;
}
$channels_config = isset($remote_config['channels']) ? $remote_config['channels'] : [];
foreach ($channels_config as $channel_id => $channel_config) {
// Checks if synchronization of this channel is enabled.
if ($channel_config['enabled']) {
// Enqueues the channel for synchronization.
$this->logger
->info('Enqueuing channel %channel_id from remote %remote_id for synchronization.', [
'%channel_id' => $channel_id,
'%remote_id' => $remote_id,
]);
$this->entityShareCron
->enqueue($remote_id, $channel_id, NULL);
}
}
}
}
// Updates last run timestamp.
$this->state
->set(self::STATE_ID, $now);
}