Completed
Pull Request — master (#30)
by
unknown
02:33
created
src/MySql/DataLayer.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
    * @param string  $schemaName   The name of the table schema.
302 302
    * @param array[] $auditColumns Audit columns from config file.
303 303
    *
304
-   * @return array
304
+   * @return integer
305 305
    */
306 306
   public static function createTempTable($schemaName, $auditColumns)
307 307
   {
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
    * @param string $schemaName The name of the table schema.
328 328
    * @param string $tableName  The name of the table.
329 329
    *
330
-   * @return array
330
+   * @return integer
331 331
    */
332 332
   public static function dropTable($schemaName, $tableName)
333 333
   {
Please login to merge, or discard this patch.
Indentation   +309 added lines, -309 removed lines patch added patch discarded remove patch
@@ -16,90 +16,90 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class DataLayer
18 18
 {
19
-  //--------------------------------------------------------------------------------------------------------------------
20
-  /**
21
-   * The connection to the MySQL instance.
22
-   *
23
-   * @var StaticDataLayer
24
-   */
25
-  private static $dl;
26
-
27
-  /**
28
-   * The Output decorator.
29
-   *
30
-   * @var StratumStyle
31
-   */
32
-  private static $io;
33
-
34
-  //--------------------------------------------------------------------------------------------------------------------
35
-  /**
36
-   * Adds new columns to an audit table.
37
-   *
38
-   * @param string  $auditSchemaName The name of audit schema.
39
-   * @param string  $tableName       The name of the table.
40
-   * @param Columns $columns         The metadata of the new columns.
41
-   */
42
-  public static function addNewColumns($auditSchemaName, $tableName, $columns)
43
-  {
19
+    //--------------------------------------------------------------------------------------------------------------------
20
+    /**
21
+     * The connection to the MySQL instance.
22
+     *
23
+     * @var StaticDataLayer
24
+     */
25
+    private static $dl;
26
+
27
+    /**
28
+     * The Output decorator.
29
+     *
30
+     * @var StratumStyle
31
+     */
32
+    private static $io;
33
+
34
+    //--------------------------------------------------------------------------------------------------------------------
35
+    /**
36
+     * Adds new columns to an audit table.
37
+     *
38
+     * @param string  $auditSchemaName The name of audit schema.
39
+     * @param string  $tableName       The name of the table.
40
+     * @param Columns $columns         The metadata of the new columns.
41
+     */
42
+    public static function addNewColumns($auditSchemaName, $tableName, $columns)
43
+    {
44 44
     $helper = new AlterAuditTableAddColumns($auditSchemaName, $tableName, $columns);
45 45
     $sql    = $helper->buildStatement();
46 46
 
47 47
     self::executeNone($sql);
48
-  }
49
-
50
-  //--------------------------------------------------------------------------------------------------------------------
51
-  /**
52
-   * Connects to a MySQL instance.
53
-   *
54
-   * Wrapper around [mysqli::__construct](http://php.net/manual/mysqli.construct.php), however on failure an exception
55
-   * is thrown.
56
-   *
57
-   * @param string $host     The hostname.
58
-   * @param string $user     The MySQL user name.
59
-   * @param string $passWord The password.
60
-   * @param string $database The default database.
61
-   * @param int    $port     The port number.
62
-   */
63
-  public static function connect($host, $user, $passWord, $database, $port = 3306)
64
-  {
48
+    }
49
+
50
+    //--------------------------------------------------------------------------------------------------------------------
51
+    /**
52
+     * Connects to a MySQL instance.
53
+     *
54
+     * Wrapper around [mysqli::__construct](http://php.net/manual/mysqli.construct.php), however on failure an exception
55
+     * is thrown.
56
+     *
57
+     * @param string $host     The hostname.
58
+     * @param string $user     The MySQL user name.
59
+     * @param string $passWord The password.
60
+     * @param string $database The default database.
61
+     * @param int    $port     The port number.
62
+     */
63
+    public static function connect($host, $user, $passWord, $database, $port = 3306)
64
+    {
65 65
     self::$dl = new StaticDataLayer();
66 66
 
67 67
     self::$dl->connect($host, $user, $passWord, $database, $port);
68
-  }
69
-
70
-  //--------------------------------------------------------------------------------------------------------------------
71
-  /**
72
-   * Creates an audit table.
73
-   *
74
-   * @param string  $dataSchemaName  The name of the data schema.
75
-   * @param string  $auditSchemaName The name of the audit schema.
76
-   * @param string  $tableName       The name of the table.
77
-   * @param Columns $columns         The metadata of the columns of the audit table (i.e. the audit columns and columns
78
-   *                                 of the data table).
79
-   */
80
-  public static function createAuditTable($dataSchemaName, $auditSchemaName, $tableName, $columns)
81
-  {
68
+    }
69
+
70
+    //--------------------------------------------------------------------------------------------------------------------
71
+    /**
72
+     * Creates an audit table.
73
+     *
74
+     * @param string  $dataSchemaName  The name of the data schema.
75
+     * @param string  $auditSchemaName The name of the audit schema.
76
+     * @param string  $tableName       The name of the table.
77
+     * @param Columns $columns         The metadata of the columns of the audit table (i.e. the audit columns and columns
78
+     *                                 of the data table).
79
+     */
80
+    public static function createAuditTable($dataSchemaName, $auditSchemaName, $tableName, $columns)
81
+    {
82 82
     $helper = new CreateAuditTable($dataSchemaName, $auditSchemaName, $tableName, $columns);
83 83
     $sql    = $helper->buildStatement();
84 84
 
85 85
     self::executeNone($sql);
86
-  }
87
-
88
-  //--------------------------------------------------------------------------------------------------------------------
89
-  /**
90
-   * Creates a trigger on a table.
91
-   *
92
-   * @param string   $dataSchemaName  The name of the data schema.
93
-   * @param string   $auditSchemaName The name of the audit schema.
94
-   * @param string   $tableName       The name of the table.
95
-   * @param string   $triggerAction   The trigger action (i.e. INSERT, UPDATE, or DELETE).
96
-   * @param string   $triggerName     The name of the trigger.
97
-   * @param Columns  $tableColumns    The data table columns.
98
-   * @param Columns  $auditColumns    The audit table columns.
99
-   * @param string   $skipVariable    The skip variable.
100
-   * @param string[] $additionSql     Additional SQL statements.
101
-   */
102
-  public static function createAuditTrigger($dataSchemaName,
86
+    }
87
+
88
+    //--------------------------------------------------------------------------------------------------------------------
89
+    /**
90
+     * Creates a trigger on a table.
91
+     *
92
+     * @param string   $dataSchemaName  The name of the data schema.
93
+     * @param string   $auditSchemaName The name of the audit schema.
94
+     * @param string   $tableName       The name of the table.
95
+     * @param string   $triggerAction   The trigger action (i.e. INSERT, UPDATE, or DELETE).
96
+     * @param string   $triggerName     The name of the trigger.
97
+     * @param Columns  $tableColumns    The data table columns.
98
+     * @param Columns  $auditColumns    The audit table columns.
99
+     * @param string   $skipVariable    The skip variable.
100
+     * @param string[] $additionSql     Additional SQL statements.
101
+     */
102
+    public static function createAuditTrigger($dataSchemaName,
103 103
                                             $auditSchemaName,
104 104
                                             $tableName,
105 105
                                             $triggerAction,
@@ -108,151 +108,151 @@  discard block
 block discarded – undo
108 108
                                             $auditColumns,
109 109
                                             $skipVariable,
110 110
                                             $additionSql)
111
-  {
111
+    {
112 112
     $helper = new CreateAuditTrigger($dataSchemaName,
113
-                                     $auditSchemaName,
114
-                                     $tableName,
115
-                                     $triggerAction,
116
-                                     $triggerName,
117
-                                     $tableColumns,
118
-                                     $auditColumns,
119
-                                     $skipVariable,
120
-                                     $additionSql);
113
+                                        $auditSchemaName,
114
+                                        $tableName,
115
+                                        $triggerAction,
116
+                                        $triggerName,
117
+                                        $tableColumns,
118
+                                        $auditColumns,
119
+                                        $skipVariable,
120
+                                        $additionSql);
121 121
     $sql    = $helper->buildStatement();
122 122
 
123 123
     self::executeNone($sql);
124
-  }
125
-
126
-  //--------------------------------------------------------------------------------------------------------------------
127
-  /**
128
-   * Closes the connection to the MySQL instance, if connected.
129
-   */
130
-  public static function disconnect()
131
-  {
124
+    }
125
+
126
+    //--------------------------------------------------------------------------------------------------------------------
127
+    /**
128
+     * Closes the connection to the MySQL instance, if connected.
129
+     */
130
+    public static function disconnect()
131
+    {
132 132
     if (self::$dl!==null)
133 133
     {
134
-      self::$dl->disconnect();
135
-      self::$dl = null;
134
+        self::$dl->disconnect();
135
+        self::$dl = null;
136 136
     }
137
-  }
138
-
139
-  //--------------------------------------------------------------------------------------------------------------------
140
-  /**
141
-   * Drops a trigger.
142
-   *
143
-   * @param string $triggerSchema The name of the trigger schema.
144
-   * @param string $triggerName   The mame of trigger.
145
-   */
146
-  public static function dropTrigger($triggerSchema, $triggerName)
147
-  {
137
+    }
138
+
139
+    //--------------------------------------------------------------------------------------------------------------------
140
+    /**
141
+     * Drops a trigger.
142
+     *
143
+     * @param string $triggerSchema The name of the trigger schema.
144
+     * @param string $triggerName   The mame of trigger.
145
+     */
146
+    public static function dropTrigger($triggerSchema, $triggerName)
147
+    {
148 148
     $sql = sprintf('drop trigger `%s`.`%s`', $triggerSchema, $triggerName);
149 149
 
150 150
     self::executeNone($sql);
151
-  }
152
-
153
-  //--------------------------------------------------------------------------------------------------------------------
154
-  /**
155
-   * @param string $query The SQL statement.
156
-   *
157
-   * @return int The number of affected rows (if any).
158
-   */
159
-  public static function executeNone($query)
160
-  {
151
+    }
152
+
153
+    //--------------------------------------------------------------------------------------------------------------------
154
+    /**
155
+     * @param string $query The SQL statement.
156
+     *
157
+     * @return int The number of affected rows (if any).
158
+     */
159
+    public static function executeNone($query)
160
+    {
161 161
     self::logQuery($query);
162 162
 
163 163
     return self::$dl->executeNone($query);
164
-  }
165
-
166
-  //--------------------------------------------------------------------------------------------------------------------
167
-  /**
168
-   * Executes a query that returns 0 or 1 row.
169
-   * Throws an exception if the query selects 2 or more rows.
170
-   *
171
-   * @param string $query The SQL statement.
172
-   *
173
-   * @return array|null The selected row.
174
-   */
175
-  public static function executeRow0($query)
176
-  {
164
+    }
165
+
166
+    //--------------------------------------------------------------------------------------------------------------------
167
+    /**
168
+     * Executes a query that returns 0 or 1 row.
169
+     * Throws an exception if the query selects 2 or more rows.
170
+     *
171
+     * @param string $query The SQL statement.
172
+     *
173
+     * @return array|null The selected row.
174
+     */
175
+    public static function executeRow0($query)
176
+    {
177 177
     self::logQuery($query);
178 178
 
179 179
     return self::$dl->executeRow0($query);
180
-  }
181
-
182
-  //--------------------------------------------------------------------------------------------------------------------
183
-  /**
184
-   * Executes a query that returns 1 and only 1 row.
185
-   * Throws an exception if the query selects none, 2 or more rows.
186
-   *
187
-   * @param string $query The SQL statement.
188
-   *
189
-   * @return array The selected row.
190
-   */
191
-  public static function executeRow1($query)
192
-  {
180
+    }
181
+
182
+    //--------------------------------------------------------------------------------------------------------------------
183
+    /**
184
+     * Executes a query that returns 1 and only 1 row.
185
+     * Throws an exception if the query selects none, 2 or more rows.
186
+     *
187
+     * @param string $query The SQL statement.
188
+     *
189
+     * @return array The selected row.
190
+     */
191
+    public static function executeRow1($query)
192
+    {
193 193
     self::logQuery($query);
194 194
 
195 195
     return self::$dl->executeRow1($query);
196
-  }
197
-
198
-  //--------------------------------------------------------------------------------------------------------------------
199
-  /**
200
-   * Executes a query that returns 0 or more rows.
201
-   *
202
-   * @param string $query The SQL statement.
203
-   *
204
-   * @return \array[]
205
-   */
206
-  public static function executeRows($query)
207
-  {
196
+    }
197
+
198
+    //--------------------------------------------------------------------------------------------------------------------
199
+    /**
200
+     * Executes a query that returns 0 or more rows.
201
+     *
202
+     * @param string $query The SQL statement.
203
+     *
204
+     * @return \array[]
205
+     */
206
+    public static function executeRows($query)
207
+    {
208 208
     self::logQuery($query);
209 209
 
210 210
     return self::$dl->executeRows($query);
211
-  }
212
-
213
-  //--------------------------------------------------------------------------------------------------------------------
214
-  /**
215
-   * Executes a query that returns 0 or 1 row.
216
-   * Throws an exception if the query selects 2 or more rows.
217
-   *
218
-   * @param string $query The SQL statement.
219
-   *
220
-   * @return int|string|null The selected row.
221
-   */
222
-  public static function executeSingleton0($query)
223
-  {
211
+    }
212
+
213
+    //--------------------------------------------------------------------------------------------------------------------
214
+    /**
215
+     * Executes a query that returns 0 or 1 row.
216
+     * Throws an exception if the query selects 2 or more rows.
217
+     *
218
+     * @param string $query The SQL statement.
219
+     *
220
+     * @return int|string|null The selected row.
221
+     */
222
+    public static function executeSingleton0($query)
223
+    {
224 224
     self::logQuery($query);
225 225
 
226 226
     return self::$dl->executeSingleton0($query);
227
-  }
228
-
229
-  //--------------------------------------------------------------------------------------------------------------------
230
-  /**
231
-   * Executes a query that returns 1 and only 1 row with 1 column.
232
-   * Throws an exception if the query selects none, 2 or more rows.
233
-   *
234
-   * @param string $query The SQL statement.
235
-   *
236
-   * @return int|string The selected row.
237
-   */
238
-  public static function executeSingleton1($query)
239
-  {
227
+    }
228
+
229
+    //--------------------------------------------------------------------------------------------------------------------
230
+    /**
231
+     * Executes a query that returns 1 and only 1 row with 1 column.
232
+     * Throws an exception if the query selects none, 2 or more rows.
233
+     *
234
+     * @param string $query The SQL statement.
235
+     *
236
+     * @return int|string The selected row.
237
+     */
238
+    public static function executeSingleton1($query)
239
+    {
240 240
     self::logQuery($query);
241 241
 
242 242
     return self::$dl->executeSingleton1($query);
243
-  }
244
-
245
-  //--------------------------------------------------------------------------------------------------------------------
246
-  /**
247
-   * Selects metadata of all columns of table.
248
-   *
249
-   * @param string $schemaName The name of the table schema.
250
-   * @param string $tableName  The name of the table.
251
-   *
252
-   * @return \array[]
253
-   */
254
-  public static function getTableColumns($schemaName, $tableName)
255
-  {
243
+    }
244
+
245
+    //--------------------------------------------------------------------------------------------------------------------
246
+    /**
247
+     * Selects metadata of all columns of table.
248
+     *
249
+     * @param string $schemaName The name of the table schema.
250
+     * @param string $tableName  The name of the table.
251
+     *
252
+     * @return \array[]
253
+     */
254
+    public static function getTableColumns($schemaName, $tableName)
255
+    {
256 256
     $sql = sprintf('
257 257
 select COLUMN_NAME        as column_name
258 258
 ,      COLUMN_TYPE        as column_type
@@ -263,23 +263,23 @@  discard block
 block discarded – undo
263 263
 where  TABLE_SCHEMA = %s
264 264
 and    TABLE_NAME   = %s
265 265
 order by ORDINAL_POSITION',
266
-                   self::$dl->quoteString($schemaName),
267
-                   self::$dl->quoteString($tableName));
266
+                    self::$dl->quoteString($schemaName),
267
+                    self::$dl->quoteString($tableName));
268 268
 
269 269
     return self::$dl->executeRows($sql);
270
-  }
271
-
272
-  //--------------------------------------------------------------------------------------------------------------------
273
-  /**
274
-   * Selects table engine, character_set_name and table_collation.
275
-   *
276
-   * @param string $schemaName The name of the table schema.
277
-   * @param string $tableName  The name of the table.
278
-   *
279
-   * @return array
280
-   */
281
-  public static function getTableOptions($schemaName, $tableName)
282
-  {
270
+    }
271
+
272
+    //--------------------------------------------------------------------------------------------------------------------
273
+    /**
274
+     * Selects table engine, character_set_name and table_collation.
275
+     *
276
+     * @param string $schemaName The name of the table schema.
277
+     * @param string $tableName  The name of the table.
278
+     *
279
+     * @return array
280
+     */
281
+    public static function getTableOptions($schemaName, $tableName)
282
+    {
283 283
     $sql = sprintf('
284 284
 SELECT t1.TABLE_COLLATION    as table_collation
285 285
 ,      t1.ENGINE             as engine
@@ -288,87 +288,87 @@  discard block
 block discarded – undo
288 288
 inner join information_schema.COLLATION_CHARACTER_SET_APPLICABILITY t2  on  t2.COLLATION_NAME = t1.TABLE_COLLATION
289 289
 WHERE t1.TABLE_SCHEMA = %s
290 290
 AND   t1.TABLE_NAME   = %s',
291
-                   self::$dl->quoteString($schemaName),
292
-                   self::$dl->quoteString($tableName));
291
+                    self::$dl->quoteString($schemaName),
292
+                    self::$dl->quoteString($tableName));
293 293
 
294 294
     return self::$dl->executeRow1($sql);
295
-  }
296
-
297
-  //--------------------------------------------------------------------------------------------------------------------
298
-  /**
299
-   * Create temp table for getting column type information for audit columns.
300
-   *
301
-   * @param string  $schemaName   The name of the table schema.
302
-   * @param array[] $auditColumns Audit columns from config file.
303
-   *
304
-   * @return array
305
-   */
306
-  public static function createTempTable($schemaName, $auditColumns)
307
-  {
295
+    }
296
+
297
+    //--------------------------------------------------------------------------------------------------------------------
298
+    /**
299
+     * Create temp table for getting column type information for audit columns.
300
+     *
301
+     * @param string  $schemaName   The name of the table schema.
302
+     * @param array[] $auditColumns Audit columns from config file.
303
+     *
304
+     * @return array
305
+     */
306
+    public static function createTempTable($schemaName, $auditColumns)
307
+    {
308 308
     $sql = new CompoundSyntaxStore();
309 309
     $sql->append(sprintf('CREATE TABLE %s.temp (', $schemaName));
310 310
     foreach ($auditColumns as $column)
311 311
     {
312
-      $sql->append(sprintf('%s %s', $column['column_name'], $column['column_type']));
313
-      if (end($auditColumns)!==$column)
314
-      {
312
+        $sql->append(sprintf('%s %s', $column['column_name'], $column['column_type']));
313
+        if (end($auditColumns)!==$column)
314
+        {
315 315
         $sql->appendToLastLine(',');
316
-      }
316
+        }
317 317
     }
318 318
     $sql->append(')');
319 319
 
320 320
     return self::$dl->executeNone($sql->getCode());
321
-  }
322
-
323
-  //--------------------------------------------------------------------------------------------------------------------
324
-  /**
325
-   * Drop table.
326
-   *
327
-   * @param string $schemaName The name of the table schema.
328
-   * @param string $tableName  The name of the table.
329
-   *
330
-   * @return array
331
-   */
332
-  public static function dropTable($schemaName, $tableName)
333
-  {
321
+    }
322
+
323
+    //--------------------------------------------------------------------------------------------------------------------
324
+    /**
325
+     * Drop table.
326
+     *
327
+     * @param string $schemaName The name of the table schema.
328
+     * @param string $tableName  The name of the table.
329
+     *
330
+     * @return array
331
+     */
332
+    public static function dropTable($schemaName, $tableName)
333
+    {
334 334
     $sql = sprintf('drop table %s.%s', $schemaName, $tableName);
335 335
 
336 336
     return self::$dl->executeNone($sql);
337
-  }
338
-
339
-  //--------------------------------------------------------------------------------------------------------------------
340
-  /**
341
-   * Selects all triggers on a table.
342
-   *
343
-   * @param string $schemaName The name of the table schema.
344
-   * @param string $tableName  The name of the table.
345
-   *
346
-   * @return \array[]
347
-   */
348
-  public static function getTableTriggers($schemaName, $tableName)
349
-  {
337
+    }
338
+
339
+    //--------------------------------------------------------------------------------------------------------------------
340
+    /**
341
+     * Selects all triggers on a table.
342
+     *
343
+     * @param string $schemaName The name of the table schema.
344
+     * @param string $tableName  The name of the table.
345
+     *
346
+     * @return \array[]
347
+     */
348
+    public static function getTableTriggers($schemaName, $tableName)
349
+    {
350 350
     $sql = sprintf('
351 351
 select Trigger_Name as trigger_name
352 352
 from   information_schema.TRIGGERS
353 353
 where  TRIGGER_SCHEMA     = %s
354 354
 and    EVENT_OBJECT_TABLE = %s
355 355
 order by Trigger_Name',
356
-                   self::$dl->quoteString($schemaName),
357
-                   self::$dl->quoteString($tableName));
356
+                    self::$dl->quoteString($schemaName),
357
+                    self::$dl->quoteString($tableName));
358 358
 
359 359
     return self::$dl->executeRows($sql);
360
-  }
361
-
362
-  //--------------------------------------------------------------------------------------------------------------------
363
-  /**
364
-   * Selects all table names in a schema.
365
-   *
366
-   * @param string $schemaName The name of the schema.
367
-   *
368
-   * @return \array[]
369
-   */
370
-  public static function getTablesNames($schemaName)
371
-  {
360
+    }
361
+
362
+    //--------------------------------------------------------------------------------------------------------------------
363
+    /**
364
+     * Selects all table names in a schema.
365
+     *
366
+     * @param string $schemaName The name of the schema.
367
+     *
368
+     * @return \array[]
369
+     */
370
+    public static function getTablesNames($schemaName)
371
+    {
372 372
     $sql = sprintf("
373 373
 select TABLE_NAME as table_name
374 374
 from   information_schema.TABLES
@@ -377,67 +377,67 @@  discard block
 block discarded – undo
377 377
 order by TABLE_NAME", self::$dl->quoteString($schemaName));
378 378
 
379 379
     return self::$dl->executeRows($sql);
380
-  }
381
-
382
-  //--------------------------------------------------------------------------------------------------------------------
383
-  /**
384
-   * Acquires a write lock on a table.
385
-   *
386
-   * @param string $tableName The table name.
387
-   */
388
-  public static function lockTable($tableName)
389
-  {
380
+    }
381
+
382
+    //--------------------------------------------------------------------------------------------------------------------
383
+    /**
384
+     * Acquires a write lock on a table.
385
+     *
386
+     * @param string $tableName The table name.
387
+     */
388
+    public static function lockTable($tableName)
389
+    {
390 390
     $sql = sprintf('lock tables `%s` write', $tableName);
391 391
 
392 392
     self::$dl->executeNone($sql);
393
-  }
394
-
395
-  //--------------------------------------------------------------------------------------------------------------------
396
-  /**
397
-   * Sets the Output decorator.
398
-   *
399
-   * @param StratumStyle $io The Output decorator.
400
-   */
401
-  public static function setIo($io)
402
-  {
393
+    }
394
+
395
+    //--------------------------------------------------------------------------------------------------------------------
396
+    /**
397
+     * Sets the Output decorator.
398
+     *
399
+     * @param StratumStyle $io The Output decorator.
400
+     */
401
+    public static function setIo($io)
402
+    {
403 403
     self::$io = $io;
404
-  }
405
-
406
-  //--------------------------------------------------------------------------------------------------------------------
407
-  /**
408
-   * Releases all table locks.
409
-   */
410
-  public static function unlockTables()
411
-  {
404
+    }
405
+
406
+    //--------------------------------------------------------------------------------------------------------------------
407
+    /**
408
+     * Releases all table locks.
409
+     */
410
+    public static function unlockTables()
411
+    {
412 412
     $sql = 'unlock tables';
413 413
 
414 414
     self::$dl->executeNone($sql);
415
-  }
416
-
417
-  //--------------------------------------------------------------------------------------------------------------------
418
-  /**
419
-   * Logs the query on the console.
420
-   *
421
-   * @param string $query The query.
422
-   */
423
-  private static function logQuery($query)
424
-  {
415
+    }
416
+
417
+    //--------------------------------------------------------------------------------------------------------------------
418
+    /**
419
+     * Logs the query on the console.
420
+     *
421
+     * @param string $query The query.
422
+     */
423
+    private static function logQuery($query)
424
+    {
425 425
     $query = trim($query);
426 426
 
427 427
     if (strpos($query, "\n")!==false)
428 428
     {
429
-      // Query is a multi line query.
430
-      self::$io->logVeryVerbose('Executing query:');
431
-      self::$io->logVeryVerbose('<sql>%s</sql>', $query);
429
+        // Query is a multi line query.
430
+        self::$io->logVeryVerbose('Executing query:');
431
+        self::$io->logVeryVerbose('<sql>%s</sql>', $query);
432 432
     }
433 433
     else
434 434
     {
435
-      // Query is a single line query.
436
-      self::$io->logVeryVerbose('Executing query: <sql>%s</sql>', $query);
435
+        // Query is a single line query.
436
+        self::$io->logVeryVerbose('Executing query: <sql>%s</sql>', $query);
437
+    }
437 438
     }
438
-  }
439 439
 
440
-  //--------------------------------------------------------------------------------------------------------------------
440
+    //--------------------------------------------------------------------------------------------------------------------
441 441
 }
442 442
 
443 443
 //----------------------------------------------------------------------------------------------------------------------
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
                                      $auditColumns,
119 119
                                      $skipVariable,
120 120
                                      $additionSql);
121
-    $sql    = $helper->buildStatement();
121
+    $sql = $helper->buildStatement();
122 122
 
123 123
     self::executeNone($sql);
124 124
   }
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
    */
130 130
   public static function disconnect()
131 131
   {
132
-    if (self::$dl!==null)
132
+    if (self::$dl !== null)
133 133
     {
134 134
       self::$dl->disconnect();
135 135
       self::$dl = null;
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
     foreach ($auditColumns as $column)
311 311
     {
312 312
       $sql->append(sprintf('%s %s', $column['column_name'], $column['column_type']));
313
-      if (end($auditColumns)!==$column)
313
+      if (end($auditColumns) !== $column)
314 314
       {
315 315
         $sql->appendToLastLine(',');
316 316
       }
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
   {
425 425
     $query = trim($query);
426 426
 
427
-    if (strpos($query, "\n")!==false)
427
+    if (strpos($query, "\n") !== false)
428 428
     {
429 429
       // Query is a multi line query.
430 430
       self::$io->logVeryVerbose('Executing query:');
Please login to merge, or discard this patch.
src/Command/DiffCommand.php 1 patch
Indentation   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -22,89 +22,89 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class DiffCommand extends AuditCommand
24 24
 {
25
-  //--------------------------------------------------------------------------------------------------------------------
26
-  /**
27
-   * Array with columns for each table.
28
-   * array [
29
-   *    table_name [
30
-   *            column [
31
-   *                    data table type,
32
-   *                    audit table type
33
-   *                    ],
34
-   *                      ...
35
-   *               ]
36
-   *       ]
37
-   *
38
-   * @var array[]
39
-   */
40
-  private $diffColumns;
41
-
42
-  /**
43
-   * If set all tables and columns are shown.
44
-   *
45
-   * @var boolean
46
-   */
47
-  private $full;
48
-
49
-  //--------------------------------------------------------------------------------------------------------------------
50
-  /**
51
-   * Check full full and return array without new or obsolete columns if full not set.
52
-   *
53
-   * @param array[] $columns The metadata of the columns of a table.
54
-   *
55
-   * @return array[]
56
-   */
57
-  private static function removeMatchingColumns($columns)
58
-  {
25
+    //--------------------------------------------------------------------------------------------------------------------
26
+    /**
27
+     * Array with columns for each table.
28
+     * array [
29
+     *    table_name [
30
+     *            column [
31
+     *                    data table type,
32
+     *                    audit table type
33
+     *                    ],
34
+     *                      ...
35
+     *               ]
36
+     *       ]
37
+     *
38
+     * @var array[]
39
+     */
40
+    private $diffColumns;
41
+
42
+    /**
43
+     * If set all tables and columns are shown.
44
+     *
45
+     * @var boolean
46
+     */
47
+    private $full;
48
+
49
+    //--------------------------------------------------------------------------------------------------------------------
50
+    /**
51
+     * Check full full and return array without new or obsolete columns if full not set.
52
+     *
53
+     * @param array[] $columns The metadata of the columns of a table.
54
+     *
55
+     * @return array[]
56
+     */
57
+    private static function removeMatchingColumns($columns)
58
+    {
59 59
     $cleaned = [];
60 60
     /** @var ColumnTypes $column */
61 61
     foreach ($columns as $column)
62 62
     {
63
-      $columnsArray = $column->getTypes();
64
-      if (!isset($columnsArray['data_column_type']))
65
-      {
63
+        $columnsArray = $column->getTypes();
64
+        if (!isset($columnsArray['data_column_type']))
65
+        {
66 66
         if ($columnsArray['audit_column_type']!=$columnsArray['config_column_type'])
67 67
         {
68
-          $cleaned[] = $column;
68
+            $cleaned[] = $column;
69
+        }
69 70
         }
70
-      }
71
-      elseif (!isset($columnsArray['config_column_type']))
72
-      {
71
+        elseif (!isset($columnsArray['config_column_type']))
72
+        {
73 73
         if (($columnsArray['audit_column_type']!=$columnsArray['data_column_type']) || ($columnsArray['audit_character_set_name']!=$columnsArray['data_character_set_name'] || $columnsArray['audit_collation_name']!=$columnsArray['data_collation_name']))
74 74
         {
75
-          $cleaned[] = $column;
75
+            $cleaned[] = $column;
76
+        }
76 77
         }
77
-      }
78
-      else
79
-      {
78
+        else
79
+        {
80 80
         if (($columnsArray['data_column_type']!=$columnsArray['audit_column_type'] && $columnsArray['audit_column_type']!=$columnsArray['config_column_type']) || ($columnsArray['audit_column_type']!=$columnsArray['config_column_type'] && !empty($columnsArray['config_column_type'])))
81 81
         {
82
-          $cleaned[] = $column;
82
+            $cleaned[] = $column;
83
+        }
83 84
         }
84
-      }
85 85
     }
86 86
 
87 87
     return $cleaned;
88
-  }
89
-
90
-  //--------------------------------------------------------------------------------------------------------------------
91
-  /**
92
-   * {@inheritdoc}
93
-   */
94
-  protected function configure()
95
-  {
88
+    }
89
+
90
+    //--------------------------------------------------------------------------------------------------------------------
91
+    /**
92
+     * {@inheritdoc}
93
+     */
94
+    protected function configure()
95
+    {
96 96
     $this->setName('diff')
97
-         ->setDescription('Compares data tables and audit tables')
98
-         ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json')
99
-         ->addOption('full', 'f', InputOption::VALUE_NONE, 'Show all columns');
100
-  }
101
-
102
-  //--------------------------------------------------------------------------------------------------------------------
103
-  /**
104
-   * {@inheritdoc}
105
-   */
106
-  protected function execute(InputInterface $input, OutputInterface $output)
107
-  {
97
+            ->setDescription('Compares data tables and audit tables')
98
+            ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json')
99
+            ->addOption('full', 'f', InputOption::VALUE_NONE, 'Show all columns');
100
+    }
101
+
102
+    //--------------------------------------------------------------------------------------------------------------------
103
+    /**
104
+     * {@inheritdoc}
105
+     */
106
+    protected function execute(InputInterface $input, OutputInterface $output)
107
+    {
108 108
     $this->io = new StratumStyle($input, $output);
109 109
     // Style for column names with miss matched column types.
110 110
     $style = new OutputFormatterStyle(null, 'red');
@@ -135,179 +135,179 @@  discard block
 block discarded – undo
135 135
 
136 136
     $this->getDiff();
137 137
     $this->printDiff($output);
138
-  }
139
-
140
-  //--------------------------------------------------------------------------------------------------------------------
141
-  /**
142
-   * Get the difference between data and audit tables.
143
-   *
144
-   * @param Columns $dataColumns  The table columns from data schema.
145
-   * @param Columns $auditColumns The table columns from audit schema.
146
-   *
147
-   * @return \array[]
148
-   */
149
-  private function createDiffArray($dataColumns, $auditColumns)
150
-  {
138
+    }
139
+
140
+    //--------------------------------------------------------------------------------------------------------------------
141
+    /**
142
+     * Get the difference between data and audit tables.
143
+     *
144
+     * @param Columns $dataColumns  The table columns from data schema.
145
+     * @param Columns $auditColumns The table columns from audit schema.
146
+     *
147
+     * @return \array[]
148
+     */
149
+    private function createDiffArray($dataColumns, $auditColumns)
150
+    {
151 151
     $diff = [];
152 152
 
153 153
     foreach ($this->config['audit_columns'] as $column)
154 154
     {
155
-      $columnTypes                  = new ColumnTypes($column, 'config');
156
-      $diff[$column['column_name']] = $columnTypes;
155
+        $columnTypes                  = new ColumnTypes($column, 'config');
156
+        $diff[$column['column_name']] = $columnTypes;
157 157
     }
158 158
 
159 159
     foreach ($auditColumns->getColumns() as $column)
160 160
     {
161
-      if (isset($diff[$column['column_name']]))
162
-      {
161
+        if (isset($diff[$column['column_name']]))
162
+        {
163 163
         $diff[$column['column_name']]->appendColumnTypes($column, 'audit');
164
-      }
165
-      else
166
-      {
164
+        }
165
+        else
166
+        {
167 167
         $columnTypes                  = new ColumnTypes($column, 'audit');
168 168
         $diff[$column['column_name']] = $columnTypes;
169
-      }
169
+        }
170 170
     }
171 171
 
172 172
     foreach ($dataColumns->getColumns() as $column)
173 173
     {
174
-      if (isset($diff[$column['column_name']]))
175
-      {
174
+        if (isset($diff[$column['column_name']]))
175
+        {
176 176
         $diff[$column['column_name']]->appendColumnTypes($column, 'data');
177
-      }
178
-      else
179
-      {
177
+        }
178
+        else
179
+        {
180 180
         $columnTypes                  = new ColumnTypes($column, 'data');
181 181
         $diff[$column['column_name']] = $columnTypes;
182
-      }
182
+        }
183 183
     }
184 184
 
185 185
     return $diff;
186
-  }
187
-
188
-  //--------------------------------------------------------------------------------------------------------------------
189
-  /**
190
-   * Computes the difference between data and audit tables.
191
-   */
192
-  private function getDiff()
193
-  {
186
+    }
187
+
188
+    //--------------------------------------------------------------------------------------------------------------------
189
+    /**
190
+     * Computes the difference between data and audit tables.
191
+     */
192
+    private function getDiff()
193
+    {
194 194
     foreach ($this->dataSchemaTables as $table)
195 195
     {
196
-      if ($this->config['tables'][$table['table_name']]['audit'])
197
-      {
196
+        if ($this->config['tables'][$table['table_name']]['audit'])
197
+        {
198 198
         $res = StaticDataLayer::searchInRowSet('table_name', $table['table_name'], $this->auditSchemaTables);
199 199
         if (isset($res))
200 200
         {
201
-          $dataColumns  = new Columns(DataLayer::getTableColumns($this->config['database']['data_schema'], $table['table_name']));
202
-          $auditColumns = DataLayer::getTableColumns($this->config['database']['audit_schema'], $table['table_name']);
203
-          $auditColumns = $this->addNotNull($auditColumns);
204
-          $auditColumns = new Columns($auditColumns);
201
+            $dataColumns  = new Columns(DataLayer::getTableColumns($this->config['database']['data_schema'], $table['table_name']));
202
+            $auditColumns = DataLayer::getTableColumns($this->config['database']['audit_schema'], $table['table_name']);
203
+            $auditColumns = $this->addNotNull($auditColumns);
204
+            $auditColumns = new Columns($auditColumns);
205 205
 
206
-          $this->diffColumns[$table['table_name']] = $this->createDiffArray($dataColumns, $auditColumns);
206
+            $this->diffColumns[$table['table_name']] = $this->createDiffArray($dataColumns, $auditColumns);
207
+        }
207 208
         }
208
-      }
209 209
     }
210
-  }
211
-
212
-  //--------------------------------------------------------------------------------------------------------------------
213
-  /**
214
-   * Add not null to audit columns if it not nullable.
215
-   *
216
-   * @param array $theColumns Audit columns.
217
-   *
218
-   * @return array
219
-   */
220
-  private function addNotNull($theColumns)
221
-  {
210
+    }
211
+
212
+    //--------------------------------------------------------------------------------------------------------------------
213
+    /**
214
+     * Add not null to audit columns if it not nullable.
215
+     *
216
+     * @param array $theColumns Audit columns.
217
+     *
218
+     * @return array
219
+     */
220
+    private function addNotNull($theColumns)
221
+    {
222 222
     $modifiedColumns = [];
223 223
     foreach ($theColumns as $column)
224 224
     {
225
-      $modifiedColumn = $column;
226
-      $auditColumn    = StaticDataLayer::searchInRowSet('column_name', $modifiedColumn['column_name'], $this->config['audit_columns']);
227
-      if (isset($auditColumn))
228
-      {
225
+        $modifiedColumn = $column;
226
+        $auditColumn    = StaticDataLayer::searchInRowSet('column_name', $modifiedColumn['column_name'], $this->config['audit_columns']);
227
+        if (isset($auditColumn))
228
+        {
229 229
         if ($modifiedColumn['is_nullable']==='NO')
230 230
         {
231
-          $modifiedColumn['column_type'] = sprintf('%s not null', $modifiedColumn['column_type']);
231
+            $modifiedColumn['column_type'] = sprintf('%s not null', $modifiedColumn['column_type']);
232
+        }
232 233
         }
233
-      }
234
-      $modifiedColumns[] = $modifiedColumn;
234
+        $modifiedColumns[] = $modifiedColumn;
235 235
     }
236 236
 
237 237
     return $modifiedColumns;
238
-  }
239
-
240
-  //--------------------------------------------------------------------------------------------------------------------
241
-  /**
242
-   * Writes the difference between the audit tables and metadata tables to the output.
243
-   *
244
-   * @param OutputInterface $output The output.
245
-   */
246
-  private function diffTables($output)
247
-  {
238
+    }
239
+
240
+    //--------------------------------------------------------------------------------------------------------------------
241
+    /**
242
+     * Writes the difference between the audit tables and metadata tables to the output.
243
+     *
244
+     * @param OutputInterface $output The output.
245
+     */
246
+    private function diffTables($output)
247
+    {
248 248
     foreach ($this->config['tables'] as $tableName => $table)
249 249
     {
250
-      $res = StaticDataLayer::searchInRowSet('table_name', $tableName, $this->auditSchemaTables);
251
-      if ($table['audit'] && !isset($res))
252
-      {
250
+        $res = StaticDataLayer::searchInRowSet('table_name', $tableName, $this->auditSchemaTables);
251
+        if ($table['audit'] && !isset($res))
252
+        {
253 253
         $output->writeln(sprintf('<miss_table>%s</>', $tableName));
254
-      }
255
-      else if (!$table['audit'] && isset($res))
256
-      {
254
+        }
255
+        else if (!$table['audit'] && isset($res))
256
+        {
257 257
         $output->writeln(sprintf('<obsolete_table>%s</>', $tableName));
258
-      }
258
+        }
259 259
     }
260
-  }
261
-
262
-  //--------------------------------------------------------------------------------------------------------------------
263
-  /**
264
-   * Writes the difference between the audit and data tables to the output.
265
-   *
266
-   * @param OutputInterface $output The output.
267
-   */
268
-  private function printDiff($output)
269
-  {
260
+    }
261
+
262
+    //--------------------------------------------------------------------------------------------------------------------
263
+    /**
264
+     * Writes the difference between the audit and data tables to the output.
265
+     *
266
+     * @param OutputInterface $output The output.
267
+     */
268
+    private function printDiff($output)
269
+    {
270 270
     $first = true;
271 271
     if (isset($this->diffColumns))
272 272
     {
273
-      foreach ($this->diffColumns as $tableName => $columns)
274
-      {
273
+        foreach ($this->diffColumns as $tableName => $columns)
274
+        {
275 275
         // Remove matching columns unless the full option is used.
276 276
         if (!$this->full)
277 277
         {
278
-          $columns = self::removeMatchingColumns($columns);
278
+            $columns = self::removeMatchingColumns($columns);
279 279
         }
280 280
 
281 281
         if (!empty($columns))
282 282
         {
283
-          // Add an empty line between tables.
284
-          if ($first)
285
-          {
283
+            // Add an empty line between tables.
284
+            if ($first)
285
+            {
286 286
             $first = false;
287
-          }
288
-          else
289
-          {
287
+            }
288
+            else
289
+            {
290 290
             $output->writeln('');
291
-          }
291
+            }
292 292
 
293
-          // Write table name.
294
-          $output->writeln($tableName);
293
+            // Write table name.
294
+            $output->writeln($tableName);
295 295
 
296
-          // Write table with columns.
297
-          $rows = new TableHelper($this->config['database']['data_schema'], $this->config['database']['audit_schema'], $tableName, $this->config['audit_columns'], $this->full);
298
-          $rows->appendRows($columns);
299
-          $rows->addHighlighting();
300
-          $table = new Table($output);
301
-          $table->setHeaders(['column', 'data table', 'audit table', 'config'])
296
+            // Write table with columns.
297
+            $rows = new TableHelper($this->config['database']['data_schema'], $this->config['database']['audit_schema'], $tableName, $this->config['audit_columns'], $this->full);
298
+            $rows->appendRows($columns);
299
+            $rows->addHighlighting();
300
+            $table = new Table($output);
301
+            $table->setHeaders(['column', 'data table', 'audit table', 'config'])
302 302
                 ->setRows($rows->getRows());
303
-          $table->render();
303
+            $table->render();
304
+        }
304 305
         }
305
-      }
306 306
     }
307 307
     $this->diffTables($output);
308
-  }
308
+    }
309 309
 
310
-  //--------------------------------------------------------------------------------------------------------------------
310
+    //--------------------------------------------------------------------------------------------------------------------
311 311
 }
312 312
 
313 313
 //----------------------------------------------------------------------------------------------------------------------
Please login to merge, or discard this patch.
src/MySql/Command/AuditCommand.php 2 patches
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -17,113 +17,113 @@  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
             $this->config['tables'][$table['table_name']]['alias'] = Table::getRandomAlias();
97
-          }
97
+            }
98 98
         }
99
-      }
100
-      else
101
-      {
99
+        }
100
+        else
101
+        {
102 102
         $this->io->writeln(sprintf('<info>Found new table %s</info>', $table['table_name']));
103 103
         $this->config['tables'][$table['table_name']] = ['audit' => false,
104
-                                                         'alias' => null,
105
-                                                         'skip'  => null];
106
-      }
104
+                                                            'alias' => null,
105
+                                                            'skip'  => null];
106
+        }
107 107
     }
