matecat /
simple-s3
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the Simple S3 package. |
||
| 4 | * |
||
| 5 | * (c) Mauro Cassani<https://github.com/mauretto78> |
||
| 6 | * |
||
| 7 | * For the full copyright and license information, please view the LICENSE |
||
| 8 | * file that was distributed with this source code. |
||
| 9 | * |
||
| 10 | */ |
||
| 11 | |||
| 12 | namespace Matecat\SimpleS3\Commands\Handlers; |
||
| 13 | |||
| 14 | use Exception; |
||
| 15 | use Matecat\SimpleS3\Commands\CommandHandler; |
||
| 16 | use Matecat\SimpleS3\Helpers\File; |
||
| 17 | |||
| 18 | class DeleteFolder extends CommandHandler |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Delete a folder. |
||
| 22 | * For a complete reference: |
||
| 23 | * https://docs.aws.amazon.com/cli/latest/reference/s3api/delete-object.html |
||
| 24 | * |
||
| 25 | * @param array $params |
||
| 26 | * |
||
| 27 | * @return true |
||
| 28 | * @throws Exception |
||
| 29 | */ |
||
| 30 | 1 | public function handle(array $params = []): true |
|
|
0 ignored issues
–
show
|
|||
| 31 | { |
||
| 32 | 1 | $bucketName = $params[ 'bucket' ]; |
|
| 33 | 1 | $prefix = $params[ 'prefix' ]; |
|
| 34 | |||
| 35 | 1 | if (false === File::endsWith($prefix, $this->client->getPrefixSeparator())) { |
|
| 36 | 1 | $prefix .= $this->client->getPrefixSeparator(); |
|
| 37 | } |
||
| 38 | |||
| 39 | try { |
||
| 40 | 1 | $this->client->getConn()->deleteMatchingObjects($bucketName, $prefix); |
|
| 41 | 1 | $this->commandHandlerLogger?->log($this, sprintf('Folder \'%s\' was successfully deleted from \'%s\' bucket', $prefix, $bucketName)); |
|
| 42 | |||
| 43 | 1 | if ($this->client->hasCache()) { |
|
| 44 | 1 | $items = $this->client->getItemsInABucket([ |
|
| 45 | 1 | 'bucket' => $bucketName, |
|
| 46 | 1 | 'prefix' => $prefix, |
|
| 47 | 1 | ]); |
|
| 48 | |||
| 49 | 1 | foreach ($items as $key) { |
|
| 50 | 1 | $this->client->getCache()->remove($bucketName, $key); |
|
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | 1 | return true; |
|
|
0 ignored issues
–
show
|
|||
| 55 | } catch (Exception $e) { |
||
| 56 | $this->commandHandlerLogger?->logExceptionAndReturnFalse($e); |
||
| 57 | |||
| 58 | throw $e; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @param array $params |
||
| 64 | * |
||
| 65 | * @return bool |
||
| 66 | */ |
||
| 67 | 1 | public function validateParams(array $params = []): bool |
|
| 68 | { |
||
| 69 | 1 | return ( |
|
| 70 | 1 | isset($params[ 'bucket' ]) and |
|
| 71 | 1 | isset($params[ 'prefix' ]) |
|
| 72 | 1 | ); |
|
| 73 | } |
||
| 74 | } |
||
| 75 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths