Completed
Push — master ( 744b49...fa00f5 )
by P.R.
04:15
created

DropTriggersCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
//----------------------------------------------------------------------------------------------------------------------
3
namespace SetBased\Audit\MySql\Command;
4
5
use SetBased\Audit\MySql\AuditDataLayer;
6
use SetBased\Stratum\Style\StratumStyle;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
//----------------------------------------------------------------------------------------------------------------------
12
/**
13
 * Command for dropping all triggers.
14
 */
15
class DropTriggersCommand extends MySqlBaseCommand
16
{
17
  //--------------------------------------------------------------------------------------------------------------------
18
  /**
19
   * {@inheritdoc}
20
   */
21 1
  protected function configure()
22
  {
23 1
    $this->setName('drop-triggers')
24 1
         ->setDescription('Drops all triggers')
25 1
         ->addArgument('config file', InputArgument::REQUIRED, 'The audit configuration file');
26 1
  }
27
28
  //--------------------------------------------------------------------------------------------------------------------
29
  /**
30
   * {@inheritdoc}
31
   */
32
  protected function execute(InputInterface $input, OutputInterface $output)
33
  {
34
    $this->io = new StratumStyle($input, $output);
35
36
    $this->configFileName = $input->getArgument('config file');
37
    $this->readConfigFile();
38
39
    // Create database connection with params from config file
40
    $this->connect($this->config);
41
42
    $this->dropTriggers();
43
44
    // Drop database connection
45
    AuditDataLayer::disconnect();
46
47
    $this->rewriteConfig();
48
  }
49
50
  //--------------------------------------------------------------------------------------------------------------------
51
  /**
52
   * Drops all triggers.
53
   */
54
  private function dropTriggers()
55
  {
56
    $data_schema = $this->config['database']['data_schema'];
57
    $triggers = AuditDataLayer::getTriggers($data_schema);
58
    foreach ($triggers as $trigger)
59
    {
60
      $this->io->logInfo('Dropping trigger <dbo>%s</dbo> from table <dbo>%s</dbo>',
61
                         $trigger['trigger_name'],
62
                         $trigger['table_name']);
63
64
      AuditDataLayer::dropTrigger($data_schema, $trigger['trigger_name']);
65
    }
66
  }
67
68
  //--------------------------------------------------------------------------------------------------------------------
69
}
70
71
//----------------------------------------------------------------------------------------------------------------------
72