Mercurial > hg > isophonics-drupal-site
annotate core/modules/system/src/CronController.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\system; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\Core\Controller\ControllerBase; |
Chris@0 | 6 use Drupal\Core\CronInterface; |
Chris@0 | 7 use Symfony\Component\DependencyInjection\ContainerInterface; |
Chris@0 | 8 use Symfony\Component\HttpFoundation\Response; |
Chris@0 | 9 |
Chris@0 | 10 /** |
Chris@0 | 11 * Controller for Cron handling. |
Chris@0 | 12 */ |
Chris@0 | 13 class CronController extends ControllerBase { |
Chris@0 | 14 |
Chris@0 | 15 /** |
Chris@0 | 16 * The cron service. |
Chris@0 | 17 * |
Chris@0 | 18 * @var \Drupal\Core\CronInterface |
Chris@0 | 19 */ |
Chris@0 | 20 protected $cron; |
Chris@0 | 21 |
Chris@0 | 22 /** |
Chris@0 | 23 * Constructs a CronController object. |
Chris@0 | 24 * |
Chris@0 | 25 * @param \Drupal\Core\CronInterface $cron |
Chris@0 | 26 * The cron service. |
Chris@0 | 27 */ |
Chris@0 | 28 public function __construct(CronInterface $cron) { |
Chris@0 | 29 $this->cron = $cron; |
Chris@0 | 30 } |
Chris@0 | 31 |
Chris@0 | 32 /** |
Chris@0 | 33 * {@inheritdoc} |
Chris@0 | 34 */ |
Chris@0 | 35 public static function create(ContainerInterface $container) { |
Chris@0 | 36 return new static($container->get('cron')); |
Chris@0 | 37 } |
Chris@0 | 38 |
Chris@0 | 39 |
Chris@0 | 40 /** |
Chris@0 | 41 * Run Cron once. |
Chris@0 | 42 * |
Chris@0 | 43 * @return \Symfony\Component\HttpFoundation\Response |
Chris@0 | 44 * A Symfony response object. |
Chris@0 | 45 */ |
Chris@0 | 46 public function run() { |
Chris@0 | 47 $this->cron->run(); |
Chris@0 | 48 |
Chris@0 | 49 // HTTP 204 is "No content", meaning "I did what you asked and we're done." |
Chris@0 | 50 return new Response('', 204); |
Chris@0 | 51 } |
Chris@0 | 52 |
Chris@0 | 53 /** |
Chris@0 | 54 * Run cron manually. |
Chris@0 | 55 * |
Chris@0 | 56 * @return \Symfony\Component\HttpFoundation\RedirectResponse |
Chris@0 | 57 * A Symfony direct response object. |
Chris@0 | 58 */ |
Chris@0 | 59 public function runManually() { |
Chris@0 | 60 if ($this->cron->run()) { |
Chris@0 | 61 drupal_set_message($this->t('Cron ran successfully.')); |
Chris@0 | 62 } |
Chris@0 | 63 else { |
Chris@0 | 64 drupal_set_message($this->t('Cron run failed.'), 'error'); |
Chris@0 | 65 } |
Chris@0 | 66 |
Chris@0 | 67 return $this->redirect('system.status'); |
Chris@0 | 68 } |
Chris@0 | 69 |
Chris@0 | 70 } |