|
1
|
|
|
<?php |
|
2
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
3
|
|
|
namespace SetBased\Audit\MySql\Command; |
|
4
|
|
|
|
|
5
|
|
|
use SetBased\Audit\MySql\Audit; |
|
6
|
|
|
use SetBased\Audit\MySql\AuditDataLayer; |
|
7
|
|
|
use SetBased\Stratum\Style\StratumStyle; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
|
|
12
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
13
|
|
|
/** |
|
14
|
|
|
* Command for creating audit tables and audit triggers. |
|
15
|
|
|
*/ |
|
16
|
|
|
class AuditCommand extends MySqlBaseCommand |
|
17
|
|
|
{ |
|
18
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
19
|
|
|
/** |
|
20
|
|
|
* {@inheritdoc} |
|
21
|
|
|
*/ |
|
22
|
10 |
|
protected function configure() |
|
23
|
|
|
{ |
|
24
|
10 |
|
$this->setName('audit') |
|
25
|
10 |
|
->setDescription('Create (missing) audit table and (re)creates audit triggers') |
|
26
|
10 |
|
->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file'); |
|
27
|
10 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
9 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
34
|
|
|
{ |
|
35
|
9 |
|
$this->io = new StratumStyle($input, $output); |
|
36
|
|
|
|
|
37
|
9 |
|
$this->configFileName = $input->getArgument('config file'); |
|
38
|
9 |
|
$this->readConfigFile(); |
|
39
|
|
|
|
|
40
|
|
|
// Create database connection with params from config file |
|
41
|
9 |
|
$this->connect($this->config); |
|
42
|
|
|
|
|
43
|
9 |
|
$audit = new Audit($this->config, $this->io); |
|
44
|
9 |
|
$audit->main(); |
|
45
|
|
|
|
|
46
|
|
|
// Drop database connection |
|
47
|
9 |
|
AuditDataLayer::disconnect(); |
|
48
|
|
|
|
|
49
|
9 |
|
$this->rewriteConfig(); |
|
50
|
9 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
56
|
|
|
|