You are here

function scheduler_cron in Scheduler 2.x

Same name and namespace in other branches
  1. 8 scheduler.module \scheduler_cron()
  2. 5 scheduler.module \scheduler_cron()
  3. 6 scheduler.module \scheduler_cron()
  4. 7 scheduler.module \scheduler_cron()

Implements hook_cron().

15 calls to scheduler_cron()
SchedulerEventsTest::testNodeEvents in tests/src/Functional/SchedulerEventsTest.php
Covers six events for nodes.
SchedulerEventsTest::testSchedulerEvents in tests/src/Functional/SchedulerEventsTest.php
Tests six scheduler events for entity types other than node.
SchedulerHooksLegacyTest::testAllowedPublishing in tests/src/Functional/SchedulerHooksLegacyTest.php
Covers hook_scheduler_allow_publishing()
SchedulerHooksLegacyTest::testAllowedUnpublishing in tests/src/Functional/SchedulerHooksLegacyTest.php
Covers hook_scheduler_allow_unpublishing()
SchedulerHooksLegacyTest::testNidList in tests/src/Functional/SchedulerHooksLegacyTest.php
Covers hook_scheduler_nid_list($action)

... See full list

1 string reference to 'scheduler_cron'
scheduler_cron_is_running in ./scheduler.module
Return whether Scheduler cron is running.

File

./scheduler.module, line 839
Scheduler publishes and unpublishes entities on dates specified by the user.

Code

function scheduler_cron() {

  // Use drupal_static so that any function can find out if we are running
  // Scheduler cron. Set the default value to FALSE, then turn on the flag.
  // @see scheduler_cron_is_running()
  $scheduler_cron =& drupal_static(__FUNCTION__, FALSE);
  $scheduler_cron = TRUE;

  /** @var \Drupal\scheduler\SchedulerManager $scheduler_manager */
  $scheduler_manager = \Drupal::service('scheduler.manager');
  $scheduler_manager
    ->publish();
  $scheduler_manager
    ->unpublish();

  // Scheduler 7.x provided hook_scheduler_api() which has been replaced by
  // event dispatching in 8.x. Display a warning in the log if any of these
  // hooks still exist, so that admins and developers are informed.
  foreach (Drupal::moduleHandler()
    ->getImplementations('scheduler_api') as $module) {
    \Drupal::logger('scheduler')
      ->warning('Function %function has not been executed. In Drupal 8, implementations of hook_scheduler_api() should be replaced by Scheduler event listeners.', [
      '%function' => $module . '_scheduler_api',
    ]);
  }

  // Reset the static scheduler_cron flag.
  drupal_static_reset(__FUNCTION__);
}