108
-  }
109
-
110
-  //--------------------------------------------------------------------------------------------------------------------
111
-  /**
112
-   * {@inheritdoc}
113
-   */
114
-  protected function configure()
115
-  {
108
+    }
109
+
110
+    //--------------------------------------------------------------------------------------------------------------------
111
+    /**
112
+     * {@inheritdoc}
113
+     */
114
+    protected function configure()
115
+    {
116 116
     $this->setName('audit')
117
-         ->setDescription('Create (missing) audit table and (re)creates audit triggers')
118
-         ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json');
119
-  }
120
-
121
-  //--------------------------------------------------------------------------------------------------------------------
122
-  /**
123
-   * {@inheritdoc}
124
-   */
125
-  protected function execute(InputInterface $input, OutputInterface $output)
126
-  {
117
+            ->setDescription('Create (missing) audit table and (re)creates audit triggers')
118
+            ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json');
119
+    }
120
+
121
+    //--------------------------------------------------------------------------------------------------------------------
122
+    /**
123
+     * {@inheritdoc}
124
+     */
125
+    protected function execute(InputInterface $input, OutputInterface $output)
126
+    {
127 127
     $this->io = new StratumStyle($input, $output);
128 128
 
129 129
     $this->configFileName = $input->getArgument('config file');
@@ -140,77 +140,77 @@  discard block
 block discarded – undo
140 140
 
141 141
     foreach ($this->dataSchemaTables as $table)
142 142
     {
143
-      if ($this->config['tables'][$table['table_name']]['audit'])
144
-      {
143
+        if ($this->config['tables'][$table['table_name']]['audit'])
144
+        {
145 145
         $tableColumns = [];
146 146
         if (isset($this->config['table_columns'][$table['table_name']]))
147 147
         {
148
-          $tableColumns = $this->config['table_columns'][$table['table_name']];
148
+            $tableColumns = $this->config['table_columns'][$table['table_name']];
149 149
         }
150 150
         $currentTable = new Table($this->io,
151
-                                  $table['table_name'],
152
-                                  $this->config['database']['data_schema'],
153
-                                  $this->config['database']['audit_schema'],
154
-                                  $tableColumns,
155
-                                  $this->config['audit_columns'],
156
-                                  $this->config['tables'][$table['table_name']]['alias'],
157
-                                  $this->config['tables'][$table['table_name']]['skip']);
151
+                                    $table['table_name'],
152
+                                    $this->config['database']['data_schema'],
153
+                                    $this->config['database']['audit_schema'],
154
+                                    $tableColumns,
155
+                                    $this->config['audit_columns'],
156
+                                    $this->config['tables'][$table['table_name']]['alias'],
157
+                                    $this->config['tables'][$table['table_name']]['skip']);
158 158
         $res          = StaticDataLayer::searchInRowSet('table_name', $currentTable->getTableName(), $this->auditSchemaTables);
159 159
         if (!isset($res))
160 160
         {
161
-          $currentTable->createMissingAuditTable();
161
+            $currentTable->createMissingAuditTable();
162 162
         }
163 163
 
164 164
         $columns        = $currentTable->main($this->config['additional_sql']);
165 165
         $alteredColumns = $columns['altered_columns']->getColumns();
166 166
         if (empty($alteredColumns))
167 167
         {
168
-          $this->getColumns($currentTable->getTableName(), $columns['full_columns']);
168
+            $this->getColumns($currentTable->getTableName(), $columns['full_columns']);
169
+        }
169 170
         }
170
-      }
171 171
     }
