|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Content\Media\Infrastructure\Path; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\ArrayParameterType; |
|
6
|
|
|
use Doctrine\DBAL\Connection; |
|
7
|
|
|
use Shopware\Core\Content\Media\Core\Application\MediaPathUpdater; |
|
8
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Dbal\Common\IteratorFactory; |
|
9
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexer; |
|
10
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexingMessage; |
|
11
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Indexing\PostUpdateIndexer; |
|
12
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
13
|
|
|
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException; |
|
14
|
|
|
use Shopware\Core\Framework\Uuid\Uuid; |
|
15
|
|
|
|
|
16
|
|
|
#[Package('core')] |
|
17
|
|
|
class MediaPathPostUpdater extends PostUpdateIndexer |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @internal |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct( |
|
23
|
|
|
private readonly IteratorFactory $iteratorFactory, |
|
24
|
|
|
private readonly MediaPathUpdater $updater, |
|
25
|
|
|
private readonly Connection $connection |
|
26
|
|
|
) { |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function getName(): string |
|
30
|
|
|
{ |
|
31
|
|
|
return 'media.path.post_update'; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function iterate(?array $offset): ?EntityIndexingMessage |
|
35
|
|
|
{ |
|
36
|
|
|
$iterator = $this->iteratorFactory->createIterator('media', $offset); |
|
37
|
|
|
|
|
38
|
|
|
$ids = $iterator->fetch(); |
|
39
|
|
|
|
|
40
|
|
|
if (empty($ids)) { |
|
41
|
|
|
return null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return new EntityIndexingMessage(array_values($ids), $iterator->getOffset()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function handle(EntityIndexingMessage $message): void |
|
48
|
|
|
{ |
|
49
|
|
|
$this->updater->updateMedia($message->getData()); |
|
50
|
|
|
|
|
51
|
|
|
$thumbnails = $this->connection->fetchFirstColumn( |
|
52
|
|
|
'SELECT LOWER(HEX(id)) FROM media_thumbnail WHERE media_id IN (:ids)', |
|
53
|
|
|
['ids' => Uuid::fromHexToBytesList($message->getData())], |
|
54
|
|
|
['ids' => ArrayParameterType::STRING] |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
$this->updater->updateThumbnails($thumbnails); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getTotal(): int |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->iteratorFactory->createIterator('media', null)->fetchCount(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getDecorated(): EntityIndexer |
|
66
|
|
|
{ |
|
67
|
|
|
throw new DecorationPatternException(self::class); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|