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

Commit b0d0537

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

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/Adapter/Shopware6BunnyCdnAdapter.php

Lines changed: 36 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\WriteBatchInput;
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,35 @@ public function fileExists(string $path): bool
6064

6165
return parent::fileExists($path);
6266
}
67+
68+
public function writeBatch(WriteBatchInput|array|Config ...$input): void
69+
{
70+
$files = [];
71+
$config = null;
72+
73+
foreach ($input as $data) {
74+
// migrate WriteBatchInput of Shopware to WriteBatchFile
75+
if ($data instanceof WriteBatchInput) {
76+
foreach ($data->getTargetFiles() as $targetFile) {
77+
if (\is_resource($data->getSourceFile())) {
78+
$sourceContent = stream_get_contents($data->getSourceFile());
79+
$files[] = new WriteBatchFile($sourceContent, $targetFile);
80+
continue;
81+
}
82+
83+
$files[] = new WriteBatchFile(\file_get_contents($data->getSourceFile()), $targetFile);
84+
}
85+
} elseif ($data instanceof Config) {
86+
$config = $data;
87+
} elseif (\is_array($data)) {
88+
foreach ($data as $item) {
89+
if ($item instanceof WriteBatchFile) {
90+
$files[] = $item;
91+
}
92+
}
93+
}
94+
}
95+
96+
parent::writeBatch($files, $config);
97+
}
6398
}

0 commit comments

Comments
 (0)