1 | <?php |
||
2 | |||
3 | namespace Matecat\SimpleS3\Console; |
||
4 | |||
5 | use Matecat\SimpleS3\Client; |
||
6 | use Symfony\Component\Console\Command\Command; |
||
7 | use Symfony\Component\Console\Input\InputArgument; |
||
8 | use Symfony\Component\Console\Input\InputInterface; |
||
9 | use Symfony\Component\Console\Output\OutputInterface; |
||
10 | use Symfony\Component\Console\Style\SymfonyStyle; |
||
11 | |||
12 | class BucketClearCommand extends Command |
||
13 | { |
||
14 | /** |
||
15 | * @var Client |
||
16 | */ |
||
17 | private $s3Client; |
||
18 | |||
19 | /** |
||
20 | * CacheFlushCommand constructor. |
||
21 | * |
||
22 | * @param Client $s3Client |
||
23 | * @param null $name |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
24 | */ |
||
25 | public function __construct(Client $s3Client, $name = null) |
||
26 | { |
||
27 | parent::__construct($name); |
||
28 | |||
29 | $this->s3Client = $s3Client; |
||
30 | } |
||
31 | |||
32 | protected function configure() |
||
33 | { |
||
34 | $this |
||
35 | ->setName('ss3:bucket:clear') |
||
36 | ->setDescription('Clears a bucket.') |
||
37 | ->setHelp('This command clears a bucket on S3.') |
||
38 | ->addArgument('bucket', InputArgument::REQUIRED, 'The name of the bucket') |
||
39 | ; |
||
40 | } |
||
41 | |||
42 | protected function execute(InputInterface $input, OutputInterface $output) |
||
43 | { |
||
44 | $bucket = $input->getArgument('bucket'); |
||
45 | $io = new SymfonyStyle($input, $output); |
||
46 | |||
47 | try { |
||
48 | if (true === $this->s3Client->clearBucket(['bucket' => $bucket])) { |
||
49 | $io->success('The bucket was successfully cleared'); |
||
50 | } else { |
||
51 | $io->error('There was an error in clearing bucket'); |
||
52 | } |
||
53 | } catch (\Exception $e) { |
||
54 | $io->error($e->getMessage()); |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 |