|
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,56 @@ 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 = 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 | + } |
63 | 119 | } |
0 commit comments