Skip to content

Commit

Permalink
Merge branch 'next-36982/auto-imported-from-github' into 'trunk'
Browse files Browse the repository at this point in the history
NEXT-36982 - Fix media url loader with unset thumbnails

See merge request shopware/6/product/platform!14121
  • Loading branch information
marcelbrode committed Jun 26, 2024
2 parents 7057965 + ad34964 commit 9b4febd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Fix media url loader with unset thumbnails
issue: NEXT-36982
author: Elias Lackner
author_email: [email protected]
author_github: @lacknere
---
# Core
* Changed `MediaUrlLoader::loaded` and `MediaUrlLoader::map` methods to skip thumbnails if unset.
4 changes: 2 additions & 2 deletions src/Core/Content/Media/Core/Application/MediaUrlLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function loaded(iterable $entities): void

$entity->assign(['url' => $urls[$entity->getUniqueIdentifier()]]);

if (!$entity->has('thumbnails')) {
if (!$entity->has('thumbnails') || $entity->get('thumbnails') === null) {
continue;
}

Expand Down Expand Up @@ -91,7 +91,7 @@ private function map(iterable $entities): array

$mapped[$entity->getUniqueIdentifier()] = UrlParams::fromMedia($entity);

if (!$entity->has('thumbnails')) {
if (!$entity->has('thumbnails') || $entity->get('thumbnails') === null) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ public function testLoad(IdsCollection $ids, PartialEntity $entity, array $expec
$actual = [$entity->get('id') => $entity->get('url')];

if ($entity->has('thumbnails')) {
static::assertIsIterable($entity->get('thumbnails'));
foreach ($entity->get('thumbnails') as $thumbnail) {
static::assertInstanceOf(Entity::class, $thumbnail);
$actual[$thumbnail->get('id')] = $thumbnail->get('url');
if ($entity->get('thumbnails') !== null) {
static::assertIsIterable($entity->get('thumbnails'));
foreach ($entity->get('thumbnails') as $thumbnail) {
static::assertInstanceOf(Entity::class, $thumbnail);
$actual[$thumbnail->get('id')] = $thumbnail->get('url');
}
} else {
$actual[$ids->get('thumbnail')] = null;
}
}

Expand Down Expand Up @@ -91,6 +95,20 @@ public static function loadedProvider(): \Generator
[$ids->get('media') => 'http://localhost:8000/foo/bar.png?ts=946684800'],
];

yield 'Test with unset thumbnails' => [
$ids,
(new PartialEntity())->assign([
'id' => $ids->get('media'),
'path' => '/foo/bar.png',
'private' => false,
'thumbnails' => null,
]),
[
$ids->get('media') => 'http://localhost:8000/foo/bar.png',
$ids->get('thumbnail') => null,
],
];

yield 'Test with thumbnails' => [
$ids,
(new PartialEntity())->assign([
Expand Down

0 comments on commit 9b4febd

Please sign in to comment.