Completed
Pull Request — master (#41)
by Dima
03:13
created

DiffCommand::listOfTables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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 1
   * @var array
31
   */
32 1
  private $dataSchemaTables;
33 1
34 1
  //--------------------------------------------------------------------------------------------------------------------
35 1
  /**
36 1
   * 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
  protected function configure()
60
  {
61
    $this->setName('diff')
62
         ->setDescription('Compares data tables and audit tables')
63
         ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json')
64
         ->addOption('full', 'f', InputOption::VALUE_NONE, 'Show all columns');
65
  }
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->readMetadata();
79
80
    $this->connect($this->config);
81
82
    $diff = new AuditDiff($this->config, $this->io, $input, $output);
83
    $diff->main();
84
  }
85
86
  //--------------------------------------------------------------------------------------------------------------------
87
88
}
89
90
//----------------------------------------------------------------------------------------------------------------------
91