function UpdateCronHooks::cron
Same name and namespace in other branches
- main core/modules/update/src/Hook/UpdateCronHooks.php \Drupal\update\Hook\UpdateCronHooks::cron()
Implements hook_cron().
Attributes
File
-
core/
modules/ update/ src/ Hook/ UpdateCronHooks.php, line 49
Class
- UpdateCronHooks
- Hook implementations for update.
Namespace
Drupal\update\HookCode
public function cron() : void {
$update_config = $this->configFactory
->get('update.settings');
$frequency = $update_config->get('check.interval_days');
$interval = 60 * 60 * 24 * $frequency;
$last_check = $this->state
->get('update.last_check', 0);
$request_time = $this->time
->getRequestTime();
if ($request_time - $last_check > $interval) {
// If the configured update interval has elapsed, we want to invalidate
// the data for all projects, attempt to re-fetch, and trigger any
// configured notifications about the new status.
($this->updateManager)()
->refreshUpdateData();
($this->updateProcessor)()
->fetchData();
}
else {
// Otherwise, see if any individual projects are now stale or still
// missing data, and if so, try to fetch the data.
update_get_available(TRUE);
}
$last_email_notice = $this->state
->get('update.last_email_notification', 0);
if ($request_time - $last_email_notice > $interval) {
// If configured time between notifications elapsed, send email about
// updates possibly available.
if ($this->notify()) {
// Track when the last mail was successfully sent to avoid sending
// too many emails.
$this->state
->set('update.last_email_notification', $request_time);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.