3 namespace Drupal\system;
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\Core\CronInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8 use Symfony\Component\HttpFoundation\Response;
11 * Controller for Cron handling.
13 class CronController extends ControllerBase {
18 * @var \Drupal\Core\CronInterface
23 * Constructs a CronController object.
25 * @param \Drupal\Core\CronInterface $cron
28 public function __construct(CronInterface $cron) {
35 public static function create(ContainerInterface $container) {
36 return new static($container->get('cron'));
42 * @return \Symfony\Component\HttpFoundation\Response
43 * A Symfony response object.
45 public function run() {
48 // HTTP 204 is "No content", meaning "I did what you asked and we're done."
49 return new Response('', 204);
55 * @return \Symfony\Component\HttpFoundation\RedirectResponse
56 * A Symfony direct response object.
58 public function runManually() {
59 if ($this->cron->run()) {
60 $this->messenger()->addStatus($this->t('Cron ran successfully.'));
63 $this->messenger()->addError($this->t('Cron run failed.'));
66 return $this->redirect('system.status');