Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Commit c18b6fb

Browse files
committed
feat: add support for writeBatch
1 parent c4a8bf2 commit c18b6fb

File tree

7 files changed

+105
-4
lines changed

7 files changed

+105
-4
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
"v6.5.8.2",
2626
"6.5.x",
2727
"v6.6.0.3",
28+
"v6.6.8.1",
2829
"trunk"
2930
]
3031
php: ["8.2"]
@@ -70,4 +71,4 @@ jobs:
7071
with:
7172
files: ./clover.xml
7273
root_dir: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }}
73-
working-directory: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }}
74+
working-directory: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }}

CHANGELOG_en-GB.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 3.4.0
2+
3+
* Feat: (for Shopware >= 6.6.8.0) Add support for writeBatch.
4+
With this you can use storage for theme and asset with more speed. Instead of 2,5 hours it now takes 30 seconds for assets on storage with SSD with demo shop.
5+
16
# 3.3.3
27

38
* Fix: correct config message for Shopware >6.6.3.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ https://github.com/FriendsOfShopware/FroshPlatformBunnycdnMediaStorage/releases/
6767
6868
## Recommendations and warnings
6969
70-
- Don't store theme or asset files on external storage if possible. Due to some improvements in shopware with 6.5 and 6.6 there are created many files. This is the reason why this would slow down theme compilation and asset installation significantly.
70+
- Before Shopware 6.6.8.0 and plugin version 3.4.0: Don't store theme or asset files on external storage. Due to some improvements in shopware with 6.5 and 6.6 there are created many files. This is the reason why this would slow down theme compilation and asset installation significantly.
7171
- Utilize storage zones with SSDs as they are significantly faster than standard option (means HDDs), with up to 80x faster upload speeds in our tests.
7272
7373
## Suggestions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"require": {
2222
"shopware/core": "~6.5.3||~6.6.0",
23-
"platformcommunity/flysystem-bunnycdn": "^3.3.4",
23+
"platformcommunity/flysystem-bunnycdn": "^3.3.5",
2424
"league/flysystem-path-prefixing": "^3.10.3",
2525
"ajgl/flysystem-replicate": "^2.2",
2626
"tinect/flysystem-garbage": "^1.0"

src/Adapter/BunnyCdnFactory.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use League\Flysystem\Local\LocalFilesystemAdapter;
88
use League\Flysystem\PathPrefixing\PathPrefixedAdapter;
99
use Shopware\Core\Framework\Adapter\Filesystem\Adapter\AdapterFactoryInterface;
10+
use Shopware\Core\Framework\Adapter\Filesystem\Plugin\WriteBatchInterface;
1011
use Tinect\Flysystem\Garbage\GarbageFilesystemAdapter;
1112

1213
class BunnyCdnFactory implements AdapterFactoryInterface
@@ -19,7 +20,7 @@ public function create(array $config): FilesystemAdapter
1920
$adapterConfig = new AdapterConfig();
2021
$adapterConfig->assign($config);
2122

22-
$adapter = new Shopware6BunnyCdnAdapter($adapterConfig);
23+
$adapter = $this->getBasicAdapter($adapterConfig);
2324

2425
if (!empty($adapterConfig->isUseGarbage())) {
2526
$adapter = new GarbageFilesystemAdapter($adapter);
@@ -36,6 +37,15 @@ public function create(array $config): FilesystemAdapter
3637
return $adapter;
3738
}
3839

