Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / src / CronController.php
1 <?php
2
3 namespace Drupal\system;
4
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\Core\CronInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8 use Symfony\Component\HttpFoundation\Response;
9
10 /**
11  * Controller for Cron handling.
12  */
13 class CronController extends ControllerBase {
14
15   /**
16    * The cron service.
17    *
18    * @var \Drupal\Core\CronInterface
19    */
20   protected $cron;
21
22   /**
23    * Constructs a CronController object.
24    *
25    * @param \Drupal\Core\CronInterface $cron
26    *   The cron service.
27    */
28   public function __construct(CronInterface $cron) {
29     $this->cron = $cron;
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public static function create(ContainerInterface $container) {
36     return new static($container->get('cron'));
37   }
38
39   /**
40    * Run Cron once.
41    *
42    * @return \Symfony\Component\HttpFoundation\Response
43    *   A Symfony response object.
44    */
45   public function run() {
46     $this->cron->run();
47
48     // HTTP 204 is "No content", meaning "I did what you asked and we're done."
49     return new Response('', 204);
50   }
51
52   /**
53    * Run cron manually.
54    *
55    * @return \Symfony\Component\HttpFoundation\RedirectResponse
56    *   A Symfony direct response object.
57    */
58   public function runManually() {
59     if ($this->cron->run()) {
60       $this->messenger()->addStatus($this->t('Cron ran successfully.'));
61     }
62     else {
63       $this->messenger()->addError($this->t('Cron run failed.'));
64     }
65
66     return $this->redirect('system.status');
67   }
68
69 }