|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Storefront\Theme\Subscriber; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; |
|
6
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; |
|
7
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; |
|
8
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
9
|
|
|
use Shopware\Core\Framework\Plugin\PluginLifecycleService; |
|
10
|
|
|
use Shopware\Core\Framework\Update\Event\UpdatePostFinishEvent; |
|
11
|
|
|
use Shopware\Core\System\SalesChannel\SalesChannelEntity; |
|
|
|
|
|
|
12
|
|
|
use Shopware\Storefront\Theme\Exception\ThemeCompileException; |
|
13
|
|
|
use Shopware\Storefront\Theme\ThemeCollection; |
|
14
|
|
|
use Shopware\Storefront\Theme\ThemeEntity; |
|
|
|
|
|
|
15
|
|
|
use Shopware\Storefront\Theme\ThemeLifecycleService; |
|
16
|
|
|
use Shopware\Storefront\Theme\ThemeService; |
|
17
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @internal |
|
21
|
|
|
*/ |
|
22
|
|
|
#[Package('storefront')] |
|
23
|
|
|
class UpdateSubscriber implements EventSubscriberInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @internal |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct( |
|
29
|
|
|
private readonly ThemeService $themeService, |
|
30
|
|
|
private readonly ThemeLifecycleService $themeLifecycleService, |
|
31
|
|
|
private readonly EntityRepository $salesChannelRepository |
|
32
|
|
|
) { |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>> |
|
|
|
|
|
|
37
|
|
|
*/ |
|
38
|
|
|
public static function getSubscribedEvents(): array |
|
39
|
|
|
{ |
|
40
|
|
|
return [ |
|
41
|
|
|
UpdatePostFinishEvent::class => 'updateFinished', |
|
42
|
|
|
]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @internal |
|
47
|
|
|
*/ |
|
48
|
|
|
public function updateFinished(UpdatePostFinishEvent $event): void |
|
49
|
|
|
{ |
|
50
|
|
|
$context = $event->getContext(); |
|
51
|
|
|
$this->themeLifecycleService->refreshThemes($context); |
|
52
|
|
|
|
|
53
|
|
|
if ($context->hasState(PluginLifecycleService::STATE_SKIP_ASSET_BUILDING)) { |
|
54
|
|
|
return; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$criteria = new Criteria(); |
|
58
|
|
|
$criteria->addFilter(new EqualsFilter('active', true)); |
|
59
|
|
|
$criteria->getAssociation('themes') |
|
60
|
|
|
->addFilter(new EqualsFilter('active', true)); |
|
61
|
|
|
|
|
62
|
|
|
$alreadyCompiled = []; |
|
63
|
|
|
/** @var SalesChannelEntity $salesChannel */ |
|
64
|
|
|
foreach ($this->salesChannelRepository->search($criteria, $context) as $salesChannel) { |
|
65
|
|
|
$themes = $salesChannel->getExtension('themes'); |
|
66
|
|
|
if (!$themes instanceof ThemeCollection) { |
|
67
|
|
|
continue; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$failedThemes = []; |
|
71
|
|
|
|
|
72
|
|
|
/** @var ThemeEntity $theme */ |
|
73
|
|
|
foreach ($themes as $theme) { |
|
74
|
|
|
// NEXT-21735 - his is covered randomly |
|
75
|
|
|
// @codeCoverageIgnoreStart |
|
76
|
|
|
if (\in_array($theme->getId(), $alreadyCompiled, true) !== false) { |
|
77
|
|
|
continue; |
|
78
|
|
|
} |
|
79
|
|
|
// @codeCoverageIgnoreEnd |
|
80
|
|
|
|
|
81
|
|
|
try { |
|
82
|
|
|
$alreadyCompiled += $this->themeService->compileThemeById($theme->getId(), $context); |
|
83
|
|
|
} catch (ThemeCompileException $e) { |
|
84
|
|
|
$failedThemes[] = $theme->getName(); |
|
85
|
|
|
$alreadyCompiled[] = $theme->getId(); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
if (!empty($failedThemes)) { |
|
90
|
|
|
$event->appendPostUpdateMessage('Theme(s): ' . implode(', ', $failedThemes) . ' could not be recompiled.'); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths