|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of byrokrat\giroapp. |
|
5
|
|
|
* |
|
6
|
|
|
* byrokrat\giroapp is free software: you can redistribute it and/or |
|
7
|
|
|
* modify it under the terms of the GNU General Public License as published |
|
8
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* byrokrat\giroapp is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU General Public License |
|
17
|
|
|
* along with byrokrat\giroapp. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
* |
|
19
|
|
|
* Copyright 2016-21 Hannes Forsgård |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
declare(strict_types=1); |
|
23
|
|
|
|
|
24
|
|
|
namespace byrokrat\giroapp\Console; |
|
25
|
|
|
|
|
26
|
|
|
use byrokrat\giroapp\DependencyInjection; |
|
27
|
|
|
use byrokrat\giroapp\Domain\State\AwaitingResponseStateInterface; |
|
28
|
|
|
use byrokrat\giroapp\Domain\State\Active; |
|
29
|
|
|
use byrokrat\giroapp\Domain\State\Error; |
|
30
|
|
|
use byrokrat\giroapp\Domain\State\ExportableStateInterface; |
|
31
|
|
|
use byrokrat\giroapp\Domain\State\Revoked; |
|
32
|
|
|
use byrokrat\giroapp\Domain\State\Paused; |
|
33
|
|
|
use byrokrat\giroapp\Status\StatisticsManager; |
|
34
|
|
|
use Money\Money; |
|
35
|
|
|
use Money\MoneyFormatter; |
|
36
|
|
|
use Symfony\Component\Console\Command\Command; |
|
37
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
38
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
39
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Command to display database status |
|
43
|
|
|
*/ |
|
44
|
|
|
final class StatusConsole implements ConsoleInterface |
|
45
|
|
|
{ |
|
46
|
|
|
use DependencyInjection\DonorQueryProperty; |
|
47
|
|
|
use DependencyInjection\MoneyFormatterProperty; |
|
48
|
|
|
|
|
49
|
|
|
/** @var StatisticsManager */ |
|
50
|
|
|
private $statisticsManager; |
|
51
|
|
|
|
|
52
|
|
|
public function __construct(StatisticsManager $statisticsManager) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->statisticsManager = $statisticsManager; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function configure(Command $command): void |
|
58
|
|
|
{ |
|
59
|
|
|
$command |
|
60
|
|
|
->setName('status') |
|
61
|
|
|
->setDescription('Show current status') |
|
62
|
|
|
->setHelp('Examine the status of the giroapp database') |
|
63
|
|
|
->addOption( |
|
64
|
|
|
'show', |
|
65
|
|
|
null, |
|
66
|
|
|
InputOption::VALUE_REQUIRED, |
|
67
|
|
|
'Show only named statistic (possible values include donor-count, ' |
|
68
|
|
|
. 'monthly-amount, exportable-count, waiting-count, error-count, revoked-count and paused-count)' |
|
69
|
|
|
) |
|
70
|
|
|
->addOption('all', 'a', InputOption::VALUE_NONE, 'Show all statistics, including 0 values') |
|
71
|
|
|
; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function execute(InputInterface $input, OutputInterface $output): void |
|
75
|
|
|
{ |
|
76
|
|
|
/** @var string */ |
|
77
|
|
|
$showOnly = $input->getOption('show'); |
|
78
|
|
|
|
|
79
|
|
|
if ($showOnly) { |
|
80
|
|
|
$output->writeln((string)$this->statisticsManager->getStatistic($showOnly)->getValue()); |
|
81
|
|
|
return; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
foreach ($this->statisticsManager->getAllStatistics() as $statistic) { |
|
85
|
|
|
if ($statistic->getValue() == 0 && !$input->getOption('all')) { |
|
86
|
|
|
continue; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$output->writeln("{$statistic->getDescription()}: <comment>{$statistic->getValue()}</comment>"); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|