Mercurial > hg > isophonics-drupal-site
annotate core/modules/system/src/CronController.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 129ea1e6d783 |
children |
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 * Run Cron once. |
Chris@0 | 41 * |
Chris@0 | 42 * @return \Symfony\Component\HttpFoundation\Response |
Chris@0 | 43 * A Symfony response object. |
Chris@0 | 44 */ |
Chris@0 | 45 public function run() { |
Chris@0 | 46 $this->cron->run(); |
Chris@0 | 47 |
Chris@0 | 48 // HTTP 204 is "No content", meaning "I did what you asked and we're done." |
Chris@0 | 49 return new Response('', 204); |
Chris@0 | 50 } |
Chris@0 | 51 |
Chris@0 | 52 /** |
Chris@0 | 53 * Run cron manually. |
Chris@0 | 54 * |
Chris@0 | 55 * @return \Symfony\Component\HttpFoundation\RedirectResponse |
Chris@0 | 56 * A Symfony direct response object. |
Chris@0 | 57 */ |
Chris@0 | 58 public function runManually() { |
Chris@0 | 59 if ($this->cron->run()) { |
Chris@17 | 60 $this->messenger()->addStatus($this->t('Cron ran successfully.')); |
Chris@0 | 61 } |
Chris@0 | 62 else { |
Chris@17 | 63 $this->messenger()->addError($this->t('Cron run failed.')); |
Chris@0 | 64 } |
Chris@0 | 65 |
Chris@0 | 66 return $this->redirect('system.status'); |
Chris@0 | 67 } |
Chris@0 | 68 |
Chris@0 | 69 } |