1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Shopware\Storefront\Theme\Command; |
4
|
|
|
|
5
|
|
|
use Shopware\Core\Framework\Context; |
6
|
|
|
use Shopware\Core\Framework\Log\Package; |
7
|
|
|
use Shopware\Storefront\Theme\ConfigLoader\AbstractAvailableThemeProvider; |
8
|
|
|
use Shopware\Storefront\Theme\ThemeService; |
9
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
10
|
|
|
use Symfony\Component\Console\Command\Command; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Input\InputOption; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
15
|
|
|
|
16
|
|
|
#[AsCommand( |
17
|
|
|
name: 'theme:compile', |
18
|
|
|
description: 'Compile the theme', |
19
|
|
|
)] |
20
|
|
|
#[Package('storefront')] |
21
|
|
|
class ThemeCompileCommand extends Command |
22
|
|
|
{ |
23
|
|
|
private SymfonyStyle $io; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @internal |
27
|
|
|
*/ |
28
|
|
|
public function __construct( |
29
|
|
|
private readonly ThemeService $themeService, |
30
|
|
|
private readonly AbstractAvailableThemeProvider $themeProvider |
31
|
|
|
) { |
32
|
|
|
parent::__construct(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function configure(): void |
36
|
|
|
{ |
37
|
|
|
$this |
38
|
|
|
->addOption('keep-assets', 'k', InputOption::VALUE_NONE, 'Keep current assets, do not delete them') |
39
|
|
|
->addOption('active-only', 'a', InputOption::VALUE_NONE, 'Compile themes only for active sales channels') |
40
|
|
|
->addOption('only', 'o', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Compile themes only for given sales channels ids') |
41
|
|
|
->addOption('skip', 's', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Skip compiling themes for given sales channels ids') |
42
|
|
|
->addOption('only-themes', 'O', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Compile only themes for given theme ids') |
43
|
|
|
->addOption('skip-themes', 'S', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Skip compiling themes for given theme ids') |
44
|
|
|
; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
48
|
|
|
{ |
49
|
|
|
$this->io = new SymfonyStyle($input, $output); |
50
|
|
|
$context = Context::createDefaultContext(); |
51
|
|
|
$this->io->writeln('Start theme compilation'); |
52
|
|
|
|
53
|
|
|
$onlySalesChannel = ((array) $input->getOption('only')) ?: null; |
54
|
|
|
$skipSalesChannel = ((array) $input->getOption('skip')) ?: null; |
55
|
|
|
if ($onlySalesChannel !== null && $skipSalesChannel !== null |
56
|
|
|
&& \count(array_intersect($onlySalesChannel, $skipSalesChannel)) > 0) { |
57
|
|
|
$this->io->error('The sales channel includes and skips contain contradicting entries:' . implode( |
58
|
|
|
', ', |
59
|
|
|
array_intersect($onlySalesChannel, $skipSalesChannel) |
60
|
|
|
)); |
61
|
|
|
|
62
|
|
|
return self::FAILURE; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$onlyThemes = ((array) $input->getOption('only-themes')) ?: null; |
66
|
|
|
$skipThemes = ((array) $input->getOption('skip-themes')) ?: null; |
67
|
|
|
if ($onlyThemes !== null && $skipThemes !== null |
68
|
|
|
&& \count(array_intersect($onlyThemes, $skipThemes)) > 0) { |
69
|
|
|
$this->io->error('The theme includes and skips contain contradicting entries:' . implode( |
70
|
|
|
', ', |
71
|
|
|
array_intersect($onlyThemes, $skipThemes) |
72
|
|
|
)); |
73
|
|
|
|
74
|
|
|
return self::FAILURE; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
foreach ($this->themeProvider->load($context, $input->getOption('active-only')) as $salesChannelId => $themeId) { |
|
|
|
|
78
|
|
|
if ($onlySalesChannel !== null && !\in_array($salesChannelId, $onlySalesChannel, true) |
79
|
|
|
|| $skipSalesChannel !== null && \in_array($salesChannelId, $skipSalesChannel, true) |
80
|
|
|
|| $onlyThemes !== null && !\in_array($themeId, $onlyThemes, true) |
81
|
|
|
|| $skipThemes !== null && \in_array($themeId, $skipThemes, true)) { |
82
|
|
|
continue; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$this->io->block(\sprintf('Compiling theme for sales channel for : %s', $salesChannelId)); |
86
|
|
|
|
87
|
|
|
$start = microtime(true); |
88
|
|
|
$this->themeService->compileTheme($salesChannelId, $themeId, $context, null, !$input->getOption('keep-assets')); |
89
|
|
|
$this->io->note(sprintf('Took %f seconds', microtime(true) - $start)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return self::SUCCESS; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.