Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Get Shopware Version
id: shopware-constraint
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
composer -V

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }}

Expand All @@ -65,7 +65,7 @@ jobs:
composer create-placeholders
php -d pcov.enabled=1 ${{ github.workspace }}/vendor/bin/phpunit --coverage-clover clover.xml --testsuite Unit

- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:
composer -V

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }}

Expand All @@ -112,7 +112,7 @@ jobs:
composer create-placeholders
php -d pcov.enabled=1 ${{ github.workspace }}/vendor/bin/phpunit --testsuite Integration

- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
Expand Down
13 changes: 13 additions & 0 deletions phpstan.baseline-generated-files.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ parameters:
count: 1
path: src/DependencyInjection/ThumbnailService.php
reportUnmatched: false

-
message: '#^Call to deprecated method#'
count: 3
path: src/DependencyInjection/ThumbnailService.php
reportUnmatched: false

-
message: '#^Only booleans are allowed in &&#'
count: 1
path: src/DependencyInjection/ThumbnailService.php
reportUnmatched: false

-
message: "#^Call to an undefined method Shopware\\\\Core\\\\Content\\\\Media\\\\Message\\\\GenerateThumbnailsMessage\\:\\:setContext\\(\\)\\.$#"
count: 1
Expand Down
6 changes: 5 additions & 1 deletion src/Controller/Api/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;
use Shopware\Core\Content\Media\Aggregate\MediaFolder\MediaFolderCollection;

