|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Content\Sitemap\ScheduledTask; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Content\Sitemap\Event\SitemapSalesChannelCriteriaEvent; |
|
6
|
|
|
use Shopware\Core\Content\Sitemap\Service\SitemapExporterInterface; |
|
7
|
|
|
use Shopware\Core\Defaults; |
|
8
|
|
|
use Shopware\Core\Framework\Context; |
|
9
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; |
|
10
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; |
|
11
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; |
|
12
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter; |
|
13
|
|
|
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskHandler; |
|
14
|
|
|
use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelDomain\SalesChannelDomainEntity; |
|
|
|
|
|
|
15
|
|
|
use Shopware\Core\System\SalesChannel\SalesChannelEntity; |
|
|
|
|
|
|
16
|
|
|
use Shopware\Core\System\SystemConfig\SystemConfigService; |
|
17
|
|
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler; |
|
18
|
|
|
use Symfony\Component\Messenger\MessageBusInterface; |
|
19
|
|
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @package sales-channel |
|
23
|
|
|
* |
|
24
|
|
|
* @internal |
|
25
|
|
|
*/ |
|
26
|
|
|
#[AsMessageHandler(handles: SitemapGenerateTask::class)] |
|
27
|
|
|
final class SitemapGenerateTaskHandler extends ScheduledTaskHandler |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @internal |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct( |
|
33
|
|
|
EntityRepository $scheduledTaskRepository, |
|
34
|
|
|
private EntityRepository $salesChannelRepository, |
|
35
|
|
|
private SystemConfigService $systemConfigService, |
|
36
|
|
|
private MessageBusInterface $messageBus, |
|
37
|
|
|
private EventDispatcherInterface $eventDispatcher |
|
38
|
|
|
) { |
|
39
|
|
|
parent::__construct($scheduledTaskRepository); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function run(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$sitemapRefreshStrategy = $this->systemConfigService->getInt('core.sitemap.sitemapRefreshStrategy'); |
|
45
|
|
|
if ($sitemapRefreshStrategy !== SitemapExporterInterface::STRATEGY_SCHEDULED_TASK) { |
|
46
|
|
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$criteria = new Criteria(); |
|
50
|
|
|
$criteria->addAssociation('domains'); |
|
51
|
|
|
$criteria->addFilter(new NotFilter( |
|
52
|
|
|
NotFilter::CONNECTION_AND, |
|
53
|
|
|
[new EqualsFilter('domains.id', null)] |
|
54
|
|
|
)); |
|
55
|
|
|
|
|
56
|
|
|
$criteria->addAssociation('type'); |
|
57
|
|
|
$criteria->addFilter(new EqualsFilter('type.id', Defaults::SALES_CHANNEL_TYPE_STOREFRONT)); |
|
58
|
|
|
|
|
59
|
|
|
$context = Context::createDefaultContext(); |
|
60
|
|
|
|
|
61
|
|
|
$this->eventDispatcher->dispatch( |
|
62
|
|
|
new SitemapSalesChannelCriteriaEvent($criteria, $context) |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
$salesChannels = $this->salesChannelRepository->search($criteria, $context)->getEntities(); |
|
66
|
|
|
|
|
67
|
|
|
/** @var SalesChannelEntity $salesChannel */ |
|
68
|
|
|
foreach ($salesChannels as $salesChannel) { |
|
69
|
|
|
if ($salesChannel->getDomains() === null) { |
|
70
|
|
|
continue; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$languageIds = $salesChannel->getDomains()->map(function (SalesChannelDomainEntity $salesChannelDomain) { |
|
74
|
|
|
return $salesChannelDomain->getLanguageId(); |
|
75
|
|
|
}); |
|
76
|
|
|
|
|
77
|
|
|
$languageIds = array_unique($languageIds); |
|
78
|
|
|
|
|
79
|
|
|
foreach ($languageIds as $languageId) { |
|
80
|
|
|
$this->messageBus->dispatch(new SitemapMessage($salesChannel->getId(), $languageId, null, null, false)); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
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