Completed
Pull Request — master (#55)
by Dima
03:18
created

DiffCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

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