|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Content\Sitemap\ScheduledTask; |
|
4
|
|
|
|
|
5
|
|
|
use Psr\Log\LoggerInterface; |
|
6
|
|
|
use Shopware\Core\Content\Sitemap\Exception\AlreadyLockedException; |
|
7
|
|
|
use Shopware\Core\Content\Sitemap\Service\SitemapExporterInterface; |
|
8
|
|
|
use Shopware\Core\System\SalesChannel\Context\AbstractSalesChannelContextFactory; |
|
9
|
|
|
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextService; |
|
10
|
|
|
use Shopware\Core\System\SystemConfig\SystemConfigService; |
|
11
|
|
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @package sales-channel |
|
15
|
|
|
* |
|
16
|
|
|
* @internal |
|
17
|
|
|
*/ |
|
18
|
|
|
#[AsMessageHandler] |
|
19
|
|
|
final class SitemapMessageHandler |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @internal |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct( |
|
25
|
|
|
private AbstractSalesChannelContextFactory $salesChannelContextFactory, |
|
26
|
|
|
private SitemapExporterInterface $sitemapExporter, |
|
27
|
|
|
private LoggerInterface $logger, |
|
28
|
|
|
private SystemConfigService $systemConfigService, |
|
29
|
|
|
) { |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function __invoke(SitemapMessage $message): void |
|
33
|
|
|
{ |
|
34
|
|
|
$sitemapRefreshStrategy = $this->systemConfigService->getInt('core.sitemap.sitemapRefreshStrategy'); |
|
35
|
|
|
if ($sitemapRefreshStrategy !== SitemapExporterInterface::STRATEGY_SCHEDULED_TASK) { |
|
36
|
|
|
return; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$this->generate($message); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
private function generate(SitemapMessage $message): void |
|
43
|
|
|
{ |
|
44
|
|
|
if ($message->getLastSalesChannelId() === null || $message->getLastLanguageId() === null) { |
|
|
|
|
|
|
45
|
|
|
return; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$context = $this->salesChannelContextFactory->create('', $message->getLastSalesChannelId(), [SalesChannelContextService::LANGUAGE_ID => $message->getLastLanguageId()]); |
|
49
|
|
|
|
|
50
|
|
|
try { |
|
51
|
|
|
$this->sitemapExporter->generate($context, true, $message->getLastProvider(), $message->getNextOffset()); |
|
52
|
|
|
} catch (AlreadyLockedException $exception) { |
|
53
|
|
|
$this->logger->error(sprintf('ERROR: %s', $exception->getMessage())); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|