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

Commit f47f8db

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

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
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 }}

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 (\class_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: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
class Shopware6BunnyCdnWriteBatchAdapter extends Shopware6BunnyCdnAdapter implements WriteBatchInterface
11+
{
12+
public function writeBatch(CopyBatchInput|array|Config ...$input): void
13+
{
14+
$files = [];
15+
$config = new Config();
16+
17+
foreach ($input as $data) {
18+
if ($data instanceof CopyBatchInput) {
19+
// migrate CopyBatchInput of Shopware to WriteBatchFile
20+
foreach ($data->getTargetFiles() as $targetFile) {
21+
if (\is_resource($data->getSourceFile())) {
22+
$sourcePath = stream_get_meta_data($data->getSourceFile())['uri'];
23+
$files[] = new WriteBatchFile($sourcePath, $targetFile);
24+
25+
continue;
26+
}
27+
28+
$files[] = new WriteBatchFile($data->getSourceFile(), $targetFile);
29+
}
30+
31+
continue;
32+
}
33+
34+
if ($data instanceof Config) {
35+
$config = $data;
36+
37+
continue;
38+
}
39+
40+
if (\is_array($data)) {
41+
foreach ($data as $item) {
42+
if ($item instanceof WriteBatchFile) {
43+
$files[] = $item;
44+
45+
continue;
46+
}
47+
48+
throw new \InvalidArgumentException('Each value of array must be a WriteBatchFile object.');
49+
}
50+
51+
continue;
52+
}
53+
54+
throw new \InvalidArgumentException('Unsupported input type.');
55+
}
56+
57+
if (empty($files)) {
58+
return;
59+
}
60+
61+
parent::writeBatch($files, $config);
62+
}
63+
}

0 commit comments

Comments
 (0)