entity_share_cron.module in Entity Share Cron 8
Same filename and directory in other branches
Hook implementations for the Entity share cron module.
File
entity_share_cron.moduleView source
<?php
/**
* @file
* Hook implementations for the Entity share cron module.
*/
/**
* Implements hook_cron().
*/
function entity_share_cron_cron() {
$config = \Drupal::configFactory()
->getEditable('entity_share_cron.settings');
// Checks the interval since the last synchronization.
$now = time();
$interval = $config
->get('cron_interval');
$last_run = $config
->get('cron_last_run');
if ($last_run + $interval < $now) {
$service = \Drupal::service('entity_share_cron');
$logger = \Drupal::logger('entity_share_cron');
// Enqueues enabled remotes and channels for synchronization.
$remotes_config = $config
->get('remotes');
foreach ($remotes_config as $remote_id => $remote_config) {
// Checks if synchronization of this remote is enabled.
if (!empty($remote_config['enabled'])) {
$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 (!empty($channel_config['enabled']) && !empty($channel_config['url'])) {
// Enqueues the channel for synchronization.
$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);
}
}
}
}
// Updates last run timestamp.
$config
->set('cron_last_run', $now)
->save();
}
}
Functions
Name | Description |
---|---|
entity_share_cron_cron | Implements hook_cron(). |