172 172
 
173 173
     // Drop database connection
174 174
     DataLayer::disconnect();
175 175
 
176 176
     $this->rewriteConfig();
177
-  }
178
-
179
-  //--------------------------------------------------------------------------------------------------------------------
180
-  /**
181
-   * Get canonical column types for audit columns.
182
-   */
183
-  protected function auditColumnTypes()
184
-  {
177
+    }
178
+
179
+    //--------------------------------------------------------------------------------------------------------------------
180
+    /**
181
+     * Get canonical column types for audit columns.
182
+     */
183
+    protected function auditColumnTypes()
184
+    {
185 185
     $schema = $this->config['database']['audit_schema'];
186 186
     $table  = 'temp';
187 187
     DataLayer::createTempTable($schema, $this->config['audit_columns']);
188 188
     $auditColumns = DataLayer::getTableColumns($schema, $table);
189 189
     foreach ($auditColumns as $column)
190 190
     {
191
-      $key = StaticDataLayer::searchInRowSet('column_name', $column['column_name'], $this->config['audit_columns']);
192
-      if (isset($key))
193
-      {
191
+        $key = StaticDataLayer::searchInRowSet('column_name', $column['column_name'], $this->config['audit_columns']);
192
+        if (isset($key))
193
+        {
194 194
         $this->config['audit_columns'][$key]['column_type'] = $column['column_type'];
195 195
         if ($column['is_nullable']==='NO')
196 196
         {
197
-          $this->config['audit_columns'][$key]['column_type'] = sprintf('%s not null', $this->config['audit_columns'][$key]['column_type']);
197
+            $this->config['audit_columns'][$key]['column_type'] = sprintf('%s not null', $this->config['audit_columns'][$key]['column_type']);
198
+        }
198 199
         }
199
-      }
200 200
     }
201 201
     DataLayer::dropTable($schema, $table);
202
-  }
203
-
204
-  //--------------------------------------------------------------------------------------------------------------------
205
-  /**
206
-   * Write new data to config file.
207
-   */
208
-  private function rewriteConfig()
209
-  {
202
+    }
203
+
204
+    //--------------------------------------------------------------------------------------------------------------------
205
+    /**
206
+     * Write new data to config file.
207
+     */
208
+    private function rewriteConfig()
209
+    {
210 210
     $this->writeTwoPhases($this->configFileName, json_encode($this->config, JSON_PRETTY_PRINT));
211
-  }
211
+    }
212 212
 
213
-  //--------------------------------------------------------------------------------------------------------------------
213
+    //--------------------------------------------------------------------------------------------------------------------
214 214
 }
215 215
 
216 216
 //----------------------------------------------------------------------------------------------------------------------
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
                                   $this->config['audit_columns'],
156 156
                                   $this->config['tables'][$table['table_name']]['alias'],
157 157
                                   $this->config['tables'][$table['table_name']]['skip']);
158
-        $res          = StaticDataLayer::searchInRowSet('table_name', $currentTable->getTableName(), $this->auditSchemaTables);
158
+        $res = StaticDataLayer::searchInRowSet('table_name', $currentTable->getTableName(), $this->auditSchemaTables);
159 159
         if (!isset($res))
160 160
         {
161 161
           $currentTable->createMissingAuditTable();
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
       if (isset($key))
193 193
       {
194 194
         $this->config['audit_columns'][$key]['column_type'] = $column['column_type'];
195
-        if ($column['is_nullable']==='NO')
195
+        if ($column['is_nullable'] === 'NO')
196 196
         {
197 197
           $this->config['audit_columns'][$key]['column_type'] = sprintf('%s not null', $this->config['audit_columns'][$key]['column_type']);
198 198
         }
Please login to merge, or discard this patch.