Completed
Push — master ( da3388...742dfe )
by P.R.
8s
created
src/MySql/Command/AuditCommand.php 2 patches
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -17,116 +17,116 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class AuditCommand extends MySqlCommand
19 19
 {
20
-  //--------------------------------------------------------------------------------------------------------------------
21
-  /**
22
-   * All tables in the in the audit schema.
23
-   *
24
-   * @var array
25
-   */
26
-  protected $auditSchemaTables;
27
-
28
-  /**
29
-   * Array of tables from data schema.
30
-   *
31
-   * @var array
32
-   */
33
-  protected $dataSchemaTables;
34
-
35
-  /**
36
-   * If true remove all column information from config file.
37
-   *
38
-   * @var boolean
39
-   */
40
-  private $pruneOption;
41
-
42
-  //--------------------------------------------------------------------------------------------------------------------
43
-  /**
44
-   * Compares the tables listed in the config file and the tables found in the audit schema
45
-   *
46
-   * @param string  $tableName Name of table
47
-   * @param Columns $columns   The table columns.
48
-   */
49
-  public function getColumns($tableName, $columns)
50
-  {
20
+    //--------------------------------------------------------------------------------------------------------------------
21
+    /**
22
+     * All tables in the in the audit schema.
23
+     *
24
+     * @var array
25
+     */
26
+    protected $auditSchemaTables;
27
+
28
+    /**
29
+     * Array of tables from data schema.
30
+     *
31
+     * @var array
32
+     */
33
+    protected $dataSchemaTables;
34
+
35
+    /**
36
+     * If true remove all column information from config file.
37
+     *
38
+     * @var boolean
39
+     */
40
+    private $pruneOption;
41
+
42
+    //--------------------------------------------------------------------------------------------------------------------
43
+    /**
44
+     * Compares the tables listed in the config file and the tables found in the audit schema
45
+     *
46
+     * @param string  $tableName Name of table
47
+     * @param Columns $columns   The table columns.
48
+     */
49
+    public function getColumns($tableName, $columns)
50
+    {
51 51
     $newColumns = [];
52 52
     foreach ($columns->getColumns() as $column)
53 53
     {
54
-      $newColumns[] = ['column_name' => $column['column_name'],
55
-                       'column_type' => $column['column_type']];
54
+        $newColumns[] = ['column_name' => $column['column_name'],
55
+                        'column_type' => $column['column_type']];
56 56
     }
57 57
     $this->config['table_columns'][$tableName] = $newColumns;
58 58
 
59 59
     if ($this->pruneOption)
60 60
     {
61
-      $this->config['table_columns'] = [];
61
+        $this->config['table_columns'] = [];
62
+    }
62 63
     }
63
-  }
64
-
65
-  //--------------------------------------------------------------------------------------------------------------------
66
-  /**
67
-   * Getting list of all tables from information_schema of database from config file.
68
-   */
69
-  public function listOfTables()
70
-  {
64
+
65
+    //--------------------------------------------------------------------------------------------------------------------
66
+    /**
67
+     * Getting list of all tables from information_schema of database from config file.
68
+     */
69
+    public function listOfTables()
70
+    {
71 71
     $this->dataSchemaTables = DataLayer::getTablesNames($this->config['database']['data_schema']);
72 72
 
73 73
     $this->auditSchemaTables = DataLayer::getTablesNames($this->config['database']['audit_schema']);
74
-  }
75
-
76
-  //--------------------------------------------------------------------------------------------------------------------
77
-  /**
78
-   * Found tables in config file
79
-   *
80
-   * Compares the tables listed in the config file and the tables found in the data schema
81
-   */
82
-  public function unknownTables()
83
-  {
74
+    }
75
+
76
+    //--------------------------------------------------------------------------------------------------------------------
77
+    /**
78
+     * Found tables in config file
79
+     *
80
+     * Compares the tables listed in the config file and the tables found in the data schema
81
+     */
82
+    public function unknownTables()
83
+    {
84 84
     foreach ($this->dataSchemaTables as $table)
85 85
     {
86
-      if (isset($this->config['tables'][$table['table_name']]))
87
-      {
86
+        if (isset($this->config['tables'][$table['table_name']]))
87
+        {
88 88
         if (!isset($this->config['tables'][$table['table_name']]['audit']))
89 89
         {
90
-          $this->io->writeln(sprintf('<info>AuditApplication flag is not set in table %s</info>', $table['table_name']));
90
+            $this->io->writeln(sprintf('<info>AuditApplication flag is not set in table %s</info>', $table['table_name']));
91 91
         }
92 92
         else
93 93
         {
94
-          if ($this->config['tables'][$table['table_name']]['audit'])
95
-          {
94
+            if ($this->config['tables'][$table['table_name']]['audit'])
95
+            {
96 96
             if(!isset($this->config['tables'][$table['table_name']]['alias']))
97 97
             {
98
-              $this->config['tables'][$table['table_name']]['alias'] = Table::getRandomAlias();
98
+                $this->config['tables'][$table['table_name']]['alias'] = Table::getRandomAlias();
99
+            }
99 100
             }
100
-          }
101 101
         }
102
-      }
103
-      else
104
-      {
102
+        }
103
+        else
104
+        {
105 105
         $this->io->writeln(sprintf('<info>Found new table %s</info>', $table['table_name']));
106 106
         $this->config['tables'][$table['table_name']] = ['audit' => false,
107
-                                                         'alias' => null,
108
-                                                         'skip'  => null];
109
-      }
107
+                                                            'alias' => null,
108
+                                                            'skip'  => null];
109
+        }
110
+    }
110 111
     }
111
-  }
112
-
113
-  //--------------------------------------------------------------------------------------------------------------------
114
-  /**
115
-   * {@inheritdoc}
116
-   */
117
-  protected function configure()
118
-  {
112
+
113
+    //--------------------------------------------------------------------------------------------------------------------
114
+    /**
115
+     * {@inheritdoc}
116
+     */
117
+    protected function configure()
118
+    {
119 119
     $this->setName('audit')
120
-         ->setDescription('Create (missing) audit table and (re)creates audit triggers')
121
-         ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json');
122
-  }
123
-
124
-  //--------------------------------------------------------------------------------------------------------------------
125
-  /**
126
-   * {@inheritdoc}
127
-   */
128
-  protected function execute(InputInterface $input, OutputInterface $output)
129
-  {
120
+            ->setDescription('Create (missing) audit table and (re)creates audit triggers')
121
+            ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json');
122
+    }
123
+
124
+    //--------------------------------------------------------------------------------------------------------------------
125
+    /**
126
+     * {@inheritdoc}
127
+     */
128
+    protected function execute(InputInterface $input, OutputInterface $output)
129
+    {
130 130
     $this->io = new StratumStyle($input, $output);
131 131
 
132 132
     $this->configFileName = $input->getArgument('config file');
@@ -141,52 +141,52 @@  discard block
 block discarded – undo
141 141
 
142 142
     foreach ($this->dataSchemaTables as $table)
143 143
     {
144
-      if ($this->config['tables'][$table['table_name']]['audit'])
145
-      {
144
+        if ($this->config['tables'][$table['table_name']]['audit'])
145
+        {
146 146
         $tableColumns = [];
147 147
         if (isset($this->config['table_columns'][$table['table_name']]))
148 148
         {
149
-          $tableColumns = $this->config['table_columns'][$table['table_name']];
149
+            $tableColumns = $this->config['table_columns'][$table['table_name']];
150 150
         }
151 151
         $currentTable = new Table($this->io,
152
-                                  $table['table_name'],
153
-                                  $this->config['database']['data_schema'],
154
-                                  $this->config['database']['audit_schema'],
155
-                                  $tableColumns,
156
-                                  $this->config['audit_columns'],
157
-                                  $this->config['tables'][$table['table_name']]['alias'],
158
-                                  $this->config['tables'][$table['table_name']]['skip']);
152
+                                    $table['table_name'],
153
+                                    $this->config['database']['data_schema'],
154
+                                    $this->config['database']['audit_schema'],
155
+                                    $tableColumns,
156
+                                    $this->config['audit_columns'],
157
+                                    $this->config['tables'][$table['table_name']]['alias'],
158
+                                    $this->config['tables'][$table['table_name']]['skip']);
159 159
         $res          = StaticDataLayer::searchInRowSet('table_name', $currentTable->getTableName(), $this->auditSchemaTables);
160 160
         if (!isset($res))
161 161
         {
162
-          $currentTable->createMissingAuditTable();
162
+            $currentTable->createMissingAuditTable();
163 163
         }
164 164
 
165 165
         $columns        = $currentTable->main($this->config['additional_sql']);
166 166
         $alteredColumns = $columns['altered_columns']->getColumns();
167 167
         if (empty($alteredColumns))
168 168
         {
169
-          $this->getColumns($currentTable->getTableName(), $columns['full_columns']);
169
+            $this->getColumns($currentTable->getTableName(), $columns['full_columns']);
170
+        }
170 171
         }
171
-      }
172 172
     }
173 173
 
174 174
     // Drop database connection
175 175
     DataLayer::disconnect();
176 176
 
177 177
     $this->rewriteConfig();
178
-  }
179
-
180
-  //--------------------------------------------------------------------------------------------------------------------
181
-  /**
182
-   * Write new data to config file.
183
-   */
184
-  private function rewriteConfig()
185
-  {
178
+    }
179
+
180
+    //--------------------------------------------------------------------------------------------------------------------
181
+    /**
182
+     * Write new data to config file.
183
+     */
184
+    private function rewriteConfig()
185
+    {
186 186
     $this->writeTwoPhases($this->configFileName, json_encode($this->config, JSON_PRETTY_PRINT));
187
-  }
187
+    }
188 188
 
189
-  //--------------------------------------------------------------------------------------------------------------------
189
+    //--------------------------------------------------------------------------------------------------------------------
190 190
 }
191 191
 
192 192
 //----------------------------------------------------------------------------------------------------------------------
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
         {
94 94
           if ($this->config['tables'][$table['table_name']]['audit'])
95 95
           {
96
-            if(!isset($this->config['tables'][$table['table_name']]['alias']))
96
+            if (!isset($this->config['tables'][$table['table_name']]['alias']))
97 97
             {
98 98
               $this->config['tables'][$table['table_name']]['alias'] = Table::getRandomAlias();
99 99
             }
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
                                   $this->config['audit_columns'],
157 157
                                   $this->config['tables'][$table['table_name']]['alias'],
158 158
                                   $this->config['tables'][$table['table_name']]['skip']);
159
-        $res          = StaticDataLayer::searchInRowSet('table_name', $currentTable->getTableName(), $this->auditSchemaTables);
159
+        $res = StaticDataLayer::searchInRowSet('table_name', $currentTable->getTableName(), $this->auditSchemaTables);
160 160
         if (!isset($res))
161 161
         {
162 162
           $currentTable->createMissingAuditTable();
Please login to merge, or discard this patch.