You are here

public function CronController::runCron in CiviCRM Cron 8

Runs CiviCRM cron.

Consumers of this endpoint should expect an HTTP response with a non-empty value for the "X-CiviCRM-Cron" header.

1 string reference to 'CronController::runCron'
civicrm_cron.routing.yml in ./civicrm_cron.routing.yml
civicrm_cron.routing.yml

File

src/Controller/CronController.php, line 47

Class

CronController
Class CronController.

Namespace

Drupal\civicrm_cron\Controller

Code

public function runCron() {
  $this->civicrm
    ->initialize();
  $config = $this
    ->config('civicrm_cron.settings');
  if ($username = $config
    ->get('username')) {
    CRM_Utils_System::authenticateScript(TRUE, $username, $config
      ->get('password'));
  }
  else {
    CRM_Utils_System::authenticateScript(FALSE);
  }
  $facility = new CRM_Core_JobManager();
  $facility
    ->execute();

  // Prevents caching of the entire page/request and allows us to add a header
  // indicating that the cron run was successful.
  $response = new Response();
  $response
    ->setContent('CiviCRM cron run successful.');
  $response->headers
    ->set('X-CiviCRM-Cron', TRUE);
  return $response;
}