‪TYPO3CMS  11.5
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;
31 use TYPO3\CMS\Core\DependencyInjection\ContainerBuilder;
33 use TYPO3\CMS\Core\Package\PackageManager;
35 
36 class ‪CacheWarmupCommand extends Command
37 {
38  protected ContainerBuilder ‪$containerBuilder;
39  protected PackageManager ‪$packageManager;
42 
43  public function ‪__construct(
44  ContainerBuilder ‪$containerBuilder,
45  PackageManager ‪$packageManager,
48  ) {
49  $this->containerBuilder = ‪$containerBuilder;
50  $this->packageManager = ‪$packageManager;
51  $this->bootService = ‪$bootService;
52  $this->dependencyInjectionCache = ‪$dependencyInjectionCache;
53  parent::__construct('cache:warmup');
54  }
55 
59  protected function ‪configure(): void
60  {
61  $this->setDescription('Warmup TYPO3 caches.');
62  $this->setHelp('This command is useful for deployments to warmup caches during release preparation.');
63  $this->setDefinition([
64  new InputOption('group', 'g', InputOption::VALUE_OPTIONAL, 'The cache group to warmup (system, pages, di or all)', 'all'),
65  ]);
66  }
67 
71  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
72  {
73  $group = $input->getOption('group') ?? 'all';
74 
75  if ($group === 'di' || $group === 'system' || $group === 'all') {
76  $this->containerBuilder->warmupCache($this->packageManager, $this->dependencyInjectionCache);
77  if ($group === 'di') {
78  return 0;
79  }
80  }
81 
82  $container = $this->bootService->getContainer();
83 
84  $allowExtFileCaches = true;
85  if ($group === 'system' || $group === 'all') {
86  $coreCache = $container->get('cache.core');
89 
90  // Load TCA uncached…
91  $allowExtFileCaches = false;
92  // …but store the fresh base TCA to cache
93  $listenerProvider = $container->get(ListenerProvider::class);
94  $listenerProvider->addListener(AfterTcaCompilationEvent::class, WarmupBaseTcaCache::class, 'storeBaseTcaCache');
95  }
96 
97  // Perform a full boot to load localconf as requirement extensions and for TCA loading.
98  // TCA will be cached during dispatch of AfterTcaCompilationEvent.
99  $this->bootService->loadExtLocalconfDatabaseAndExtTables(false, $allowExtFileCaches);
100 
101  $eventDispatcher = $container->get(EventDispatcherInterface::class);
102 
103  $groups = $group === 'all' ? $container->get(CacheManager::class)->getCacheGroups() : [$group];
104  $event = new ‪CacheWarmupEvent($groups);
105  $eventDispatcher->dispatch($event);
106 
107  if (count($event->getErrors()) > 0) {
108  return 1;
109  }
110 
111  return 0;
112  }
113 }
‪TYPO3\CMS\Core\Command\CacheWarmupCommand\$bootService
‪BootService $bootService
Definition: CacheWarmupCommand.php:40
‪TYPO3\CMS\Core\Command\CacheWarmupCommand\$dependencyInjectionCache
‪FrontendInterface $dependencyInjectionCache
Definition: CacheWarmupCommand.php:41
‪TYPO3\CMS\Core\Command\CacheWarmupCommand
Definition: CacheWarmupCommand.php:37
‪TYPO3\CMS\Core\Command\CacheWarmupCommand\$containerBuilder
‪ContainerBuilder $containerBuilder
Definition: CacheWarmupCommand.php:38
‪TYPO3\CMS\Core\Command\CacheWarmupCommand\configure
‪configure()
Definition: CacheWarmupCommand.php:59
‪TYPO3\CMS\Core\Configuration\Event\AfterTcaCompilationEvent
Definition: AfterTcaCompilationEvent.php:27
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\createExtLocalconfCacheEntry
‪static createExtLocalconfCacheEntry(FrontendInterface $codeCache)
Definition: ExtensionManagementUtility.php:1548
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\createExtTablesCacheEntry
‪static createExtTablesCacheEntry(FrontendInterface $codeCache)
Definition: ExtensionManagementUtility.php:1782
‪TYPO3\CMS\Core\Cache\Event\CacheWarmupEvent
Definition: CacheWarmupEvent.php:24
‪TYPO3\CMS\Core\Core\BootService
Definition: BootService.php:33
‪TYPO3\CMS\Core\Command\CacheWarmupCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: CacheWarmupCommand.php:71
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Core\Command\CacheWarmupCommand\__construct
‪__construct(ContainerBuilder $containerBuilder, PackageManager $packageManager, BootService $bootService, FrontendInterface $dependencyInjectionCache)
Definition: CacheWarmupCommand.php:43
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪$output
‪$output
Definition: annotationChecker.php:121
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Core\Event\WarmupBaseTcaCache
Definition: WarmupBaseTcaCache.php:25
‪TYPO3\CMS\Core\Command
Definition: CacheFlushCommand.php:18
‪TYPO3\CMS\Core\EventDispatcher\ListenerProvider
Definition: ListenerProvider.php:30
‪TYPO3\CMS\Core\Command\CacheWarmupCommand\$packageManager
‪PackageManager $packageManager
Definition: CacheWarmupCommand.php:39