|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Framework\Adapter\Cache; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\ArrayParameterType; |
|
6
|
|
|
use Doctrine\DBAL\Connection; |
|
7
|
|
|
use Shopware\Core\Checkout\Cart\CachedRuleLoader; |
|
8
|
|
|
use Shopware\Core\Checkout\Customer\Aggregate\CustomerGroup\CustomerGroupDefinition; |
|
9
|
|
|
use Shopware\Core\Checkout\Payment\PaymentMethodDefinition; |
|
10
|
|
|
use Shopware\Core\Checkout\Payment\SalesChannel\CachedPaymentMethodRoute; |
|
11
|
|
|
use Shopware\Core\Checkout\Shipping\SalesChannel\CachedShippingMethodRoute; |
|
12
|
|
|
use Shopware\Core\Checkout\Shipping\ShippingMethodDefinition; |
|
13
|
|
|
use Shopware\Core\Content\Category\CategoryDefinition; |
|
14
|
|
|
use Shopware\Core\Content\Category\Event\CategoryIndexerEvent; |
|
15
|
|
|
use Shopware\Core\Content\Category\SalesChannel\CachedCategoryRoute; |
|
16
|
|
|
use Shopware\Core\Content\Category\SalesChannel\CachedNavigationRoute; |
|
17
|
|
|
use Shopware\Core\Content\Cms\CmsPageDefinition; |
|
18
|
|
|
use Shopware\Core\Content\LandingPage\Event\LandingPageIndexerEvent; |
|
19
|
|
|
use Shopware\Core\Content\LandingPage\SalesChannel\CachedLandingPageRoute; |
|
20
|
|
|
use Shopware\Core\Content\Product\Aggregate\ProductCategory\ProductCategoryDefinition; |
|
21
|
|
|
use Shopware\Core\Content\Product\Aggregate\ProductCrossSelling\ProductCrossSellingDefinition; |
|
22
|
|
|
use Shopware\Core\Content\Product\Aggregate\ProductManufacturer\ProductManufacturerDefinition; |
|
23
|
|
|
use Shopware\Core\Content\Product\Aggregate\ProductProperty\ProductPropertyDefinition; |
|
24
|
|
|
use Shopware\Core\Content\Product\Events\ProductChangedEventInterface; |
|
25
|
|
|
use Shopware\Core\Content\Product\ProductDefinition; |
|
26
|
|
|
use Shopware\Core\Content\Product\SalesChannel\CrossSelling\CachedProductCrossSellingRoute; |
|
27
|
|
|
use Shopware\Core\Content\Product\SalesChannel\Detail\CachedProductDetailRoute; |
|
28
|
|
|
use Shopware\Core\Content\Product\SalesChannel\Listing\CachedProductListingRoute; |
|
29
|
|
|
use Shopware\Core\Content\Product\SalesChannel\Review\CachedProductReviewRoute; |
|
30
|
|
|
use Shopware\Core\Content\ProductStream\ProductStreamDefinition; |
|
31
|
|
|
use Shopware\Core\Content\Property\Aggregate\PropertyGroupOption\PropertyGroupOptionDefinition; |
|
32
|
|
|
use Shopware\Core\Content\Property\Aggregate\PropertyGroupOptionTranslation\PropertyGroupOptionTranslationDefinition; |
|
33
|
|
|
use Shopware\Core\Content\Property\Aggregate\PropertyGroupTranslation\PropertyGroupTranslationDefinition; |
|
34
|
|
|
use Shopware\Core\Content\Property\PropertyGroupDefinition; |
|
35
|
|
|
use Shopware\Core\Content\Seo\Event\SeoUrlUpdateEvent; |
|
36
|
|
|
use Shopware\Core\Content\Sitemap\Event\SitemapGeneratedEvent; |
|
37
|
|
|
use Shopware\Core\Content\Sitemap\SalesChannel\CachedSitemapRoute; |
|
38
|
|
|
use Shopware\Core\Defaults; |
|
39
|
|
|
use Shopware\Core\Framework\Adapter\Translation\Translator; |
|
40
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Cache\EntityCacheKeyGenerator; |
|
41
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenContainerEvent; |
|
42
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
43
|
|
|
use Shopware\Core\Framework\Uuid\Uuid; |
|
44
|
|
|
use Shopware\Core\System\Country\Aggregate\CountryState\CountryStateDefinition; |
|
45
|
|
|
use Shopware\Core\System\Country\CountryDefinition; |
|
46
|
|
|
use Shopware\Core\System\Country\SalesChannel\CachedCountryRoute; |
|
47
|
|
|
use Shopware\Core\System\Country\SalesChannel\CachedCountryStateRoute; |
|
48
|
|
|
use Shopware\Core\System\Currency\CurrencyDefinition; |
|
49
|
|
|
use Shopware\Core\System\Currency\SalesChannel\CachedCurrencyRoute; |
|
50
|
|
|
use Shopware\Core\System\Language\LanguageDefinition; |
|
51
|
|
|
use Shopware\Core\System\Language\SalesChannel\CachedLanguageRoute; |
|
52
|
|
|
use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelCountry\SalesChannelCountryDefinition; |
|
53
|
|
|
use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelCurrency\SalesChannelCurrencyDefinition; |
|
54
|
|
|
use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelLanguage\SalesChannelLanguageDefinition; |
|
55
|
|
|
use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelPaymentMethod\SalesChannelPaymentMethodDefinition; |
|
56
|
|
|
use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelShippingMethod\SalesChannelShippingMethodDefinition; |
|
57
|
|
|
use Shopware\Core\System\SalesChannel\Context\CachedBaseContextFactory; |
|
58
|
|
|
use Shopware\Core\System\SalesChannel\Context\CachedSalesChannelContextFactory; |
|
59
|
|
|
use Shopware\Core\System\SalesChannel\SalesChannelDefinition; |
|
60
|
|
|
use Shopware\Core\System\Salutation\SalesChannel\CachedSalutationRoute; |
|
61
|
|
|
use Shopware\Core\System\Salutation\SalutationDefinition; |
|
62
|
|
|
use Shopware\Core\System\Snippet\SnippetDefinition; |
|
63
|
|
|
use Shopware\Core\System\StateMachine\Loader\InitialStateIdLoader; |
|
64
|
|
|
use Shopware\Core\System\StateMachine\StateMachineDefinition; |
|
65
|
|
|
use Shopware\Core\System\SystemConfig\CachedSystemConfigLoader; |
|
66
|
|
|
use Shopware\Core\System\SystemConfig\Event\SystemConfigChangedHook; |
|
67
|
|
|
use Shopware\Core\System\SystemConfig\SystemConfigService; |
|
68
|
|
|
use Shopware\Core\System\Tax\TaxDefinition; |
|
69
|
|
|
|
|
70
|
|
|
#[Package('core')] |
|
71
|
|
|
class CacheInvalidationSubscriber |
|
72
|
|
|
{ |
|
73
|
|
|
/** |
|
74
|
|
|
* @internal |
|
75
|
|
|
*/ |
|
76
|
|
|
public function __construct( |
|
77
|
|
|
private readonly CacheInvalidator $cacheInvalidator, |
|
78
|
|
|
private readonly Connection $connection, |
|
79
|
|
|
private readonly bool $fineGrainedCacheSnippet, |
|
80
|
|
|
private readonly bool $fineGrainedCacheConfig |
|
81
|
|
|
) { |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function invalidateInitialStateIdLoader(EntityWrittenContainerEvent $event): void |
|
85
|
|
|
{ |
|
86
|
|
|
if (!$event->getPrimaryKeys(StateMachineDefinition::ENTITY_NAME)) { |
|
87
|
|
|
return; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$this->cacheInvalidator->invalidate([InitialStateIdLoader::CACHE_KEY]); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function invalidateSitemap(SitemapGeneratedEvent $event): void |
|
94
|
|
|
{ |
|
95
|
|
|
$this->cacheInvalidator->invalidate([ |
|
96
|
|
|
CachedSitemapRoute::buildName($event->getSalesChannelContext()->getSalesChannelId()), |
|
97
|
|
|
]); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function invalidateConfig(): void |
|
101
|
|
|
{ |
|
102
|
|
|
// invalidates the complete cached config |
|
103
|
|
|
$this->cacheInvalidator->invalidate([ |
|
104
|
|
|
CachedSystemConfigLoader::CACHE_TAG, |
|
105
|
|
|
]); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function invalidateConfigKey(SystemConfigChangedHook $event): void |
|
109
|
|
|
{ |
|
110
|
|
|
$keys = []; |
|
111
|
|
|
|
|
112
|
|
|
if ($this->fineGrainedCacheConfig) { |
|
113
|
|
|
/** @var list<string> $keys */ |
|
114
|
|
|
$keys = array_map( |
|
115
|
|
|
static fn (string $key) => SystemConfigService::buildName($key), |
|
116
|
|
|
$event->getWebhookPayload()['changes'] |
|
117
|
|
|
); |
|
118
|
|
|
} else { |
|
119
|
|
|
$keys[] = 'global.system.config'; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
// invalidates the complete cached config and routes which access a specific key |
|
123
|
|
|
$this->cacheInvalidator->invalidate([ |
|
124
|
|
|
...$keys, |
|
125
|
|
|
CachedSystemConfigLoader::CACHE_TAG, |
|
126
|
|
|
]); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function invalidateSnippets(EntityWrittenContainerEvent $event): void |
|
130
|
|
|
{ |
|
131
|
|
|
if (!$this->fineGrainedCacheSnippet) { |
|
132
|
|
|
$this->cacheInvalidator->invalidate(['shopware.translator']); |
|
133
|
|
|
|
|
134
|
|
|
return; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
// invalidates all http cache items where the snippets used |
|
138
|
|
|
$snippets = $event->getEventByEntityName(SnippetDefinition::ENTITY_NAME); |
|
139
|
|
|
|
|
140
|
|
|
if (!$snippets) { |
|
141
|
|
|
return; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
$tags = []; |
|
145
|
|
|
foreach ($snippets->getPayloads() as $payload) { |
|
146
|
|
|
if (isset($payload['translationKey'])) { |
|
147
|
|
|
$tags[] = Translator::buildName($payload['translationKey']); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
$this->cacheInvalidator->invalidate($tags); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function invalidateShippingMethodRoute(EntityWrittenContainerEvent $event): void |
|
154
|
|
|
{ |
|
155
|
|
|
// checks if a shipping method changed or the assignment between shipping method and sales channel |
|
156
|
|
|
$logs = [...$this->getChangedShippingMethods($event), ...$this->getChangedShippingAssignments($event)]; |
|
157
|
|
|
|
|
158
|
|
|
$this->cacheInvalidator->invalidate($logs); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @deprecated tag:v6.6.0 - Will be removed without a replacement - reason:remove-subscriber |
|
163
|
|
|
*/ |
|
164
|
|
|
public function invalidateSeoUrls(SeoUrlUpdateEvent $event): void |
|
165
|
|
|
{ |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
public function invalidateRules(): void |
|
169
|
|
|
{ |
|
170
|
|
|
// invalidates the rule loader each time a rule changed or a plugin install state changed |
|
171
|
|
|
$this->cacheInvalidator->invalidate([CachedRuleLoader::CACHE_KEY]); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
public function invalidateCmsPageIds(EntityWrittenContainerEvent $event): void |
|
175
|
|
|
{ |
|
176
|
|
|
// invalidates all routes and http cache pages where a cms page was loaded, the id is assigned as tag |
|
177
|
|
|
/** @var list<string> $ids */ |
|
178
|
|
|
$ids = array_map(EntityCacheKeyGenerator::buildCmsTag(...), $event->getPrimaryKeys(CmsPageDefinition::ENTITY_NAME)); |
|
179
|
|
|
$this->cacheInvalidator->invalidate($ids); |
|
|
|
|
|
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
public function invalidateProductIds(ProductChangedEventInterface $event): void |
|
183
|
|
|
{ |
|
184
|
|
|
// invalidates all routes which loads products in nested unknown objects, like cms listing elements or cross selling elements |
|
185
|
|
|
$this->cacheInvalidator->invalidate(array_map(EntityCacheKeyGenerator::buildProductTag(...), $event->getIds())); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public function invalidateStreamIds(EntityWrittenContainerEvent $event): void |
|
189
|
|
|
{ |
|
190
|
|
|
// invalidates all routes which are loaded based on a stream (e.G. category listing and cross selling) |
|
191
|
|
|
/** @var list<string> $ids */ |
|
192
|
|
|
$ids = array_map(EntityCacheKeyGenerator::buildStreamTag(...), $event->getPrimaryKeys(ProductStreamDefinition::ENTITY_NAME)); |
|
193
|
|
|
$this->cacheInvalidator->invalidate($ids); |
|
|
|
|
|
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
public function invalidateCategoryRouteByCategoryIds(CategoryIndexerEvent $event): void |
|
197
|
|
|
{ |
|
198
|
|
|
// invalidates the category route cache when a category changed |
|
199
|
|
|
$this->cacheInvalidator->invalidate(array_map(CachedCategoryRoute::buildName(...), $event->getIds())); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
public function invalidateListingRouteByCategoryIds(CategoryIndexerEvent $event): void |
|
203
|
|
|
{ |
|
204
|
|
|
// invalidates the product listing route each time a category changed |
|
205
|
|
|
$this->cacheInvalidator->invalidate(array_map([CachedProductListingRoute::class, 'buildName'], $event->getIds())); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
public function invalidateIndexedLandingPages(LandingPageIndexerEvent $event): void |
|
209
|
|
|
{ |
|
210
|
|
|
// invalidates the landing page route, if the corresponding landing page changed |
|
211
|
|
|
/** @var list<string> $ids */ |
|
212
|
|
|
$ids = array_map([CachedLandingPageRoute::class, 'buildName'], $event->getIds()); |
|
213
|
|
|
$this->cacheInvalidator->invalidate($ids); |
|
|
|
|
|
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
public function invalidateCurrencyRoute(EntityWrittenContainerEvent $event): void |
|
217
|
|
|
{ |
|
218
|
|
|
// invalidates the currency route when a currency changed or an assignment between the sales channel and currency changed |
|
219
|
|
|
$this->cacheInvalidator->invalidate([...$this->getChangedCurrencyAssignments($event), ...$this->getChangedCurrencies($event)]); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
public function invalidateLanguageRoute(EntityWrittenContainerEvent $event): void |
|
223
|
|
|
{ |
|
224
|
|
|
// invalidates the language route when a language changed or an assignment between the sales channel and language changed |
|
225
|
|
|
$this->cacheInvalidator->invalidate([...$this->getChangedLanguageAssignments($event), ...$this->getChangedLanguages($event)]); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
public function invalidateCountryRoute(EntityWrittenContainerEvent $event): void |
|
229
|
|
|
{ |
|
230
|
|
|
// invalidates the country route when a country changed or an assignment between the sales channel and country changed |
|
231
|
|
|
$this->cacheInvalidator->invalidate([...$this->getChangedCountryAssignments($event), ...$this->getChangedCountries($event)]); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
public function invalidateCountryStateRoute(EntityWrittenContainerEvent $event): void |
|
235
|
|
|
{ |
|
236
|
|
|
$tags = []; |
|
237
|
|
|
if ( |
|
238
|
|
|
$event->getDeletedPrimaryKeys(CountryStateDefinition::ENTITY_NAME) |
|
239
|
|
|
|| $event->getPrimaryKeysWithPropertyChange(CountryStateDefinition::ENTITY_NAME, ['countryId']) |
|
240
|
|
|
) { |
|
241
|
|
|
$tags[] = CachedCountryStateRoute::ALL_TAG; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
if (empty($tags)) { |
|
245
|
|
|
// invalidates the country-state route when a state changed or an assignment between the state and country changed |
|
246
|
|
|
/** @var list<string> $tags */ |
|
247
|
|
|
$tags = array_map( |
|
248
|
|
|
[CachedCountryStateRoute::class, 'buildName'], |
|
249
|
|
|
$event->getPrimaryKeys(CountryDefinition::ENTITY_NAME) |
|
250
|
|
|
); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
$this->cacheInvalidator->invalidate($tags); |
|
|
|
|
|
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
public function invalidateSalutationRoute(EntityWrittenContainerEvent $event): void |
|
257
|
|
|
{ |
|
258
|
|
|
// invalidates the salutation route when a salutation changed |
|
259
|
|
|
$this->cacheInvalidator->invalidate([...$this->getChangedSalutations($event)]); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
public function invalidateNavigationRoute(EntityWrittenContainerEvent $event): void |
|
263
|
|
|
{ |
|
264
|
|
|
// invalidates the navigation route when a category changed or the entry point configuration of an sales channel changed |
|
265
|
|
|
$logs = [...$this->getChangedCategories($event), ...$this->getChangedEntryPoints($event)]; |
|
266
|
|
|
|
|
267
|
|
|
$this->cacheInvalidator->invalidate($logs); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
public function invalidatePaymentMethodRoute(EntityWrittenContainerEvent $event): void |
|
271
|
|
|
{ |
|
272
|
|
|
// invalidates the payment method route when a payment method changed or an assignment between the sales channel and payment method changed |
|
273
|
|
|
$logs = [...$this->getChangedPaymentMethods($event), ...$this->getChangedPaymentAssignments($event)]; |
|
274
|
|
|
|
|
275
|
|
|
$this->cacheInvalidator->invalidate($logs); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
public function invalidateSearch(): void |
|
279
|
|
|
{ |
|
280
|
|
|
// invalidates the search and suggest route each time a product changed |
|
281
|
|
|
$this->cacheInvalidator->invalidate([ |
|
282
|
|
|
'product-suggest-route', |
|
283
|
|
|
'product-search-route', |
|
284
|
|
|
]); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
public function invalidateDetailRoute(ProductChangedEventInterface $event): void |
|
288
|
|
|
{ |
|
289
|
|
|
/** @var list<string> $parentIds */ |
|
290
|
|
|
$parentIds = $this->connection->fetchFirstColumn( |
|
291
|
|
|
'SELECT DISTINCT(LOWER(HEX(parent_id))) FROM product WHERE id IN (:ids) AND parent_id IS NOT NULL AND version_id = :version', |
|
292
|
|
|
['ids' => Uuid::fromHexToBytesList($event->getIds()), 'version' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION)], |
|
293
|
|
|
['ids' => ArrayParameterType::STRING] |
|
294
|
|
|
); |
|
295
|
|
|
|
|
296
|
|
|
// invalidates the product detail route each time a product changed or if the product is no longer available (because out of stock) |
|
297
|
|
|
$this->cacheInvalidator->invalidate( |
|
298
|
|
|
array_map(CachedProductDetailRoute::buildName(...), [...$parentIds, ...$event->getIds()]) |
|
299
|
|
|
); |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
public function invalidateProductAssignment(EntityWrittenContainerEvent $event): void |
|
303
|
|
|
{ |
|
304
|
|
|
// invalidates the product listing route, each time a product - category assignment changed |
|
305
|
|
|
$ids = $event->getPrimaryKeys(ProductCategoryDefinition::ENTITY_NAME); |
|
306
|
|
|
|
|
307
|
|
|
$ids = array_column($ids, 'categoryId'); |
|
308
|
|
|
|
|
309
|
|
|
$this->cacheInvalidator->invalidate(array_map([CachedProductListingRoute::class, 'buildName'], $ids)); |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
public function invalidateContext(EntityWrittenContainerEvent $event): void |
|
313
|
|
|
{ |
|
314
|
|
|
// invalidates the context cache - each time one of the entities which are considered inside the context factory changed |
|
315
|
|
|
$ids = $event->getPrimaryKeys(SalesChannelDefinition::ENTITY_NAME); |
|
316
|
|
|
$keys = array_map([CachedSalesChannelContextFactory::class, 'buildName'], $ids); |
|
317
|
|
|
$keys = array_merge($keys, array_map([CachedBaseContextFactory::class, 'buildName'], $ids)); |
|
318
|
|
|
|
|
319
|
|
|
if ($event->getEventByEntityName(CurrencyDefinition::ENTITY_NAME)) { |
|
320
|
|
|
$keys[] = CachedSalesChannelContextFactory::ALL_TAG; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
if ($event->getEventByEntityName(PaymentMethodDefinition::ENTITY_NAME)) { |
|
324
|
|
|
$keys[] = CachedSalesChannelContextFactory::ALL_TAG; |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
if ($event->getEventByEntityName(ShippingMethodDefinition::ENTITY_NAME)) { |
|
328
|
|
|
$keys[] = CachedSalesChannelContextFactory::ALL_TAG; |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
if ($event->getEventByEntityName(TaxDefinition::ENTITY_NAME)) { |
|
332
|
|
|
$keys[] = CachedSalesChannelContextFactory::ALL_TAG; |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
if ($event->getEventByEntityName(CountryDefinition::ENTITY_NAME)) { |
|
336
|
|
|
$keys[] = CachedSalesChannelContextFactory::ALL_TAG; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
if ($event->getEventByEntityName(CustomerGroupDefinition::ENTITY_NAME)) { |
|
340
|
|
|
$keys[] = CachedSalesChannelContextFactory::ALL_TAG; |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
if ($event->getEventByEntityName(LanguageDefinition::ENTITY_NAME)) { |
|
344
|
|
|
$keys[] = CachedSalesChannelContextFactory::ALL_TAG; |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
/** @var list<string> $keys */ |
|
348
|
|
|
$keys = array_filter(array_unique($keys)); |
|
|
|
|
|
|
349
|
|
|
|
|
350
|
|
|
if (empty($keys)) { |
|
351
|
|
|
return; |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
$this->cacheInvalidator->invalidate($keys); |
|
|
|
|
|
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
public function invalidateManufacturerFilters(EntityWrittenContainerEvent $event): void |
|
358
|
|
|
{ |
|
359
|
|
|
// invalidates the product listing route, each time a manufacturer changed |
|
360
|
|
|
$ids = $event->getPrimaryKeys(ProductManufacturerDefinition::ENTITY_NAME); |
|
361
|
|
|
|
|
362
|
|
|
if (empty($ids)) { |
|
363
|
|
|
return; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
$ids = $this->connection->fetchFirstColumn( |
|
367
|
|
|
'SELECT DISTINCT LOWER(HEX(category_id)) as category_id |
|
368
|
|
|
FROM product_category_tree |
|
369
|
|
|
INNER JOIN product ON product.id = product_category_tree.product_id AND product_category_tree.product_version_id = product.version_id |
|
370
|
|
|
WHERE product.product_manufacturer_id IN (:ids) |
|
371
|
|
|
AND product.version_id = :version', |
|
372
|
|
|
['ids' => Uuid::fromHexToBytesList($ids), 'version' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION)], |
|
373
|
|
|
['ids' => ArrayParameterType::STRING] |
|
374
|
|
|
); |
|
375
|
|
|
|
|
376
|
|
|
$this->cacheInvalidator->invalidate( |
|
377
|
|
|
array_map([CachedProductListingRoute::class, 'buildName'], $ids) |
|
378
|
|
|
); |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
public function invalidatePropertyFilters(EntityWrittenContainerEvent $event): void |
|
382
|
|
|
{ |
|
383
|
|
|
$this->cacheInvalidator->invalidate([...$this->getChangedPropertyFilterTags($event), ...$this->getDeletedPropertyFilterTags($event)]); |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
public function invalidateReviewRoute(ProductChangedEventInterface $event): void |
|
387
|
|
|
{ |
|
388
|
|
|
$this->cacheInvalidator->invalidate( |
|
389
|
|
|
array_map([CachedProductReviewRoute::class, 'buildName'], $event->getIds()) |
|
390
|
|
|
); |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
public function invalidateListings(ProductChangedEventInterface $event): void |
|
394
|
|
|
{ |
|
395
|
|
|
// invalidates product listings which are based on the product category assignment |
|
396
|
|
|
$this->cacheInvalidator->invalidate( |
|
397
|
|
|
array_map([CachedProductListingRoute::class, 'buildName'], $this->getProductCategoryIds($event->getIds())) |
|
398
|
|
|
); |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
public function invalidateStreamsBeforeIndexing(EntityWrittenContainerEvent $event): void |
|
402
|
|
|
{ |
|
403
|
|
|
// invalidates all stream based pages and routes before the product indexer changes product_stream_mapping |
|
404
|
|
|
$ids = $event->getPrimaryKeys(ProductDefinition::ENTITY_NAME); |
|
405
|
|
|
|
|
406
|
|
|
if (empty($ids)) { |
|
407
|
|
|
return; |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
// invalidates product listings which are based on a product stream |
|
411
|
|
|
$ids = $this->connection->fetchFirstColumn( |
|
412
|
|
|
'SELECT DISTINCT LOWER(HEX(product_stream_id)) |
|
413
|
|
|
FROM product_stream_mapping |
|
414
|
|
|
WHERE product_stream_mapping.product_id IN (:ids) |
|
415
|
|
|
AND product_stream_mapping.product_version_id = :version', |
|
416
|
|
|
['ids' => Uuid::fromHexToBytesList($ids), 'version' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION)], |
|
417
|
|
|
['ids' => ArrayParameterType::STRING] |
|
418
|
|
|
); |
|
419
|
|
|
|
|
420
|
|
|
$this->cacheInvalidator->invalidate( |
|
421
|
|
|
array_map(EntityCacheKeyGenerator::buildStreamTag(...), $ids) |
|
422
|
|
|
); |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
public function invalidateStreamsAfterIndexing(ProductChangedEventInterface $event): void |
|
426
|
|
|
{ |
|
427
|
|
|
// invalidates all stream based pages and routes after the product indexer changes product_stream_mapping |
|
428
|
|
|
$ids = $this->connection->fetchFirstColumn( |
|
429
|
|
|
'SELECT DISTINCT LOWER(HEX(product_stream_id)) |
|
430
|
|
|
FROM product_stream_mapping |
|
431
|
|
|
WHERE product_stream_mapping.product_id IN (:ids) |
|
432
|
|
|
AND product_stream_mapping.product_version_id = :version', |
|
433
|
|
|
['ids' => Uuid::fromHexToBytesList($event->getIds()), 'version' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION)], |
|
434
|
|
|
['ids' => ArrayParameterType::STRING] |
|
435
|
|
|
); |
|
436
|
|
|
|
|
437
|
|
|
$this->cacheInvalidator->invalidate( |
|
438
|
|
|
array_map(EntityCacheKeyGenerator::buildStreamTag(...), $ids) |
|
439
|
|
|
); |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
public function invalidateCrossSellingRoute(EntityWrittenContainerEvent $event): void |
|
443
|
|
|
{ |
|
444
|
|
|
// invalidates the product detail route for the changed cross selling definitions |
|
445
|
|
|
$ids = $event->getPrimaryKeys(ProductCrossSellingDefinition::ENTITY_NAME); |
|
446
|
|
|
|
|
447
|
|
|
if (empty($ids)) { |
|
448
|
|
|
return; |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
$ids = $this->connection->fetchFirstColumn( |
|
452
|
|
|
'SELECT DISTINCT LOWER(HEX(product_id)) FROM product_cross_selling WHERE id IN (:ids)', |
|
453
|
|
|
['ids' => Uuid::fromHexToBytesList($ids)], |
|
454
|
|
|
['ids' => ArrayParameterType::STRING] |
|
455
|
|
|
); |
|
456
|
|
|
|
|
457
|
|
|
$this->cacheInvalidator->invalidate( |
|
458
|
|
|
array_map([CachedProductCrossSellingRoute::class, 'buildName'], $ids) |
|
459
|
|
|
); |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
/** |
|
463
|
|
|
* @return list<string> |
|
|
|
|
|
|
464
|
|
|
*/ |
|
465
|
|
|
private function getDeletedPropertyFilterTags(EntityWrittenContainerEvent $event): array |
|
466
|
|
|
{ |
|
467
|
|
|
// invalidates the product listing route, each time a property changed |
|
468
|
|
|
$ids = $event->getDeletedPrimaryKeys(ProductPropertyDefinition::ENTITY_NAME); |
|
469
|
|
|
|
|
470
|
|
|
if (empty($ids)) { |
|
471
|
|
|
return []; |
|
|
|
|
|
|
472
|
|
|
} |
|
473
|
|
|
|
|
474
|
|
|
$productIds = array_column($ids, 'productId'); |
|
475
|
|
|
|
|
476
|
|
|
return array_merge( |
|
|
|
|
|
|
477
|
|
|
array_map([CachedProductDetailRoute::class, 'buildName'], array_unique($productIds)), |
|
478
|
|
|
array_map([CachedProductListingRoute::class, 'buildName'], $this->getProductCategoryIds($productIds)) |
|
479
|
|
|
); |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
/** |
|
483
|
|
|
* @return list<string> |
|
484
|
|
|
*/ |
|
485
|
|
|
private function getChangedPropertyFilterTags(EntityWrittenContainerEvent $event): array |
|
486
|
|
|
{ |
|
487
|
|
|
// invalidates the product listing route and detail rule, each time a property group changed |
|
488
|
|
|
$propertyGroupIds = array_unique(array_merge( |
|
489
|
|
|
$event->getPrimaryKeysWithPayloadIgnoringFields(PropertyGroupDefinition::ENTITY_NAME, ['id', 'updatedAt']), |
|
490
|
|
|
array_column($event->getPrimaryKeysWithPayloadIgnoringFields(PropertyGroupTranslationDefinition::ENTITY_NAME, ['propertyGroupId', 'languageId', 'updatedAt']), 'propertyGroupId') |
|
491
|
|
|
)); |
|
492
|
|
|
|
|
493
|
|
|
// invalidates the product listing route and detail rule, each time a property option changed |
|
494
|
|
|
$propertyOptionIds = array_unique(array_merge( |
|
495
|
|
|
$event->getPrimaryKeysWithPayloadIgnoringFields(PropertyGroupOptionDefinition::ENTITY_NAME, ['id', 'updatedAt']), |
|
496
|
|
|
array_column($event->getPrimaryKeysWithPayloadIgnoringFields(PropertyGroupOptionTranslationDefinition::ENTITY_NAME, ['propertyGroupOptionId', 'languageId', 'updatedAt']), 'propertyGroupOptionId') |
|
497
|
|
|
)); |
|
498
|
|
|
|
|
499
|
|
|
if (empty($propertyGroupIds) && empty($propertyOptionIds)) { |
|
500
|
|
|
return []; |
|
|
|
|
|
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
$productIds = $this->connection->fetchFirstColumn( |
|
504
|
|
|
'SELECT product_property.product_id |
|
505
|
|
|
FROM product_property |
|
506
|
|
|
LEFT JOIN property_group_option productProperties ON productProperties.id = product_property.property_group_option_id |
|
507
|
|
|
WHERE productProperties.property_group_id IN (:ids) OR productProperties.id IN (:optionIds) |
|
508
|
|
|
AND product_property.product_version_id = :version', |
|
509
|
|
|
['ids' => Uuid::fromHexToBytesList($propertyGroupIds), 'optionIds' => Uuid::fromHexToBytesList($propertyOptionIds), 'version' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION)], |
|
510
|
|
|
['ids' => ArrayParameterType::STRING, 'optionIds' => ArrayParameterType::STRING] |
|
511
|
|
|
); |
|
512
|
|
|
$productIds = array_unique([...$productIds, ...$this->connection->fetchFirstColumn( |
|
513
|
|
|
'SELECT product_option.product_id |
|
514
|
|
|
FROM product_option |
|
515
|
|
|
LEFT JOIN property_group_option productOptions ON productOptions.id = product_option.property_group_option_id |
|
516
|
|
|
WHERE productOptions.property_group_id IN (:ids) OR productOptions.id IN (:optionIds) |
|
517
|
|
|
AND product_option.product_version_id = :version', |
|
518
|
|
|
['ids' => Uuid::fromHexToBytesList($propertyGroupIds), 'optionIds' => Uuid::fromHexToBytesList($propertyOptionIds), 'version' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION)], |
|
519
|
|
|
['ids' => ArrayParameterType::STRING, 'optionIds' => ArrayParameterType::STRING] |
|
520
|
|
|
)]); |
|
521
|
|
|
|
|
522
|
|
|
if (empty($productIds)) { |
|
523
|
|
|
return []; |
|
|
|
|
|
|
524
|
|
|
} |
|
525
|
|
|
|
|
526
|
|
|
$parentIds = $this->connection->fetchFirstColumn( |
|
527
|
|
|
'SELECT DISTINCT LOWER(HEX(COALESCE(parent_id, id))) |
|
528
|
|
|
FROM product |
|
529
|
|
|
WHERE id in (:productIds) AND version_id = :version', |
|
530
|
|
|
['productIds' => $productIds, 'version' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION)], |
|
531
|
|
|
['productIds' => ArrayParameterType::STRING] |
|
532
|
|
|
); |
|
533
|
|
|
|
|
534
|
|
|
$categoryIds = $this->connection->fetchFirstColumn( |
|
535
|
|
|
'SELECT DISTINCT LOWER(HEX(category_id)) |
|
536
|
|
|
FROM product_category_tree |
|
537
|
|
|
WHERE product_id in (:productIds) AND product_version_id = :version', |
|
538
|
|
|
['productIds' => $productIds, 'version' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION)], |
|
539
|
|
|
['productIds' => ArrayParameterType::STRING] |
|
540
|
|
|
); |
|
541
|
|
|
|
|
542
|
|
|
return [...array_map([CachedProductDetailRoute::class, 'buildName'], array_filter($parentIds)), ...array_map([CachedProductListingRoute::class, 'buildName'], array_filter($categoryIds))]; |
|
|
|
|
|
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
/** |
|
546
|
|
|
* @param list<string> $ids |
|
547
|
|
|
* |
|
548
|
|
|
* @return list<string> |
|
549
|
|
|
*/ |
|
550
|
|
|
private function getProductCategoryIds(array $ids): array |
|
551
|
|
|
{ |
|
552
|
|
|
return $this->connection->fetchFirstColumn( |
|
|
|
|
|
|
553
|
|
|
'SELECT DISTINCT LOWER(HEX(category_id)) as category_id |
|
554
|
|
|
FROM product_category_tree |
|
555
|
|
|
WHERE product_id IN (:ids) |
|
556
|
|
|
AND product_version_id = :version |
|
557
|
|
|
AND category_version_id = :version', |
|
558
|
|
|
['ids' => Uuid::fromHexToBytesList($ids), 'version' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION)], |
|
559
|
|
|
['ids' => ArrayParameterType::STRING] |
|
560
|
|
|
); |
|
561
|
|
|
} |
|
562
|
|
|
|
|
563
|
|
|
/** |
|
564
|
|
|
* @return list<string> |
|
565
|
|
|
*/ |
|
566
|
|
|
private function getChangedShippingMethods(EntityWrittenContainerEvent $event): array |
|
567
|
|
|
{ |
|
568
|
|
|
$ids = $event->getPrimaryKeys(ShippingMethodDefinition::ENTITY_NAME); |
|
569
|
|
|
if (empty($ids)) { |
|
570
|
|
|
return []; |
|
|
|
|
|
|
571
|
|
|
} |
|
572
|
|
|
|
|
573
|
|
|
$ids = $this->connection->fetchFirstColumn( |
|
574
|
|
|
'SELECT DISTINCT LOWER(HEX(sales_channel_id)) as id FROM sales_channel_shipping_method WHERE shipping_method_id IN (:ids)', |
|
575
|
|
|
['ids' => Uuid::fromHexToBytesList($ids)], |
|
576
|
|
|
['ids' => ArrayParameterType::STRING] |
|
577
|
|
|
); |
|
578
|
|
|
|
|
579
|
|
|
$tags = []; |
|
580
|
|
|
if ($event->getDeletedPrimaryKeys(ShippingMethodDefinition::ENTITY_NAME)) { |
|
581
|
|
|
$tags[] = CachedShippingMethodRoute::ALL_TAG; |
|
582
|
|
|
} |
|
583
|
|
|
|
|
584
|
|
|
return array_merge($tags, array_map([CachedShippingMethodRoute::class, 'buildName'], $ids)); |
|
|
|
|
|
|
585
|
|
|
} |
|
586
|
|
|
|
|
587
|
|
|
/** |
|
588
|
|
|
* @return list<string> |
|
589
|
|
|
*/ |
|
590
|
|
|
private function getChangedShippingAssignments(EntityWrittenContainerEvent $event): array |
|
591
|
|
|
{ |
|
592
|
|
|
// Used to detect changes to the shipping assignment of a sales channel |
|
593
|
|
|
$ids = $event->getPrimaryKeys(SalesChannelShippingMethodDefinition::ENTITY_NAME); |
|
594
|
|
|
|
|
595
|
|
|
$ids = array_column($ids, 'salesChannelId'); |
|
596
|
|
|
|
|
597
|
|
|
return array_map([CachedShippingMethodRoute::class, 'buildName'], $ids); |
|
|
|
|
|
|
598
|
|
|
} |
|
599
|
|
|
|
|
600
|
|
|
/** |
|
601
|
|
|
* @return list<string> |
|
602
|
|
|
*/ |
|
603
|
|
|
private function getChangedPaymentMethods(EntityWrittenContainerEvent $event): array |
|
604
|
|
|
{ |
|
605
|
|
|
$ids = $event->getPrimaryKeys(PaymentMethodDefinition::ENTITY_NAME); |
|
606
|
|
|
if (empty($ids)) { |
|
607
|
|
|
return []; |
|
|
|
|
|
|
608
|
|
|
} |
|
609
|
|
|
|
|
610
|
|
|
$ids = $this->connection->fetchFirstColumn( |
|
611
|
|
|
'SELECT DISTINCT LOWER(HEX(sales_channel_id)) as id FROM sales_channel_payment_method WHERE payment_method_id IN (:ids)', |
|
612
|
|
|
['ids' => Uuid::fromHexToBytesList($ids)], |
|
613
|
|
|
['ids' => ArrayParameterType::STRING] |
|
614
|
|
|
); |
|
615
|
|
|
|
|
616
|
|
|
$tags = []; |
|
617
|
|
|
if ($event->getDeletedPrimaryKeys(PaymentMethodDefinition::ENTITY_NAME)) { |
|
618
|
|
|
$tags[] = CachedPaymentMethodRoute::ALL_TAG; |
|
619
|
|
|
} |
|
620
|
|
|
|
|
621
|
|
|
return array_merge($tags, array_map([CachedPaymentMethodRoute::class, 'buildName'], $ids)); |
|
|
|
|
|
|
622
|
|
|
} |
|
623
|
|
|
|
|
624
|
|
|
/** |
|
625
|
|
|
* @return list<string> |
|
626
|
|
|
*/ |
|
627
|
|
|
private function getChangedPaymentAssignments(EntityWrittenContainerEvent $event): array |
|
628
|
|
|
{ |
|
629
|
|
|
// Used to detect changes to the language assignment of a sales channel |
|
630
|
|
|
$ids = $event->getPrimaryKeys(SalesChannelPaymentMethodDefinition::ENTITY_NAME); |
|
631
|
|
|
|
|
632
|
|
|
$ids = array_column($ids, 'salesChannelId'); |
|
633
|
|
|
|
|
634
|
|
|
return array_map([CachedPaymentMethodRoute::class, 'buildName'], $ids); |
|
|
|
|
|
|
635
|
|
|
} |
|
636
|
|
|
|
|
637
|
|
|
/** |
|
638
|
|
|
* @return list<string> |
|
639
|
|
|
*/ |
|
640
|
|
|
private function getChangedCategories(EntityWrittenContainerEvent $event): array |
|
641
|
|
|
{ |
|
642
|
|
|
$ids = $event->getPrimaryKeysWithPayload(CategoryDefinition::ENTITY_NAME); |
|
643
|
|
|
|
|
644
|
|
|
if (empty($ids)) { |
|
645
|
|
|
return []; |
|
|
|
|
|
|
646
|
|
|
} |
|
647
|
|
|
|
|
648
|
|
|
/** @var list<string> $ids */ |
|
649
|
|
|
$ids = array_map([CachedNavigationRoute::class, 'buildName'], $ids); |
|
|
|
|
|
|
650
|
|
|
$ids[] = CachedNavigationRoute::BASE_NAVIGATION_TAG; |
|
651
|
|
|
|
|
652
|
|
|
return $ids; |
|
|
|
|
|
|
653
|
|
|
} |
|
654
|
|
|
|
|
655
|
|
|
/** |
|
656
|
|
|
* @return list<string> |
|
657
|
|
|
*/ |
|
658
|
|
|
private function getChangedEntryPoints(EntityWrittenContainerEvent $event): array |
|
659
|
|
|
{ |
|
660
|
|
|
$ids = $event->getPrimaryKeysWithPropertyChange( |
|
661
|
|
|
SalesChannelDefinition::ENTITY_NAME, |
|
662
|
|
|
['navigationCategoryId', 'navigationCategoryDepth', 'serviceCategoryId', 'footerCategoryId'] |
|
663
|
|
|
); |
|
664
|
|
|
|
|
665
|
|
|
if (empty($ids)) { |
|
666
|
|
|
return []; |
|
|
|
|
|
|
667
|
|
|
} |
|
668
|
|
|
|
|
669
|
|
|
return [CachedNavigationRoute::ALL_TAG]; |
|
|
|
|
|
|
670
|
|
|
} |
|
671
|
|
|
|
|
672
|
|
|
/** |
|
673
|
|
|
* @return list<string> |
|
674
|
|
|
*/ |
|
675
|
|
|
private function getChangedCountries(EntityWrittenContainerEvent $event): array |
|
676
|
|
|
{ |
|
677
|
|
|
$ids = $event->getPrimaryKeys(CountryDefinition::ENTITY_NAME); |
|
678
|
|
|
if (empty($ids)) { |
|
679
|
|
|
return []; |
|
|
|
|
|
|
680
|
|
|
} |
|
681
|
|
|
|
|
682
|
|
|
// Used to detect changes to the country itself and invalidate the route for all sales channels in which the country is assigned. |
|
683
|
|
|
$ids = $this->connection->fetchFirstColumn( |
|
684
|
|
|
'SELECT DISTINCT LOWER(HEX(sales_channel_id)) as id FROM sales_channel_country WHERE country_id IN (:ids)', |
|
685
|
|
|
['ids' => Uuid::fromHexToBytesList($ids)], |
|
686
|
|
|
['ids' => ArrayParameterType::STRING] |
|
687
|
|
|
); |
|
688
|
|
|
|
|
689
|
|
|
$tags = []; |
|
690
|
|
|
if ($event->getDeletedPrimaryKeys(CountryDefinition::ENTITY_NAME)) { |
|
691
|
|
|
$tags[] = CachedCountryRoute::ALL_TAG; |
|
692
|
|
|
} |
|
693
|
|
|
|
|
694
|
|
|
return array_merge($tags, array_map([CachedCountryRoute::class, 'buildName'], $ids)); |
|
|
|
|
|
|
695
|
|
|
} |
|
696
|
|
|
|
|
697
|
|
|
/** |
|
698
|
|
|
* @return list<string> |
|
699
|
|
|
*/ |
|
700
|
|
|
private function getChangedCountryAssignments(EntityWrittenContainerEvent $event): array |
|
701
|
|
|
{ |
|
702
|
|
|
// Used to detect changes to the country assignment of a sales channel |
|
703
|
|
|
$ids = $event->getPrimaryKeys(SalesChannelCountryDefinition::ENTITY_NAME); |
|
704
|
|
|
|
|
705
|
|
|
$ids = array_column($ids, 'salesChannelId'); |
|
706
|
|
|
|
|
707
|
|
|
return array_map([CachedCountryRoute::class, 'buildName'], $ids); |
|
|
|
|
|
|
708
|
|
|
} |
|
709
|
|
|
|
|
710
|
|
|
/** |
|
711
|
|
|
* @return list<string> |
|
712
|
|
|
*/ |
|
713
|
|
|
private function getChangedSalutations(EntityWrittenContainerEvent $event): array |
|
714
|
|
|
{ |
|
715
|
|
|
$ids = $event->getPrimaryKeys(SalutationDefinition::ENTITY_NAME); |
|
716
|
|
|
if (empty($ids)) { |
|
717
|
|
|
return []; |
|
|
|
|
|
|
718
|
|
|
} |
|
719
|
|
|
|
|
720
|
|
|
return [CachedSalutationRoute::ALL_TAG]; |
|
|
|
|
|
|
721
|
|
|
} |
|
722
|
|
|
|
|
723
|
|
|
/** |
|
724
|
|
|
* @return list<string> |
|
725
|
|
|
*/ |
|
726
|
|
|
private function getChangedLanguages(EntityWrittenContainerEvent $event): array |
|
727
|
|
|
{ |
|
728
|
|
|
$ids = $event->getPrimaryKeys(LanguageDefinition::ENTITY_NAME); |
|
729
|
|
|
if (empty($ids)) { |
|
730
|
|
|
return []; |
|
|
|
|
|
|
731
|
|
|
} |
|
732
|
|
|
|
|
733
|
|
|
// Used to detect changes to the language itself and invalidate the route for all sales channels in which the language is assigned. |
|
734
|
|
|
$ids = $this->connection->fetchFirstColumn( |
|
735
|
|
|
'SELECT DISTINCT LOWER(HEX(sales_channel_id)) as id FROM sales_channel_language WHERE language_id IN (:ids)', |
|
736
|
|
|
['ids' => Uuid::fromHexToBytesList($ids)], |
|
737
|
|
|
['ids' => ArrayParameterType::STRING] |
|
738
|
|
|
); |
|
739
|
|
|
|
|
740
|
|
|
$tags = []; |
|
741
|
|
|
if ($event->getDeletedPrimaryKeys(LanguageDefinition::ENTITY_NAME)) { |
|
742
|
|
|
$tags[] = CachedLanguageRoute::ALL_TAG; |
|
743
|
|
|
} |
|
744
|
|
|
|
|
745
|
|
|
return array_merge($tags, array_map([CachedLanguageRoute::class, 'buildName'], $ids)); |
|
|
|
|
|
|
746
|
|
|
} |
|
747
|
|
|
|
|
748
|
|
|
/** |
|
749
|
|
|
* @return list<string> |
|
750
|
|
|
*/ |
|
751
|
|
|
private function getChangedLanguageAssignments(EntityWrittenContainerEvent $event): array |
|
752
|
|
|
{ |
|
753
|
|
|
// Used to detect changes to the language assignment of a sales channel |
|
754
|
|
|
$ids = $event->getPrimaryKeys(SalesChannelLanguageDefinition::ENTITY_NAME); |
|
755
|
|
|
|
|
756
|
|
|
$ids = array_column($ids, 'salesChannelId'); |
|
757
|
|
|
|
|
758
|
|
|
return array_map([CachedLanguageRoute::class, 'buildName'], $ids); |
|
|
|
|
|
|
759
|
|
|
} |
|
760
|
|
|
|
|
761
|
|
|
/** |
|
762
|
|
|
* @return list<string> |
|
763
|
|
|
*/ |
|
764
|
|
|
private function getChangedCurrencies(EntityWrittenContainerEvent $event): array |
|
765
|
|
|
{ |
|
766
|
|
|
$ids = $event->getPrimaryKeys(CurrencyDefinition::ENTITY_NAME); |
|
767
|
|
|
|
|
768
|
|
|
if (empty($ids)) { |
|
769
|
|
|
return []; |
|
|
|
|
|
|
770
|
|
|
} |
|
771
|
|
|
|
|
772
|
|
|
// Used to detect changes to the currency itself and invalidate the route for all sales channels in which the currency is assigned. |
|
773
|
|
|
$ids = $this->connection->fetchFirstColumn( |
|
774
|
|
|
'SELECT DISTINCT LOWER(HEX(sales_channel_id)) as id FROM sales_channel_currency WHERE currency_id IN (:ids)', |
|
775
|
|
|
['ids' => Uuid::fromHexToBytesList($ids)], |
|
776
|
|
|
['ids' => ArrayParameterType::STRING] |
|
777
|
|
|
); |
|
778
|
|
|
|
|
779
|
|
|
$tags = []; |
|
780
|
|
|
if ($event->getDeletedPrimaryKeys(CurrencyDefinition::ENTITY_NAME)) { |
|
781
|
|
|
$tags[] = CachedCurrencyRoute::ALL_TAG; |
|
782
|
|
|
} |
|
783
|
|
|
|
|
784
|
|
|
return array_merge($tags, array_map([CachedCurrencyRoute::class, 'buildName'], $ids)); |
|
|
|
|
|
|
785
|
|
|
} |
|
786
|
|
|
|
|
787
|
|
|
/** |
|
788
|
|
|
* @return list<string> |
|
789
|
|
|
*/ |
|
790
|
|
|
private function getChangedCurrencyAssignments(EntityWrittenContainerEvent $event): array |
|
791
|
|
|
{ |
|
792
|
|
|
// Used to detect changes to the currency assignment of a sales channel |
|
793
|
|
|
$ids = $event->getPrimaryKeys(SalesChannelCurrencyDefinition::ENTITY_NAME); |
|
794
|
|
|
|
|
795
|
|
|
$ids = array_column($ids, 'salesChannelId'); |
|
796
|
|
|
|
|
797
|
|
|
return array_map([CachedCurrencyRoute::class, 'buildName'], $ids); |
|
|
|
|
|
|
798
|
|
|
} |
|
799
|
|
|
} |
|
800
|
|
|
|