Skip to content

Commit 39944f1

Browse files
xyngtinect
andauthored
feature: allow passing media timestamp to image service (#132)
* feature: allow passing media timestamp to image service * feat: change string "null" to "0" * chore: release 5.1.0 --------- Co-authored-by: tinect <[email protected]>
1 parent 9ce705d commit 39944f1

File tree

10 files changed

+36
-29
lines changed

10 files changed

+36
-29
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232
mysql -V
3333
php -v
3434
composer -V
35-
echo ${{ github.workspace }}
3635
3736
- name: Checkout
3837
uses: actions/checkout@v3
@@ -73,14 +72,14 @@ jobs:
7372
with:
7473
shopware-version: ${{ matrix.version }}
7574
php-version: ${{ matrix.php-version }}
75+
php-extensions: pcov
7676

7777
- name: Info
7878
run: |
7979
php bin/console -V
8080
mysql -V
8181
php -v
8282
composer -V
83-
echo ${{ github.workspace }}
8483
8584
- name: Checkout
8685
uses: actions/checkout@v3

CHANGELOG_en-GB.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 5.1.0
2+
* Add variable mediaUpdatedAt for paths to prevent caching
3+
14
# 5.0.1
25
* Fix support for cloning product entity
36

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Available variables with examples:
4848
* {mediaUrl}: https://www.example.com/
4949
* {mediaPath}: media/01/82/69/sasse.png
5050
* {width}: 800
51+
* {mediaUpdatedAt}: 1716882050 (unix timestamp) or 0
5152

5253
Feel free to decorate `ThumbnailUrlTemplateInterface` to add more individual functions like [signed imgproxy](https://github.com/FriendsOfShopware/FroshPlatformThumbnailProcessorImgProxy)
5354

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"thumbnail"
1212
],
1313
"description": "This plugins allows you to use variable thumbnails, without having them on storage.",
14-
"version": "5.0.1",
14+
"version": "5.1.0",
1515
"type": "shopware-platform-plugin",
1616
"license": "mit",
1717
"authors": [

src/Core/Media/MediaUrlGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public function generate(array $paths): array
5151
$urls[$key] = $this->thumbnailUrlTemplate->getUrl(
5252
$baseUrl,
5353
$value->path,
54-
$this->getWidth($maxWidth, $value)
54+
$this->getWidth($maxWidth, $value),
55+
$value->updatedAt
5556
);
5657
}
5758

src/Resources/app/administration/src/module/frosh-thumbnail-processor/frosh-thumbnail-processor-info-texts/frosh-thumbnail-processor-info-texts.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<b>{mediaUrl}</b>: e.g. https://cdn.test.de/<br>
1010
<b>{mediaPath}</b>: e.g. media/image/5b/6d/16/tea.png<br>
1111
<b>{width}</b>: e.g. 800
12+
<b>{mediaUpdatedAt}</b>: 1716882050 (unix timestamp) or 0
1213
</p>
1314

1415
<p>

src/Resources/config/config.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
<helpText><![CDATA[available variables:<br>
2121
{mediaUrl}: https://cdn.test.de/<br>
2222
{mediaPath}: media/image/5b/6d/16/tea.png<br>
23-
{width}: 800
23+
{width}: 800<br>
24+
{mediaUpdatedAt}: 1716882050 (unix timestamp) or 0
2425
]]></helpText>
2526
</input-field>
2627

src/Service/ThumbnailUrlTemplate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ public function __construct(
1111
) {
1212
}
1313

14-
public function getUrl(string $mediaUrl, string $mediaPath, string $width): string
14+
public function getUrl(string $mediaUrl, string $mediaPath, string $width, ?\DateTimeInterface $mediaUpdatedAt): string
1515
{
1616
return str_replace(
17-
['{mediaUrl}', '{mediaPath}', '{width}'],
18-
[$mediaUrl, $mediaPath, $width],
17+
['{mediaUrl}', '{mediaPath}', '{width}', '{mediaUpdatedAt}'],
18+
[$mediaUrl, $mediaPath, $width, $mediaUpdatedAt?->getTimestamp() ?: '0'],
1919
$this->getPattern()
2020
);
2121
}

src/Service/ThumbnailUrlTemplateInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
interface ThumbnailUrlTemplateInterface
66
{
7-
public function getUrl(string $mediaUrl, string $mediaPath, string $width): string;
7+
public function getUrl(string $mediaUrl, string $mediaPath, string $width, ?\DateTimeInterface $mediaUpdatedAt): string;
88
}
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Frosh\ThumbnailProcessor\TestsUnit\Service;
3+
namespace Frosh\ThumbnailProcessor\Tests\Unit\Service;
44

55
use Frosh\ThumbnailProcessor\Service\ConfigReader;
66
use Frosh\ThumbnailProcessor\Service\ThumbnailUrlTemplate;
@@ -9,65 +9,66 @@
99

1010
class ThumbnailUrlTemplateTest extends TestCase
1111
{
12-
/**
12+
/**
1313
* @dataProvider getSalesChannelIds
1414
*/
15-
public function testGetUrl(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width): void
15+
public function testGetUrl(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width, ?\DateTimeInterface $date): void
1616
{
1717
$configReader = $this->createMock(ConfigReader::class);
1818
$configReader->expects(static::once())
19-
->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}&uff');
19+
->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}&updatedAt={mediaUpdatedAt}&uff');
2020

2121
$class = new ThumbnailUrlTemplate($configReader);
2222

23-
$url = $class->getUrl($mediaUrl, $mediaPath, $width);
23+
$url = $class->getUrl($mediaUrl, $mediaPath, $width, $date);
2424

25-
static::assertSame(\sprintf('%s/%s?width=%s&uff', $mediaUrl, $mediaPath, $width), $url);
25+
static::assertSame(\sprintf('%s/%s?width=%s&updatedAt=%s&uff', $mediaUrl, $mediaPath, $width, $date?->getTimestamp() ?: '0'), $url);
2626
}
2727