40+
private function getBasicAdapter(AdapterConfig $adapterConfig): FilesystemAdapter
41+
{
42+
if (\interface_exists(WriteBatchInterface::class)) {
43+
return new Shopware6BunnyCdnWriteBatchAdapter($adapterConfig);
44+
}
45+
46+
return new Shopware6BunnyCdnAdapter($adapterConfig);
47+
}
48+
3949
public function getType(): string
4050
{
4151
return 'bunnycdn';
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Frosh\BunnycdnMediaStorage\Adapter;
4+
5+
use League\Flysystem\Config;
6+
use PlatformCommunity\Flysystem\BunnyCDN\WriteBatchFile;
7+
use Shopware\Core\Framework\Adapter\Filesystem\Plugin\CopyBatchInput;
8+
use Shopware\Core\Framework\Adapter\Filesystem\Plugin\WriteBatchInterface;
9+
10+
if (!\interface_exists(WriteBatchInterface::class)) {
11+
class Shopware6BunnyCdnWriteBatchAdapter extends Shopware6BunnyCdnAdapter
12+
{}
13+
} else {
14+
class Shopware6BunnyCdnWriteBatchAdapter extends Shopware6BunnyCdnAdapter implements WriteBatchInterface
15+
{
16+
public function writeBatch(CopyBatchInput|array|Config ...$input): void
17+
{
18+
$files = [];
19+
$config = new Config();
20+
21+
foreach ($input as $data) {
22+
if ($data instanceof CopyBatchInput) {
23+
// migrate CopyBatchInput of Shopware to WriteBatchFile
24+
foreach ($data->getTargetFiles() as $targetFile) {
25+
$sourceFile = $data->getSourceFile();
26+
27+
if (\is_string($sourceFile)) {
28+
$files[] = new WriteBatchFile($sourceFile, $targetFile);
29+
30+
continue;
31+
}
32+
33+
$metaData = stream_get_meta_data($sourceFile);
34+
if (empty($metaData['uri'])) {
35+
throw new \InvalidArgumentException('Cannot get source file path from stream.');
36+
}
37+
38+
$sourcePath = $metaData['uri'];
39+
40+
$files[] = new WriteBatchFile($sourcePath, $targetFile);
41+
}
42+
43+
continue;
44+
}
45+
46+
if ($data instanceof Config) {
47+
$config = $data;
48+
49+
continue;
50+
}
51+
52+
if (\is_array($data)) {
53+
foreach ($data as $item) {
54+
if (!$item instanceof WriteBatchFile) {
55+
throw new \InvalidArgumentException('Each value of array must be a WriteBatchFile object.');
56+
}
57+
58+
$files[] = $item;
59+
}
60+
}
61+
}
62+
63+
if (empty($files)) {
64+
return;
65+
}
66+
67+
parent::writeBatch($files, $config);
68+
}
69+
}
70+
}

tests/unit/Adapter/BunnyCdnFactoryTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
use Ajgl\Flysystem\Replicate\ReplicateFilesystemAdapter;
66
use Frosh\BunnycdnMediaStorage\Adapter\BunnyCdnFactory;
77
use Frosh\BunnycdnMediaStorage\Adapter\Shopware6BunnyCdnAdapter;
8+
use Frosh\BunnycdnMediaStorage\Adapter\Shopware6BunnyCdnWriteBatchAdapter;
89
use League\Flysystem\PathPrefixing\PathPrefixedAdapter;
910
use PHPUnit\Framework\TestCase;
11+
use Shopware\Core\Framework\Adapter\Filesystem\Plugin\WriteBatchInterface;
1012
use Tinect\Flysystem\Garbage\GarbageFilesystemAdapter;
1113

1214
class BunnyCdnFactoryTest extends TestCase
@@ -47,6 +49,19 @@ public function testFactoryCreatesReplicateFilesystemAdapter(): void
4749
static::assertInstanceOf(ReplicateFilesystemAdapter::class, $adapter);
4850
}
4951

52+
public function testFactoryCreatesWriteBatchAdapter(): void
53+
{
54+
if (!\interface_exists(WriteBatchInterface::class)) {
55+
static::markTestSkipped('WriteBatchInterface not found');
56+
}
57+
58+
$factory = new BunnyCdnFactory();
59+
$config = ['endpoint' => 'https://storage.bunnycdn.com', 'apiKey' => 'a', 'storageName' => 'a', 'useGarbage' => false];
60+
$adapter = $factory->create($config);
61+
62+
static::assertInstanceOf(WriteBatchInterface::class, $adapter);
63+
}
64+
5065
public function testFactoryReturnsBunnycdnType(): void
5166
{
5267
$factory = new BunnyCdnFactory();

0 commit comments

Comments
 (0)