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

Commit db240b7

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

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

src/Adapter/Shopware6BunnyCdnAdapter.php

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
namespace Frosh\BunnycdnMediaStorage\Adapter;
44

5+
use League\Flysystem\Config;
56
use League\Flysystem\UnableToDeleteFile;
67
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNAdapter;
8+
use PlatformCommunity\Flysystem\BunnyCDN\WriteBatchFile;
9+
use Shopware\Core\Framework\Adapter\Filesystem\Plugin\CopyBatchInput;
10+
use Shopware\Core\Framework\Adapter\Filesystem\Plugin\WriteBatchInterface;
711

8-
class Shopware6BunnyCdnAdapter extends BunnyCDNAdapter
12+
class Shopware6BunnyCdnAdapter extends BunnyCDNAdapter implements WriteBatchInterface
913
{
1014
private readonly bool $neverDelete;
1115

@@ -60,4 +64,56 @@ public function fileExists(string $path): bool
6064

6165
return parent::fileExists($path);
6266
}
67+
68+
public function writeBatch(CopyBatchInput|array|Config ...$input): void
69+
{
70+
$files = [];
71+
$config = new Config();
72+
73+
foreach ($input as $data) {
74+
if ($data instanceof CopyBatchInput) {
75+
// migrate CopyBatchInput of Shopware to WriteBatchFile
76+
foreach ($data->getTargetFiles() as $targetFile) {
77+
if (\is_resource($data->getSourceFile())) {
78+
$sourcePath = stream_get_meta_data($data->getSourceFile())['uri'];
79+
$files[] = new WriteBatchFile($sourcePath, $targetFile);
80+
81+
continue;
82+
}
83+
84+
$files[] = new WriteBatchFile($data->getSourceFile(), $targetFile);
85+
}
86+
87+
continue;
88+
}
89+
90+
if ($data instanceof Config) {
91+
$config = $data;
92+
93+
continue;
94+
}
95+
96+
if (\is_array($data)) {
97+
foreach ($data as $item) {
98+
if ($item instanceof WriteBatchFile) {
99+
$files[] = $item;
100+
101+
continue;
102+
}
103+
104+
throw new \InvalidArgumentException('Each value of array must be a WriteBatchFile object.');
105+
}
106+
107+
continue;
108+
}
109+
110+
throw new \InvalidArgumentException('Unsupported input type.');
111+
}
112+
113+
if (empty($files)) {
114+
return;
115+
}
116+
117+
parent::writeBatch($files, $config);
118+
}
63119
}

0 commit comments

Comments
 (0)