2828
/**
2929
* @dataProvider getSalesChannelIds
3030
*/
31-
public function testGetUrlWithoutSetConfig(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width): void
31+
public function testGetUrlWithoutSetConfig(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width, ?\DateTimeInterface $date): void
3232
{
3333
$configReader = $this->createMock(ConfigReader::class);
3434
$configReader->expects(static::once())
35-
->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}');
35+
->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}&updatedAt={mediaUpdatedAt}');
3636

3737
$class = new ThumbnailUrlTemplate($configReader);
3838

39-
$url = $class->getUrl($mediaUrl, $mediaPath, $width);
39+
$url = $class->getUrl($mediaUrl, $mediaPath, $width, $date);
4040

41-
static::assertSame(\sprintf('%s/%s?width=%s', $mediaUrl, $mediaPath, $width), $url);
41+
static::assertSame(\sprintf('%s/%s?width=%s&updatedAt=%s', $mediaUrl, $mediaPath, $width, $date?->getTimestamp() ?: '0'), $url);
4242
}
4343

4444
/**
4545
* @dataProvider getSalesChannelIds
4646
*/
47-
public function testGetUrlGetPatternOnce(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width): void
47+
public function testGetUrlGetPatternOnce(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width, ?\DateTimeInterface $date): void
4848
{
4949
$configReader = $this->createMock(ConfigReader::class);
5050
$configReader->expects(static::once())
51-
->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}');
51+
->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}&updatedAt={mediaUpdatedAt}');
5252

5353
$class = new ThumbnailUrlTemplate($configReader);
5454

55-
$class->getUrl($mediaUrl, $mediaPath, $width);
55+
$class->getUrl($mediaUrl, $mediaPath, $width, $date);
5656

57-
$url = $class->getUrl($mediaUrl, $mediaPath, $width);
57+
$url = $class->getUrl($mediaUrl, $mediaPath, $width, $date);
5858

59-
static::assertSame(\sprintf('%s/%s?width=%s', $mediaUrl, $mediaPath, $width), $url);
59+
static::assertSame(\sprintf('%s/%s?width=%s&updatedAt=%s', $mediaUrl, $mediaPath, $width, $date?->getTimestamp() ?: '0'), $url);
6060
}
6161

6262
/**
6363
* @return iterable<array{string|null, string, string, string}>
6464
*/
6565
public static function getSalesChannelIds(): iterable
6666
{
67-
yield [null, 'https://www.anywebpage.test', 'media/78/a1/myimage.jpg', '200'];
68-
yield [Uuid::randomHex(), 'https://www.anyotherwebpage.test', 'media/aa/a1/myimage.jpg', '300'];
69-
yield [Uuid::randomHex(), 'https://www.anyother2webpage.test', 'media/aa/bb/myimage.jpg', '700'];
70-
yield [Uuid::randomHex(), 'https://www.anyother3webpage.test', 'media/aa/cc/myimage.jpg', '900'];
71-
yield [Uuid::randomHex(), 'https://www.anyother4webpage.test', 'media/aa/dd/myimage.jpg', '1000'];
67+
yield [null, 'https://www.anywebpage.test', 'media/78/a1/myimage.jpg', '200', null];
68+
yield [null, 'https://www.anyotherwebpage.test', 'media/78/a1/myimage.jpg', '200', new \DateTimeImmutable()];
69+
yield [Uuid::randomHex(), 'https://www.anyother2webpage.test', 'media/aa/a1/myimage.jpg', '300', new \DateTimeImmutable()];
70+
yield [Uuid::randomHex(), 'https://www.anyother3webpage.test', 'media/aa/bb/myimage.jpg', '700', null];
71+
yield [Uuid::randomHex(), 'https://www.anyother4webpage.test', 'media/aa/cc/myimage.jpg', '900', new \DateTimeImmutable()];
72+
yield [Uuid::randomHex(), 'https://www.anyother5webpage.test', 'media/aa/dd/myimage.jpg', '1000', null];
7273
}
7374
}

0 commit comments

Comments
 (0)