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 FolderCopyCommand 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 |
|
|
|
|
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:folder:copy') |
36
|
|
|
->setDescription('Copy the items from a folder to another one.') |
37
|
|
|
->setHelp('This command allows you to copy items from a folder to another one.') |
38
|
|
|
->addArgument('source_bucket', InputArgument::REQUIRED, 'The source bucket') |
39
|
|
|
->addArgument('source_folder', InputArgument::REQUIRED, 'The source folder') |
40
|
|
|
->addArgument('target_bucket', InputArgument::REQUIRED, 'The target bucket') |
41
|
|
|
->addArgument('target_folder', InputArgument::REQUIRED, 'The target folder') |
42
|
|
|
; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
46
|
|
|
{ |
47
|
|
|
$sourceBucket = $input->getArgument('source_bucket'); |
48
|
|
|
$sourceFolder = $input->getArgument('source_folder'); |
49
|
|
|
$targetBucket = $input->getArgument('target_bucket'); |
50
|
|
|
$targetFolder = $input->getArgument('target_folder'); |
51
|
|
|
$io = new SymfonyStyle($input, $output); |
52
|
|
|
|
53
|
|
|
try { |
54
|
|
|
if (true === $this->s3Client->copyFolder([ |
55
|
|
|
'source_bucket' => $sourceBucket, |
56
|
|
|
'source_folder' => $sourceFolder, |
57
|
|
|
'target_bucket' => $targetBucket, |
58
|
|
|
'target_folder' => $targetFolder, |
59
|
|
|
])) { |
60
|
|
|
$io->success('The items were successfully copied'); |
61
|
|
|
} else { |
62
|
|
|
$io->error('There was an error during copying the items'); |
63
|
|
|
} |
64
|
|
|
} catch (\Exception $e) { |
65
|
|
|
$io->error($e->getMessage()); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|