#[Route(defaults: ['_routeScope' => ['api']])]
class TestController
{
public const REQUEST_ATTRIBUTE_TEST_ACTIVE = 'FroshPlatformThumbnailProcessorTestActive';
public const TEST_FILE_PATH = __DIR__ . '/../../Resources/data/froshthumbnailprocessortestimage.jpg';

/**
* @param EntityRepository<MediaCollection> $mediaRepository
* @param EntityRepository<MediaFolderCollection> $mediaFolderRepository
*/
public function __construct(
private readonly AbstractMediaUrlGenerator $urlGenerator,
private readonly EntityRepository $mediaRepository,
Expand Down Expand Up @@ -143,7 +148,6 @@ private function getMediaById(string $fileName, Context $context): ?MediaEntity
// we use the fileName filter to add backward compatibility
$criteria->addFilter(new EqualsFilter('fileName', $fileName));

/** @var MediaCollection $entities */
$entities = $this->mediaRepository->search($criteria, $context)->getEntities();

return $entities->first();
Expand Down
20 changes: 15 additions & 5 deletions src/DependencyInjection/GeneratorCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,19 @@ private function handleThumbnailService(NodeFinder $nodeFinder, array $ast): voi
} catch (\RuntimeException $e) {
if ($e->getMessage() === 'Method createThumbnailsForSizes in class Shopware\Core\Content\Media\Thumbnail\ThumbnailService is missing') {
$generateAndSaveNode = $this->getClassMethod($nodeFinder, 'generateAndSave', $ast);
$this->handleGenerateAndSaveNode($generateAndSaveNode);

// when the internal 'isSameDimension' method is no longer available, we need to add the 'mediaThumbnailSizeId' field
$addMediaThumbnailSizeId = true;
try {
$this->getClassMethod($nodeFinder, 'isSameDimension', $ast);
$addMediaThumbnailSizeId = false;
} catch (\RuntimeException $e) {
if ($e->getMessage() !== 'Method isSameDimension in class Shopware\Core\Content\Media\Thumbnail\ThumbnailService is missing') {
throw $e;
}
}

$this->handleGenerateAndSaveNode($generateAndSaveNode, $addMediaThumbnailSizeId);
} else {
throw $e;
}
Expand Down Expand Up @@ -269,7 +281,7 @@ private function handleCreateThumbnailsForSizes(ClassMethod $createThumbnailsFor
return $savedThumbnails;');
}

private function handleGenerateAndSaveNode(ClassMethod $generateAndSaveNode): void
private function handleGenerateAndSaveNode(ClassMethod $generateAndSaveNode, bool $addMediaThumbnailSizeId): void
{
// we don't need to generate the files, so we just return the array
$generateAndSaveNode->stmts = $this->getPhpParser()
Expand All @@ -284,15 +296,13 @@ private function handleGenerateAndSaveNode(ClassMethod $generateAndSaveNode): vo
throw MediaException::mediaTypeNotLoaded($media->getId());
}

$mapped = [];
foreach ($sizes as $size) {
$id = Uuid::randomHex();

$mapped[$size->getId()] = $id;

$records[] = [
\'id\' => $id,
\'mediaId\' => $media->getId(),
' . ($addMediaThumbnailSizeId ? '\'mediaThumbnailSizeId\' => $size->getId(),' : '') . '
\'width\' => $size->getWidth(),
\'height\' => $size->getHeight(),
];
Expand Down
6 changes: 4 additions & 2 deletions src/EventListener/ThumbnailSizesChangedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Frosh\ThumbnailProcessor\EventListener;

use Shopware\Core\Content\Media\Aggregate\MediaFolder\MediaFolderEntity;
use Shopware\Core\Content\Media\Aggregate\MediaFolderConfigurationMediaThumbnailSize\MediaFolderConfigurationMediaThumbnailSizeDefinition;
use Shopware\Core\Content\Media\Commands\GenerateThumbnailsCommand;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
Expand All @@ -12,9 +11,13 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Content\Media\Aggregate\MediaFolder\MediaFolderCollection;

class ThumbnailSizesChangedListener implements EventSubscriberInterface
{
/**
* @param EntityRepository<MediaFolderCollection> $mediaFolderRepository
*/
public function __construct(
private readonly GenerateThumbnailsCommand $generateThumbnailsCommand,
private readonly EntityRepository $mediaFolderRepository,
Expand Down Expand Up @@ -52,7 +55,6 @@ public function onThumbnailSizeChanged(EntityWrittenEvent $event): void

$result = $this->mediaFolderRepository->search($criteria, $event->getContext());

/** @var MediaFolderEntity $entity */
foreach ($result->getEntities() as $entity) {
$parameters = [];

Expand Down
4 changes: 4 additions & 0 deletions src/Service/SalesChannelIdDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
use Shopware\Core\PlatformRequest;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Shopware\Core\Content\ProductExport\ProductExportCollection;

class SalesChannelIdDetector
{
/**
* @param EntityRepository<ProductExportCollection> $productExportRepository
*/
public function __construct(
private readonly RequestStack $requestStack,
private readonly EntityRepository $productExportRepository
Expand Down
9 changes: 6 additions & 3 deletions tests/integration/MediaUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Shopware\Core\Content\Media\Aggregate\MediaThumbnail\MediaThumbnailCollection;
use Shopware\Core\Content\Media\Commands\GenerateThumbnailsCommand;
use Shopware\Core\Content\Media\Core\Application\AbstractMediaUrlGenerator;
use Shopware\Core\Content\Media\MediaCollection;
use Shopware\Core\Content\Media\MediaEntity;
use Shopware\Core\Content\Test\Media\MediaFixtures;
use Shopware\Core\Framework\Context;
Expand All @@ -18,14 +19,16 @@
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\DependencyInjection\ContainerInterface;

class MediaUrlTest extends TestCase
{
use IntegrationTestBehaviour;
use MediaFixtures;
use QueueTestBehaviour;

/**
* @var EntityRepository<MediaCollection>
*/
private EntityRepository $mediaRepository;

private GenerateThumbnailsCommand $generateThumbnailsCommand;
Expand Down Expand Up @@ -90,8 +93,8 @@ public function testMediaUrlWithInactiveConfigResultsInOriginalMedia(): void

$mediaResult = $this->mediaRepository->search($searchCriteria, $this->context);

/** @var MediaEntity $updatedMedia */
$updatedMedia = $mediaResult->getEntities()->first();
static::assertInstanceOf(MediaEntity::class, $updatedMedia);

$thumbnails = $updatedMedia->getThumbnails();
static::assertInstanceOf(MediaThumbnailCollection::class, $thumbnails);
Expand Down Expand Up @@ -150,8 +153,8 @@ public function testMediaUrlWithActiveConfig(): void

$mediaResult = $this->mediaRepository->search($searchCriteria, $this->context);

/** @var MediaEntity $updatedMedia */
$updatedMedia = $mediaResult->getEntities()->first();
static::assertInstanceOf(MediaEntity::class, $updatedMedia);

$thumbnails = $updatedMedia->getThumbnails();
static::assertInstanceOf(MediaThumbnailCollection::class, $thumbnails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function testOnThumbnailSizeChanged(): void
$mediaFolderCollection = new MediaFolderCollection();
$mediaFolderCollection->add($mediaFolderEntity);

/** @var StaticEntityRepository<MediaFolderCollection> */
$mediaFolderRepository = new StaticEntityRepository([$mediaFolderCollection]);

$thumbnailSizesChangedListener = new ThumbnailSizesChangedListener(
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/Service/SalesChannelIdDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Frosh\ThumbnailProcessor\Tests\Unit\Service;

use Frosh\ThumbnailProcessor\Service\SalesChannelIdDetector;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Shopware\Core\Content\ProductExport\ProductExportCollection;
use Shopware\Core\Content\ProductExport\ProductExportEntity;
Expand Down Expand Up @@ -90,6 +91,7 @@ public function testGetSalesChannelIdProductExport(): void
$productExportCollection = new ProductExportCollection();
$productExportCollection->add($productExportEntity);

/** @var StaticEntityRepository<ProductExportCollection> */
$productExportRepository = new StaticEntityRepository([$productExportCollection]);

$class = new SalesChannelIdDetector($requestStack, $productExportRepository);
Expand All @@ -106,6 +108,7 @@ public function testGetSalesChannelIdProductExportWithoutFileNameAndAccessKey():
],
));

/** @var StaticEntityRepository<ProductExportCollection>&MockObject */
$productExportRepository = $this->createMock(StaticEntityRepository::class);
$productExportRepository->expects(static::never())->method('search');

Expand Down