‪TYPO3CMS  ‪main
CacheWarmupCommand.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\EventDispatcher\EventDispatcherInterface;
21 use Symfony\Component\Console\Command\Command;
22 use Symfony\Component\Console\Input\InputInterface;
23 use Symfony\Component\Console\Input\InputOption;
24 use Symfony\Component\Console\Output\OutputInterface;
32 use TYPO3\CMS\Core\DependencyInjection\ContainerBuilder;
33 use TYPO3\CMS\Core\Package\PackageManager;
34 
35 class ‪CacheWarmupCommand extends Command
36 {
37  public function ‪__construct(
38  protected readonly ContainerBuilder $containerBuilder,
39  protected readonly PackageManager $packageManager,
40  protected readonly ‪BootService $bootService,
41  protected readonly ‪FrontendInterface $dependencyInjectionCache
42  ) {
43  parent::__construct('cache:warmup');
44  }
45 
49  protected function ‪configure(): void
50  {
51  $this->setDescription('Warmup TYPO3 caches.');
52  $this->setHelp('This command is useful for deployments to warmup caches during release preparation.');
53  $this->setDefinition([
54  new InputOption('group', 'g', InputOption::VALUE_OPTIONAL, 'The cache group to warmup (system, pages, di or all)', 'all'),
55  ]);
56  }
57 
61  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
62  {
63  $group = $input->getOption('group') ?? 'all';
64 
65  if ($group === 'di' || $group === 'system' || $group === 'all') {
66  $this->containerBuilder->warmupCache($this->packageManager, $this->dependencyInjectionCache);
67  if ($group === 'di') {
68  return Command::SUCCESS;
69  }
70  }
71 
72  $container = $this->bootService->getContainer();
73 
74  $allowExtFileCaches = true;
75  if ($group === 'system' || $group === 'all') {
76  $allowExtFileCaches = false;
77  $container->get(ExtLocalconfFactory::class)->createCacheEntry();
78  $container->get(ExtTablesFactory::class)->createCacheEntry();
79  }
80  // Perform a full boot to load localconf (requirement for extensions and for TCA loading).
81  $this->bootService->loadExtLocalconfDatabaseAndExtTables(false, $allowExtFileCaches, false);
82  if ($group === 'system' || $group === 'all') {
83  $tcaFactory = $container->get(TcaFactory::class);
84  $tcaFactory->createBaseTcaCacheFile(‪$GLOBALS['TCA']);
85  }
86  if ($allowExtFileCaches) {
87  $container->get(ExtTablesFactory::class)->load();
88  } else {
89  $container->get(ExtTablesFactory::class)->loadUncached();
90  }
91 
92  $eventDispatcher = $container->get(EventDispatcherInterface::class);
93 
94  $groups = $group === 'all' ? $container->get(CacheManager::class)->getCacheGroups() : [$group];
95  $event = new ‪CacheWarmupEvent($groups);
96  $eventDispatcher->dispatch($event);
97 
98  if (count($event->getErrors()) > 0) {
99  return Command::FAILURE;
100  }
101 
102  return Command::SUCCESS;
103  }
104 }
‪TYPO3\CMS\Core\Configuration\Tca\TcaFactory
Definition: TcaFactory.php:34
‪TYPO3\CMS\Core\Command\CacheWarmupCommand
Definition: CacheWarmupCommand.php:36
‪TYPO3\CMS\Core\Command\CacheWarmupCommand\configure
‪configure()
Definition: CacheWarmupCommand.php:49
‪TYPO3\CMS\Core\Cache\Event\CacheWarmupEvent
Definition: CacheWarmupEvent.php:24
‪TYPO3\CMS\Core\Core\BootService
Definition: BootService.php:35
‪TYPO3\CMS\Core\Command\CacheWarmupCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: CacheWarmupCommand.php:61
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Core\Configuration\Extension\ExtLocalconfFactory
Definition: ExtLocalconfFactory.php:28
‪TYPO3\CMS\Core\Configuration\Extension\ExtTablesFactory
Definition: ExtTablesFactory.php:28
‪$output
‪$output
Definition: annotationChecker.php:114
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Command
Definition: CacheFlushCommand.php:18
‪TYPO3\CMS\Core\Command\CacheWarmupCommand\__construct
‪__construct(protected readonly ContainerBuilder $containerBuilder, protected readonly PackageManager $packageManager, protected readonly BootService $bootService, protected readonly FrontendInterface $dependencyInjectionCache)
Definition: CacheWarmupCommand.php:37