|
2 | 2 |
|
3 | 3 | namespace Frosh\BunnycdnMediaStorage\Adapter; |
4 | 4 |
|
| 5 | +use League\Flysystem\Config; |
5 | 6 | use League\Flysystem\UnableToDeleteFile; |
6 | 7 | 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; |
7 | 11 |
|
8 | | -class Shopware6BunnyCdnAdapter extends BunnyCDNAdapter |
| 12 | +class Shopware6BunnyCdnAdapter extends BunnyCDNAdapter implements WriteBatchInterface |
9 | 13 | { |
10 | 14 | private readonly bool $neverDelete; |
11 | 15 |
|
@@ -60,4 +64,35 @@ public function fileExists(string $path): bool |
60 | 64 |
|
61 | 65 | return parent::fileExists($path); |
62 | 66 | } |
| 67 | + |
| 68 | + public function writeBatch(CopyBatchInput|array|Config ...$input): void |
| 69 | + { |
| 70 | + $files = []; |
| 71 | + $config = null; |
| 72 | + |
| 73 | + foreach ($input as $data) { |
| 74 | + // migrate CopyBatchInput of Shopware to WriteBatchFile |
| 75 | + if ($data instanceof CopyBatchInput) { |
| 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 | + } |
63 | 98 | } |
0 commit comments