class CronController
Same name and namespace in other branches
- 11.x core/modules/system/src/CronController.php \Drupal\system\CronController
Controller for Cron handling.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase extends \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\system\CronController implements \Drupal\Core\Controller\ControllerBase
Expanded class hierarchy of CronController
File
-
core/
modules/ system/ src/ CronController.php, line 13
Namespace
Drupal\systemView source
class CronController extends ControllerBase {
/**
* The cron service.
*
* @var \Drupal\Core\CronInterface
*/
protected $cron;
/**
* Constructs a CronController object.
*
* @param \Drupal\Core\CronInterface $cron
* The cron service.
*/
public function __construct(CronInterface $cron) {
$this->cron = $cron;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('cron'));
}
/**
* Run Cron once.
*
* @return \Symfony\Component\HttpFoundation\Response
* A Symfony response object.
*/
public function run() {
$this->cron
->run();
// HTTP 204 is "No content", meaning "I did what you asked and we're done."
return new Response('', 204);
}
/**
* Run cron manually.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* A Symfony direct response object.
*/
public function runManually() {
if ($this->cron
->run()) {
$this->messenger()
->addStatus($this->t('Cron ran successfully.'));
}
else {
$this->messenger()
->addError($this->t('Cron run failed.'));
}
return $this->redirect('system.status');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.