Skip to content

Commit

Permalink
Add support to delete files in S3 / object storage through the `php b…
Browse files Browse the repository at this point in the history
…in/console database:drop` command, closes #309.
  • Loading branch information
Syndesi committed Jul 24, 2024
1 parent e819932 commit 46978d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Added
- Add S3 status check to healthcheck command, closes #200.
- Add support to delete files in S3 / object storage through the `php bin/console database:drop` command, closes #309.
### Changed
- Update versions of Neo4j used inside the CI, closes #326.
- Increase max post limit from 2 MB (PHP default) to 100 MB, related to #119.
Expand Down
30 changes: 27 additions & 3 deletions src/Command/DatabaseDropCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use App\Style\EmberNexusStyle;
use App\Type\RabbitMQQueueType;
use AsyncAws\S3\S3Client;
use EmberNexusBundle\Service\EmberNexusConfiguration;
use Laudis\Neo4j\Databags\Statement;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use Predis\Client;
Expand Down Expand Up @@ -33,7 +35,9 @@ public function __construct(
private MongoEntityManager $mongoEntityManager,
private ElasticEntityManager $elasticEntityManager,
private Client $redisClient,
private AMQPStreamConnection $AMQPStreamConnection
private AMQPStreamConnection $AMQPStreamConnection,
private S3Client $s3Client,
private EmberNexusConfiguration $emberNexusConfiguration
) {
parent::__construct();
}
Expand Down Expand Up @@ -110,8 +114,28 @@ private function deleteMongo(): void
private function deleteObjectStorage(): void
{
$this->io->startSection('Task 3 of 6: Object Storage');
$this->io->writeln('Deleting object storage data...');
$this->io->stopSection('Object storage is currently not implemented, nothing to delete.');
$this->io->writeln('Deleting Object data...');
do {
$objects = $this->s3Client->listObjectsV2([
'Bucket' => $this->emberNexusConfiguration->getFileS3StorageBucket(),
]);
$keyCount = $objects->getKeyCount();
if ($keyCount > 0) {
$objectsToBeDeleted = [];
foreach ($objects->getContents() as $object) {
$objectsToBeDeleted[] = [
'Key' => $object->getKey(),
];
}
$this->s3Client->deleteObjects([
'Bucket' => $this->emberNexusConfiguration->getFileS3StorageBucket(),
'Delete' => [
'Objects' => $objectsToBeDeleted,
],
]);
}
} while ($keyCount > 0);
$this->io->stopSection('Successfully deleted object storage.');
}

private function deleteElastic(): void
Expand Down

0 comments on commit 46978d5

Please sign in to comment.