CronController.php in CiviCRM Cron 8
File
src/Controller/CronController.php
View source
<?php
namespace Drupal\civicrm_cron\Controller;
use CRM_Core_JobManager;
use CRM_Utils_System;
use Drupal\civicrm\Civicrm;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
class CronController extends ControllerBase {
protected $civicrm;
public function __construct(Civicrm $civicrm) {
$this->civicrm = $civicrm;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('civicrm'));
}
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();
$response = new Response();
$response
->setContent('CiviCRM cron run successful.');
$response->headers
->set('X-CiviCRM-Cron', TRUE);
return $response;
}
}