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

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. private ContaoFramework $framework;
  17. public function __construct(ContaoFramework $framework)
  18. {
  19. $this->framework = $framework;
  20. }
  21. /**
  22. * @CronJob("minutely")
  23. */
  24. public function onMinutely(): void
  25. {
  26. $this->runLegacyCrons('minutely');
  27. }
  28. /**
  29. * @CronJob("hourly")
  30. */
  31. public function onHourly(): void
  32. {
  33. $this->runLegacyCrons('hourly');
  34. }
  35. /**
  36. * @CronJob("daily")
  37. */
  38. public function onDaily(): void
  39. {
  40. $this->runLegacyCrons('daily');
  41. }
  42. /**
  43. * @CronJob("weekly")
  44. */
  45. public function onWeekly(): void
  46. {
  47. $this->runLegacyCrons('weekly');
  48. }
  49. /**
  50. * @CronJob("monthly")
  51. */
  52. public function onMonthly(): void
  53. {
  54. $this->runLegacyCrons('monthly');
  55. }
  56. /**
  57. * @todo Migrate our own cron jobs to the new framework
  58. */
  59. private function runLegacyCrons(string $interval): void
  60. {
  61. $this->framework->initialize();
  62. if (!isset($GLOBALS['TL_CRON'][$interval])) {
  63. return;
  64. }
  65. $system = $this->framework->getAdapter(System::class);
  66. // Load the default language file (see #8719)
  67. $system->loadLanguageFile('default');
  68. foreach ($GLOBALS['TL_CRON'][$interval] as $cron) {
  69. 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.');
  70. $system->importStatic($cron[0])->{$cron[1]}();
  71. }
  72. }
  73. }