Completed
Pull Request — master (#57)
by Dima
02:53
created

AlterTableCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 16
ccs 0
cts 10
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 9
nc 1
nop 2
crap 2
1
<?php
2
//----------------------------------------------------------------------------------------------------------------------
3
namespace SetBased\Audit\MySql\Command;
4
5
use SetBased\Audit\MySql\AuditAlter;
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 comparing data tables with audit tables.
14
 */
15
class AlterTableCommand extends AuditCommand
16
{
17
  //--------------------------------------------------------------------------------------------------------------------
18
  /**
19
   * Check full full and return array without new or obsolete columns if full not set.
20
   *
21
   * @param array[] $columns The metadata of the columns of a table.
22
   *
23
   * @var StratumStyle
24
   */
25
  protected $io;
26
27
  //--------------------------------------------------------------------------------------------------------------------
28
  /**
29
   * {@inheritdoc}
30
   */
31 1
  protected function configure()
32
  {
33 1
    $this->setName('alter-table-sql')
34 1
         ->setDescription('Create alter table SQL commands for audit tables columns that are different from the config columns or from columns data tables')
35 1
         ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json')
36 1
         ->addArgument('result sql file', InputArgument::OPTIONAL, 'The result file for SQL statement', 'etc/alter-table-sql-result.sql');
37 1
  }
38
39
  //--------------------------------------------------------------------------------------------------------------------
40
  /**
41
   * {@inheritdoc}
42
   */
43
  protected function execute(InputInterface $input, OutputInterface $output)
44
  {
45
    $this->io = new StratumStyle($input, $output);
46
47
    $resultSqlFile = $input->getArgument('result sql file');
48
49
    $this->configFileName = $input->getArgument('config file');
50
    $this->readConfigFile();
51
52
    $this->connect($this->config);
53
54
    $alter   = new AuditAlter($this->config, $this->configMetadata);
55
    $content = $alter->main();
56
57
    $this->writeTwoPhases($resultSqlFile, $content);
58
  }
59
60
  //--------------------------------------------------------------------------------------------------------------------
61
62
}
63
64
//----------------------------------------------------------------------------------------------------------------------
65