vendor/contao/core-bundle/src/Cron/LegacyCron.php line 89

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Contao.
  5.  *
  6.  * (c) Leo Feyer
  7.  *
  8.  * @license LGPL-3.0-or-later
  9.  */
  10. namespace Contao\CoreBundle\Cron;
  11. use Contao\CoreBundle\Framework\ContaoFramework;
  12. use Contao\CoreBundle\ServiceAnnotation\CronJob;
  13. use Contao\System;
  14. class LegacyCron
  15. {
  16.     /**
  17.      * @var ContaoFramework
  18.      */
  19.     private $framework;
  20.     public function __construct(ContaoFramework $framework)
  21.     {
  22.         $this->framework $framework;
  23.     }
  24.     /**
  25.      * @CronJob("minutely")
  26.      */
  27.     public function onMinutely(): void
  28.     {
  29.         $this->runLegacyCrons('minutely');
  30.     }
  31.     /**
  32.      * @CronJob("hourly")
  33.      */
  34.     public function onHourly(): void
  35.     {
  36.         $this->runLegacyCrons('hourly');
  37.     }
  38.     /**
  39.      * @CronJob("daily")
  40.      */
  41.     public function onDaily(): void
  42.     {
  43.         $this->runLegacyCrons('daily');
  44.     }
  45.     /**
  46.      * @CronJob("weekly")
  47.      */
  48.     public function onWeekly(): void
  49.     {
  50.         $this->runLegacyCrons('weekly');
  51.     }
  52.     /**
  53.      * @CronJob("monthly")
  54.      */
  55.     public function onMonthly(): void
  56.     {
  57.         $this->runLegacyCrons('monthly');
  58.     }
  59.     /**
  60.      * @todo Migrate our own cronjobs to the new framework
  61.      */
  62.     private function runLegacyCrons(string $interval): void
  63.     {
  64.         $this->framework->initialize();
  65.         if (!isset($GLOBALS['TL_CRON'][$interval])) {
  66.             return;
  67.         }
  68.         /** @var System $system */
  69.         $system $this->framework->getAdapter(System::class);
  70.         // Load the default language file (see #8719)
  71.         $system->loadLanguageFile('default');
  72.         foreach ($GLOBALS['TL_CRON'][$interval] as $cron) {
  73.             trigger_deprecation('contao/core-bundle''4.9''Using $GLOBALS[\'TL_CRON\'] has been deprecated and will be removed in Contao 5.0. Use the "contao.cronjob" service tag instead.');
  74.             $system->importStatic($cron[0])->{$cron[1]}();
  75.         }
  76.     }
  77. }