1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ps2alerts\Api\Command; |
4
|
|
|
|
5
|
|
|
use Ps2alerts\Api\Command\BaseCommand; |
6
|
|
|
use Ps2alerts\Api\Repository\AlertRepository; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
class DeleteMissingAlertsCommand extends BaseCommand |
12
|
|
|
{ |
13
|
|
|
protected $alertRepo; |
14
|
|
|
protected $alertProcessor; |
15
|
|
|
|
16
|
|
|
protected function configure() |
17
|
|
|
{ |
18
|
|
|
parent::configure(); // See BaseCommand.php |
19
|
|
|
$this |
20
|
|
|
->setName('DeleteMissingAlerts') |
21
|
|
|
->setDescription('Deletes all missing alerts'); |
22
|
|
|
|
23
|
|
|
$this->alertRepo = $this->container->get('Ps2alerts\Api\Repository\AlertRepository'); |
24
|
|
|
$this->alertProcessor = new DeleteAlertCommand(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
28
|
|
|
{ |
29
|
|
|
$query = $this->auraFactory->newSelect(); |
30
|
|
|
$query->from('ws_results'); |
31
|
|
|
$query->cols(['ResultID']); |
32
|
|
|
$query->orderBy(['ResultID DESC']); |
33
|
|
|
|
34
|
|
|
$allQuery = $this->db->prepare($query->getStatement()); |
35
|
|
|
$allQuery->execute($query->getBindValues()); |
36
|
|
|
|
37
|
|
|
$result = $allQuery->fetch(\PDO::FETCH_OBJ); |
38
|
|
|
|
39
|
|
|
$count = 0; |
40
|
|
|
$missing = 0; |
41
|
|
|
$max = $result->ResultID; |
42
|
|
|
|
43
|
|
|
while($count < $max) { |
44
|
|
|
$count++; |
45
|
|
|
|
46
|
|
|
$per = round(($count / $max) * 100, 2); |
47
|
|
|
|
48
|
|
|
$output->writeln("{$count} / {$max} - {$per}%"); |
49
|
|
|
|
50
|
|
|
$pdo = $this->auraFactory->newSelect(); |
51
|
|
|
$pdo->from('ws_results'); |
52
|
|
|
$pdo->cols(['ResultID']); |
53
|
|
|
$pdo->where('ResultID = ?', $count); |
54
|
|
|
|
55
|
|
|
$alertQuery = $this->db->prepare($pdo->getStatement()); |
56
|
|
|
$alertQuery->execute($pdo->getBindValues()); |
57
|
|
|
|
58
|
|
|
$alert = $alertQuery->fetch(\PDO::FETCH_OBJ); |
59
|
|
|
|
60
|
|
|
if (empty($alert)) { |
61
|
|
|
$missing++; |
62
|
|
|
$output->writeln("ALERT #{$count} DOES NOT EXIST!"); |
63
|
|
|
$this->alertProcessor->processAlert($count, $output, true); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$output->writeln("{$missing} missing alerts processed!"); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|