|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ParseServerMigration\Console\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Aws\S3\Exception\S3Exception; |
|
6
|
|
|
use Monolog\Logger; |
|
7
|
|
|
use ParseServerMigration\Config; |
|
8
|
|
|
use ParseServerMigration\Console\PictureRepository; |
|
9
|
|
|
use Parse\ParseQuery; |
|
10
|
|
|
use Symfony\Component\Console\Command\Command; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author Maxence Dupressoir <[email protected]> |
|
18
|
|
|
* @copyright 2016 Meetic |
|
19
|
|
|
*/ |
|
20
|
|
|
class DeleteCommand extends Command |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var PictureRepository |
|
24
|
|
|
*/ |
|
25
|
|
|
private $pictureRepository; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var Logger |
|
29
|
|
|
*/ |
|
30
|
|
|
private $logger; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param PictureRepository $pictureRepository |
|
34
|
|
|
* @param Logger $logger |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(PictureRepository $pictureRepository, Logger $logger) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->pictureRepository = $pictureRepository; |
|
39
|
|
|
$this->logger = $logger; |
|
40
|
|
|
|
|
41
|
|
|
parent::__construct(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function configure() |
|
45
|
|
|
{ |
|
46
|
|
|
$this |
|
47
|
|
|
->setName('parse:migration:delete') |
|
48
|
|
|
->setDescription('Delete pictures from S3') |
|
49
|
|
|
->addArgument( |
|
50
|
|
|
'number', |
|
51
|
|
|
InputArgument::REQUIRED, |
|
52
|
|
|
'Number of picture to delete' |
|
53
|
|
|
) |
|
54
|
|
|
; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
58
|
|
|
{ |
|
59
|
|
|
$number = $input->getArgument('number'); |
|
60
|
|
|
$query = new ParseQuery('Photos'); |
|
61
|
|
|
$query->limit($number); |
|
62
|
|
|
$results = $query->find(); |
|
63
|
|
|
|
|
64
|
|
|
$io = new SymfonyStyle($input, $output); |
|
65
|
|
|
|
|
66
|
|
|
foreach ($results as $picture) { |
|
67
|
|
|
try { |
|
68
|
|
|
$deleteResult = $this->pictureRepository->deletePicture($picture); |
|
69
|
|
|
|
|
70
|
|
|
$message = 'Export success for: ['.$picture->get(Config::PARSE_FILES_FIELD_NAME)->getName().'] Uploaded to : ['.$deleteResult['ObjectURL'].']'; |
|
71
|
|
|
$this->logger->info($message); |
|
72
|
|
|
$io->success($message); |
|
73
|
|
|
} catch (S3Exception $exception) { |
|
74
|
|
|
$message = 'Delete failed for: ['.$picture->get(Config::PARSE_FILES_FIELD_NAME)->getName().'] \nDetail error : ['.$exception->getMessage().']'; |
|
75
|
|
|
|
|
76
|
|
|
$io->error($message); |
|
77
|
|
|
$this->logger->error($message); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|