|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace SetBased\Audit\Command; |
|
5
|
|
|
|
|
6
|
|
|
use SetBased\Audit\MySql\AuditDataLayer; |
|
7
|
|
|
use SetBased\Audit\Style\AuditStyle; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Command for dropping all triggers. |
|
14
|
|
|
*/ |
|
15
|
|
|
class DropTriggersCommand extends AuditCommand |
|
16
|
|
|
{ |
|
17
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
18
|
|
|
/** |
|
19
|
|
|
* @inheritdoc |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function configure() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->setName('drop-triggers') |
|
24
|
|
|
->setDescription('Drops all triggers') |
|
25
|
|
|
->setHelp('Drops all triggers (including triggers not created by audit) from all tables (including tables '. |
|
26
|
|
|
'excluded for auditing) in the data schema.') |
|
27
|
|
|
->addArgument('config file', InputArgument::REQUIRED, 'The audit configuration file'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
31
|
|
|
/** |
|
32
|
|
|
* @inheritdoc |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
35
|
|
|
{ |
|
36
|
|
|
$this->io = new AuditStyle($input, $output); |
|
37
|
|
|
|
|
38
|
|
|
$this->configFileName = $input->getArgument('config file'); |
|
39
|
|
|
$this->readConfigFile(); |
|
40
|
|
|
|
|
41
|
|
|
$this->connect(); |
|
42
|
|
|
|
|
43
|
|
|
$this->dropTriggers(); |
|
44
|
|
|
|
|
45
|
|
|
AuditDataLayer::$dl->disconnect(); |
|
46
|
|
|
|
|
47
|
|
|
$this->rewriteConfig(); |
|
48
|
|
|
|
|
49
|
|
|
return 0; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
53
|
|
|
/** |
|
54
|
|
|
* Drops all triggers. |
|
55
|
|
|
*/ |
|
56
|
|
|
private function dropTriggers(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$dataSchema = $this->config->getManString('database.data_schema'); |
|
59
|
|
|
$triggers = AuditDataLayer::$dl->getTriggers($dataSchema); |
|
60
|
|
|
foreach ($triggers as $trigger) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->io->logInfo('Dropping trigger <dbo>%s</dbo> from table <dbo>%s</dbo>', |
|
63
|
|
|
$trigger['trigger_name'], |
|
64
|
|
|
$trigger['table_name']); |
|
65
|
|
|
|
|
66
|
|
|
AuditDataLayer::$dl->dropTrigger($dataSchema, $trigger['trigger_name']); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
74
|
|
|
|