Upgraded drupal core with security updates
[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   /**
41    * Run Cron once.
42    *
43    * @return \Symfony\Component\HttpFoundation\Response
44    *   A Symfony response object.
45    */
46   public function run() {
47     $this->cron->run();
48
49     // HTTP 204 is "No content", meaning "I did what you asked and we're done."
50     return new Response('', 204);
51   }
52
53   /**
54    * Run cron manually.
55    *
56    * @return \Symfony\Component\HttpFoundation\RedirectResponse
57    *   A Symfony direct response object.
58    */
59   public function runManually() {
60     if ($this->cron->run()) {
61       drupal_set_message($this->t('Cron ran successfully.'));
62     }
63     else {
64       drupal_set_message($this->t('Cron run failed.'), 'error');
65     }
66
67     return $this->redirect('system.status');
68   }
69
70 }