Passed
Push — trunk ( dee18d...92a8fe )
by Christian
12:13 queued 12s
created

GenerateThumbnailsHandler::getHandledMessages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Content\Media\Message;
4
5
use Shopware\Core\Content\Media\MediaCollection;
6
use Shopware\Core\Content\Media\Thumbnail\ThumbnailService;
7
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
8
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
9
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
10
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
11
12
/**
13
 * @package content
14
 *
15
 * @internal
16
 */
17
#[AsMessageHandler]
18
final class GenerateThumbnailsHandler
19
{
20
    /**
21
     * @internal
22
     */
23
    public function __construct(private ThumbnailService $thumbnailService, private EntityRepository $mediaRepository)
24
    {
25
    }
26
27
    public function __invoke(GenerateThumbnailsMessage|UpdateThumbnailsMessage $msg): void
28
    {
29
        $context = $msg->readContext();
30
31
        $criteria = new Criteria();
32
        $criteria->addAssociation('mediaFolder.configuration.mediaThumbnailSizes');
33
        $criteria->addFilter(new EqualsAnyFilter('media.id', $msg->getMediaIds()));
34
35
        /** @var MediaCollection $entities */
36
        $entities = $this->mediaRepository->search($criteria, $context)->getEntities();
37
38
        if ($msg instanceof UpdateThumbnailsMessage) {
39
            foreach ($entities as $media) {
40
                $this->thumbnailService->updateThumbnails($media, $context, $msg->isStrict());
0 ignored issues
show
Deprecated Code introduced by
The function Shopware\Core\Content\Me...ice::updateThumbnails() has been deprecated: tag:v6.5.0 - Parameter $strict will be mandatory in future implementation ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

40
                /** @scrutinizer ignore-deprecated */ $this->thumbnailService->updateThumbnails($media, $context, $msg->isStrict());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
41
            }
42
        } else {
43
            $this->thumbnailService->generate($entities, $context);
44
        }
45
    }
46
}
47