Completed
Push — master ( 08e0f6...9db3f2 )
by P.R.
15:16
created

DiffCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 5
Bugs 1 Features 0
Metric Value
c 5
b 1
f 0
dl 0
loc 12
ccs 0
cts 8
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 2
crap 2
1
<?php
2
//----------------------------------------------------------------------------------------------------------------------
3
namespace SetBased\Audit\MySql\Command;
4
5
use SetBased\Audit\MySql\AuditDiff;
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\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
//----------------------------------------------------------------------------------------------------------------------
14
/**
15
 * Command for comparing data tables with audit tables.
16
 */
17
class DiffCommand extends AuditCommand
18
{
19
  //--------------------------------------------------------------------------------------------------------------------
20
  /**
21
   * The names of all tables in audit schema.
22
   *
23
   * @var array
24
   */
25
  private $auditSchemaTables;
26
27
  /**
28
   * The names of all tables in data schema.
29
   *
30
   * @var array
31
   */
32
  private $dataSchemaTables;
33
34
  //--------------------------------------------------------------------------------------------------------------------
35
  /**
36
   * Check full full and return array without new or obsolete columns if full not set.
37
   *
38
   * @param array[] $columns The metadata of the columns of a table.
39
   *
40
   * @var StratumStyle
41
   */
42
  protected $io;
43
44
  //--------------------------------------------------------------------------------------------------------------------
45
  /**
46
   * Getting list of all tables from information_schema of database from config file.
47
   */
48
  public function listOfTables()
49
  {
50
    $this->dataSchemaTables = AuditDataLayer::getTablesNames($this->config['database']['data_schema']);
51
52
    $this->auditSchemaTables = AuditDataLayer::getTablesNames($this->config['database']['audit_schema']);
53
  }
54
55
  //--------------------------------------------------------------------------------------------------------------------
56
  /**
57
   * {@inheritdoc}
58
   */
59 1
  protected function configure()
60
  {
61 1
    $this->setName('diff')
62 1
         ->setDescription('Compares data tables and audit tables')
63 1
         ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json')
64 1
         ->addOption('full', 'f', InputOption::VALUE_NONE, 'Show all columns');
65 1
  }
66
67
  //--------------------------------------------------------------------------------------------------------------------
68
  /**
69
   * {@inheritdoc}
70
   */
71
  protected function execute(InputInterface $input, OutputInterface $output)
72
  {
73
    $this->io = new StratumStyle($input, $output);
74
75
    $this->configFileName = $input->getArgument('config file');
76
    $this->readConfigFile();
77
78
    $this->connect($this->config);
79
80
    $diff = new AuditDiff($this->config, $this->io, $input, $output);
81
    $diff->main();
82
  }
83
84
  //--------------------------------------------------------------------------------------------------------------------
85
86
}
87
88
//----------------------------------------------------------------------------------------------------------------------
89