|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ParseServerMigration\Console\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Monolog\Logger; |
|
6
|
|
|
use Symfony\Component\Console\Command\Command; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @author Maxence Dupressoir <[email protected]> |
|
13
|
|
|
* @copyright 2016 Meetic |
|
14
|
|
|
*/ |
|
15
|
|
|
class MainCommand extends Command |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var Command[] |
|
19
|
|
|
*/ |
|
20
|
|
|
private $commandList; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var Logger |
|
24
|
|
|
*/ |
|
25
|
|
|
private $logger; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param Command[] $commandList |
|
29
|
|
|
* @param Logger $logger |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(array $commandList, Logger $logger) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->commandList = $commandList; |
|
34
|
|
|
$this->logger = $logger; |
|
35
|
|
|
|
|
36
|
|
|
parent::__construct(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
protected function configure() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->setName('parse:migration') |
|
42
|
|
|
->setDescription('Parse server migration tool') |
|
43
|
|
|
; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
47
|
|
|
{ |
|
48
|
|
|
$io = new SymfonyStyle($input, $output); |
|
49
|
|
|
$io->title('Parse server migration tool'); |
|
50
|
|
|
$io->section('Delete command'); |
|
51
|
|
|
$io->text('Delete files from an S3 bucker'); |
|
52
|
|
|
$io->section('Export command'); |
|
53
|
|
|
$io->text('Upload existing parse pictures to S3 bucket and rename file in mongoDB'); |
|
54
|
|
|
$io->section('Migration command'); |
|
55
|
|
|
$io->text('Dump an existing Parse server into a given mongoDB, upload files to S3 and fix files names in order to match Parse self hosted pattern'); |
|
56
|
|
|
|
|
57
|
|
|
$choice = $io->choice('Select which command you want to execute', $this->getCommandsNames()); |
|
58
|
|
|
|
|
59
|
|
|
$command = $this->getCommandByName($choice); |
|
60
|
|
|
|
|
61
|
|
|
$command->execute($input, $output); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return array |
|
66
|
|
|
*/ |
|
67
|
|
|
private function getCommandsNames() |
|
68
|
|
|
{ |
|
69
|
|
|
$names = array(); |
|
70
|
|
|
foreach ($this->commandList as $command) { |
|
71
|
|
|
$names[] = $command->getName(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $names; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param $name |
|
79
|
|
|
* |
|
80
|
|
|
* @return Command |
|
81
|
|
|
*/ |
|
82
|
|
|
private function getCommandByName($name) |
|
83
|
|
|
{ |
|
84
|
|
|
foreach ($this->commandList as $command) { |
|
85
|
|
|
if ($name == $command->getName()) { |
|
86
|
|
|
return $command; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
throw new \InvalidArgumentException('No command found with name: ['.$name.']'); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|