|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ParseServerMigration\Console\Command; |
|
4
|
|
|
|
|
5
|
|
|
use ParseServerMigration\Config; |
|
6
|
|
|
use ParseServerMigration\Console\PictureApplicationService; |
|
7
|
|
|
use ParseServerMigration\Console\PictureRepository; |
|
8
|
|
|
use Parse\ParseQuery; |
|
9
|
|
|
use Psr\Log\LoggerInterface; |
|
10
|
|
|
use Symfony\Component\Console\Command\Command; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @author Maxence Dupressoir <[email protected]> |
|
17
|
|
|
* @copyright 2016 Meetic |
|
18
|
|
|
*/ |
|
19
|
|
|
class ExportCommand extends Command |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var PictureRepository |
|
23
|
|
|
*/ |
|
24
|
|
|
private $pictureApplicationService; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var LoggerInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private $logger; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param PictureApplicationService $pictureApplicationService |
|
33
|
|
|
* @param LoggerInterface $logger |
|
34
|
|
|
*/ |
|
35
|
1 |
|
public function __construct(PictureApplicationService $pictureApplicationService, LoggerInterface $logger) |
|
36
|
|
|
{ |
|
37
|
1 |
|
$this->pictureApplicationService = $pictureApplicationService; |
|
|
|
|
|
|
38
|
1 |
|
$this->logger = $logger; |
|
39
|
1 |
|
parent::__construct(); |
|
40
|
1 |
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
protected function configure() |
|
43
|
|
|
{ |
|
44
|
|
|
$this |
|
45
|
1 |
|
->setName('parse:migration:export') |
|
46
|
1 |
|
->setDescription('Upload existing parse pictures to S3 bucket and rename') |
|
47
|
|
|
; |
|
48
|
1 |
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
51
|
|
|
{ |
|
52
|
1 |
|
$io = new SymfonyStyle($input, $output); |
|
53
|
1 |
|
$io->title('Parse migration tool'); |
|
54
|
1 |
|
$io->section('Export command'); |
|
55
|
1 |
|
$io->text('Upload existing parse pictures to S3 bucket and rename file in mongoDB'); |
|
56
|
|
|
|
|
57
|
1 |
|
$limit = $io->ask('Number of picture to export', 1, null); |
|
58
|
1 |
|
$descOrder = $io->confirm('Migrate newer pictures first ?', false); |
|
59
|
|
|
|
|
60
|
|
|
//Because we have 2 steps for each picture |
|
61
|
1 |
|
$io->progressStart($limit * 2); |
|
62
|
1 |
|
$io->newLine(); |
|
63
|
|
|
|
|
64
|
1 |
|
$pictures = $this->pictureApplicationService->retrievePictures($limit, $descOrder); |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
1 |
|
foreach ($pictures as $picture) { |
|
67
|
|
|
try { |
|
68
|
|
|
$io->text('Migrating picture\'s image'); |
|
69
|
|
|
$message = $this->pictureApplicationService->migrateImage($picture); |
|
|
|
|
|
|
70
|
|
|
$io->progressAdvance(1); |
|
71
|
|
|
$io->newLine(); |
|
72
|
|
|
$this->logger->info($message); |
|
73
|
|
|
$io->success($message); |
|
74
|
|
|
|
|
75
|
|
|
$io->text('Migrating picture\'s thumbnail'); |
|
76
|
|
|
$message = $this->pictureApplicationService->migrateThumbnail($picture); |
|
|
|
|
|
|
77
|
|
|
$io->progressAdvance(1); |
|
78
|
|
|
$io->newLine(); |
|
79
|
|
|
$this->logger->info($message); |
|
80
|
|
|
$io->success($message); |
|
81
|
|
|
} catch (\ErrorException $exception) { |
|
82
|
|
|
$message = 'Upload failed for: ['.$picture->get(Config::PARSE_FILES_FIELD_NAME)->getName().'] \nDetail error : ['.$exception->getMessage().']'; |
|
83
|
|
|
|
|
84
|
|
|
$this->logger->error($message); |
|
85
|
|
|
$io->warning($message); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
1 |
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..