|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace SetBased\Audit\Command; |
|
5
|
|
|
|
|
6
|
|
|
use SetBased\Audit\Audit\Audit; |
|
7
|
|
|
use SetBased\Audit\MySql\AuditDataLayer; |
|
8
|
|
|
use SetBased\Audit\Style\AuditStyle; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Command for creating audit tables and audit triggers. |
|
15
|
|
|
*/ |
|
16
|
|
|
class AuditCommand extends BaseCommand |
|
17
|
|
|
{ |
|
18
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
19
|
|
|
/** |
|
20
|
|
|
* @inheritdoc |
|
21
|
|
|
*/ |
|
22
|
31 |
|
protected function configure() |
|
23
|
|
|
{ |
|
24
|
31 |
|
$this->setName('audit') |
|
25
|
31 |
|
->setDescription('Maintains audit tables and audit triggers') |
|
26
|
31 |
|
->setHelp("Maintains audit tables and audit triggers:\n". |
|
27
|
|
|
"- creates new audit tables\n". |
|
28
|
|
|
"- adds new columns to exiting audit tables\n". |
|
29
|
31 |
|
"- creates new and recreates existing audit triggers\n") |
|
30
|
31 |
|
->addArgument('config file', InputArgument::REQUIRED, 'The audit configuration file'); |
|
31
|
31 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
34
|
|
|
/** |
|
35
|
|
|
* @inheritdoc |
|
36
|
|
|
*/ |
|
37
|
31 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
38
|
|
|
{ |
|
39
|
31 |
|
$this->io = new AuditStyle($input, $output); |
|
40
|
|
|
|
|
41
|
31 |
|
$this->configFileName = $input->getArgument('config file'); |
|
42
|
31 |
|
$this->readConfigFile(); |
|
43
|
|
|
|
|
44
|
31 |
|
$this->connect(); |
|
45
|
|
|
|
|
46
|
31 |
|
$audit = new Audit($this->config, $this->io); |
|
47
|
31 |
|
$audit->main(); |
|
48
|
|
|
|
|
49
|
31 |
|
AuditDataLayer::$dl->disconnect(); |
|
50
|
|
|
|
|
51
|
31 |
|
$this->rewriteConfig(); |
|
52
|
|
|
|
|
53
|
31 |
|
return 0; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
60
|
|
|
|