@@ -144,7 +144,7 @@ |
||
| 144 | 144 | * |
| 145 | 145 | * @param string $columnName The column name. |
| 146 | 146 | * |
| 147 | - * @return null|string |
|
| 147 | + * @return integer|null |
|
| 148 | 148 | */ |
| 149 | 149 | public function getPreviousColumn($columnName) |
| 150 | 150 | { |
@@ -119,7 +119,7 @@ |
||
| 119 | 119 | if (!isset($columns2->columns[$column1['column_name']])) |
| 120 | 120 | { |
| 121 | 121 | $diff[] = ['column_name' => $column1['column_name'], |
| 122 | - 'column_type' => $column1['column_type']]; |
|
| 122 | + 'column_type' => $column1['column_type']]; |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -151,7 +151,7 @@ |
||
| 151 | 151 | $columns = array_keys($this->columns); |
| 152 | 152 | $key = array_search($columnName, $columns); |
| 153 | 153 | |
| 154 | - if ($key>=1) |
|
| 154 | + if ($key >= 1) |
|
| 155 | 155 | { |
| 156 | 156 | return $columns[$key - 1]; |
| 157 | 157 | } |
@@ -268,7 +268,7 @@ |
||
| 268 | 268 | /** |
| 269 | 269 | * Selects and returns the metadata of the columns of this table from information_schema. |
| 270 | 270 | * |
| 271 | - * @return array[] |
|
| 271 | + * @return \array[] |
|
| 272 | 272 | */ |
| 273 | 273 | private function getColumnsFromInformationSchema() |
| 274 | 274 | { |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | private function getAlteredColumns() |
| 260 | 260 | { |
| 261 | 261 | $alteredColumnsTypes = Columns::differentColumnTypes($this->dataTableColumnsDatabase, |
| 262 | - $this->dataTableColumnsConfig); |
|
| 262 | + $this->dataTableColumnsConfig); |
|
| 263 | 263 | |
| 264 | 264 | return $alteredColumnsTypes; |
| 265 | 265 | } |
@@ -382,9 +382,9 @@ discard block |
||
| 382 | 382 | foreach ($alteredColumns as $column) |
| 383 | 383 | { |
| 384 | 384 | $this->io->logInfo('Type of <dbo>%s.%s</dbo> has been altered to <dbo>%s</dbo>', |
| 385 | - $this->tableName, |
|
| 386 | - $column['column_name'], |
|
| 387 | - $column['column_type']); |
|
| 385 | + $this->tableName, |
|
| 386 | + $column['column_name'], |
|
| 387 | + $column['column_type']); |
|
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | 390 | |
@@ -109,14 +109,14 @@ discard block |
||
| 109 | 109 | $additionSql) |
| 110 | 110 | { |
| 111 | 111 | $helper = new CreateAuditTrigger($dataSchemaName, |
| 112 | - $auditSchemaName, |
|
| 113 | - $tableName, |
|
| 114 | - $triggerAction, |
|
| 115 | - $triggerName, |
|
| 116 | - $tableColumns, |
|
| 117 | - $auditColumns, |
|
| 118 | - $skipVariable, |
|
| 119 | - $additionSql); |
|
| 112 | + $auditSchemaName, |
|
| 113 | + $tableName, |
|
| 114 | + $triggerAction, |
|
| 115 | + $triggerName, |
|
| 116 | + $tableColumns, |
|
| 117 | + $auditColumns, |
|
| 118 | + $skipVariable, |
|
| 119 | + $additionSql); |
|
| 120 | 120 | $sql = $helper->buildStatement(); |
| 121 | 121 | |
| 122 | 122 | self::executeNone($sql); |
@@ -259,8 +259,8 @@ discard block |
||
| 259 | 259 | where TABLE_SCHEMA = %s |
| 260 | 260 | and TABLE_NAME = %s |
| 261 | 261 | order by ORDINAL_POSITION', |
| 262 | - self::$dl->quoteString($schemaName), |
|
| 263 | - self::$dl->quoteString($tableName)); |
|
| 262 | + self::$dl->quoteString($schemaName), |
|
| 263 | + self::$dl->quoteString($tableName)); |
|
| 264 | 264 | |
| 265 | 265 | return self::$dl->executeRows($sql); |
| 266 | 266 | } |
@@ -284,8 +284,8 @@ discard block |
||
| 284 | 284 | inner join information_schema.COLLATION_CHARACTER_SET_APPLICABILITY t2 on t2.COLLATION_NAME = t1.TABLE_COLLATION |
| 285 | 285 | WHERE t1.TABLE_SCHEMA = %s |
| 286 | 286 | AND t1.TABLE_NAME = %s', |
| 287 | - self::$dl->quoteString($schemaName), |
|
| 288 | - self::$dl->quoteString($tableName)); |
|
| 287 | + self::$dl->quoteString($schemaName), |
|
| 288 | + self::$dl->quoteString($tableName)); |
|
| 289 | 289 | |
| 290 | 290 | return self::$dl->executeRow1($sql); |
| 291 | 291 | } |
@@ -307,8 +307,8 @@ discard block |
||
| 307 | 307 | where TRIGGER_SCHEMA = %s |
| 308 | 308 | and EVENT_OBJECT_TABLE = %s |
| 309 | 309 | order by Trigger_Name', |
| 310 | - self::$dl->quoteString($schemaName), |
|
| 311 | - self::$dl->quoteString($tableName)); |
|
| 310 | + self::$dl->quoteString($schemaName), |
|
| 311 | + self::$dl->quoteString($tableName)); |
|
| 312 | 312 | |
| 313 | 313 | return self::$dl->executeRows($sql); |
| 314 | 314 | } |
@@ -117,7 +117,7 @@ |
||
| 117 | 117 | $auditColumns, |
| 118 | 118 | $skipVariable, |
| 119 | 119 | $additionSql); |
| 120 | - $sql = $helper->buildStatement(); |
|
| 120 | + $sql = $helper->buildStatement(); |
|
| 121 | 121 | |
| 122 | 122 | self::executeNone($sql); |
| 123 | 123 | } |
@@ -114,7 +114,7 @@ |
||
| 114 | 114 | if ($trim) $line = trim($line); |
| 115 | 115 | |
| 116 | 116 | $words = explode(' ', $line); |
| 117 | - if (count($words)>0) |
|
| 117 | + if (count($words) > 0) |
|
| 118 | 118 | { |
| 119 | 119 | switch ($words[0]) |
| 120 | 120 | { |
@@ -111,7 +111,10 @@ |
||
| 111 | 111 | */ |
| 112 | 112 | private function appendLine($line, $trim) |
| 113 | 113 | { |
| 114 | - if ($trim) $line = trim($line); |
|
| 114 | + if ($trim) |
|
| 115 | + { |
|
| 116 | + $line = trim($line); |
|
| 117 | + } |
|
| 115 | 118 | |
| 116 | 119 | $words = explode(' ', $line); |
| 117 | 120 | if (count($words)>0) |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 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]; |
|
| 104 | + 'alias' => null, |
|
| 105 | + 'skip' => null]; |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | protected function configure() |
| 115 | 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'); |
|
| 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 | 119 | } |
| 120 | 120 | |
| 121 | 121 | //-------------------------------------------------------------------------------------------------------------------- |
@@ -153,7 +153,7 @@ |
||
| 153 | 153 | $this->config['audit_columns'], |
| 154 | 154 | $this->config['tables'][$table['table_name']]['alias'], |
| 155 | 155 | $this->config['tables'][$table['table_name']]['skip']); |
| 156 | - $res = StaticDataLayer::searchInRowSet('table_name', $currentTable->getTableName(), $this->auditSchemaTables); |
|
| 156 | + $res = StaticDataLayer::searchInRowSet('table_name', $currentTable->getTableName(), $this->auditSchemaTables); |
|
| 157 | 157 | if (!isset($res)) |
| 158 | 158 | { |
| 159 | 159 | $currentTable->createMissingAuditTable(); |
@@ -155,7 +155,10 @@ discard block |
||
| 155 | 155 | $this->code->append('for each row'); |
| 156 | 156 | $this->code->append('begin'); |
| 157 | 157 | |
| 158 | - if ($this->skipVariable!==null) $this->code->append(sprintf('if (%s is null) then', $this->skipVariable)); |
|
| 158 | + if ($this->skipVariable!==null) |
|
| 159 | + { |
|
| 160 | + $this->code->append(sprintf('if (%s is null) then', $this->skipVariable)); |
|
| 161 | + } |
|
| 159 | 162 | |
| 160 | 163 | $this->code->append($this->additionalSql); |
| 161 | 164 | |
@@ -165,7 +168,10 @@ discard block |
||
| 165 | 168 | $this->createInsertStatement($rowState[1]); |
| 166 | 169 | } |
| 167 | 170 | |
| 168 | - if ($this->skipVariable!==null) $this->code->append('end if;'); |
|
| 171 | + if ($this->skipVariable!==null) |
|
| 172 | + { |
|
| 173 | + $this->code->append('end if;'); |
|
| 174 | + } |
|
| 169 | 175 | $this->code->append('end'); |
| 170 | 176 | |
| 171 | 177 | return $this->code->getCode(); |
@@ -194,14 +200,20 @@ discard block |
||
| 194 | 200 | // First the audit columns. |
| 195 | 201 | foreach ($this->auditColumns->getColumns() as $column) |
| 196 | 202 | { |
| 197 | - if ($columnNames) $columnNames .= ','; |
|
| 203 | + if ($columnNames) |
|
| 204 | + { |
|
| 205 | + $columnNames .= ','; |
|
| 206 | + } |
|
| 198 | 207 | $columnNames .= sprintf('`%s`', $column['column_name']); |
| 199 | 208 | } |
| 200 | 209 | |
| 201 | 210 | // Second the audit columns. |
| 202 | 211 | foreach ($this->tableColumns->getColumns() as $column) |
| 203 | 212 | { |
| 204 | - if ($columnNames) $columnNames .= ','; |
|
| 213 | + if ($columnNames) |
|
| 214 | + { |
|
| 215 | + $columnNames .= ','; |
|
| 216 | + } |
|
| 205 | 217 | $columnNames .= sprintf('`%s`', $column['column_name']); |
| 206 | 218 | } |
| 207 | 219 | |
@@ -221,7 +233,10 @@ discard block |
||
| 221 | 233 | // First the values for the audit columns. |
| 222 | 234 | foreach ($this->auditColumns->getColumns() as $column) |
| 223 | 235 | { |
| 224 | - if ($values) $values .= ','; |
|
| 236 | + if ($values) |
|
| 237 | + { |
|
| 238 | + $values .= ','; |
|
| 239 | + } |
|
| 225 | 240 | switch (true) |
| 226 | 241 | { |
| 227 | 242 | case (isset($column['audit_value_type'])): |
@@ -252,7 +267,10 @@ discard block |
||
| 252 | 267 | // Second the values for the audit columns. |
| 253 | 268 | foreach ($this->tableColumns->getColumns() as $column) |
| 254 | 269 | { |
| 255 | - if ($values) $values .= ','; |
|
| 270 | + if ($values) |
|
| 271 | + { |
|
| 272 | + $values .= ','; |
|
| 273 | + } |
|
| 256 | 274 | $values .= sprintf('%s.`%s`', $rowState, $column['column_name']); |
| 257 | 275 | } |
| 258 | 276 | |
@@ -19,8 +19,8 @@ |
||
| 19 | 19 | protected function configure() |
| 20 | 20 | { |
| 21 | 21 | $this->setName('about') |
| 22 | - ->setDescription('Short information about AuditApplication') |
|
| 23 | - ->setHelp('<info>audit about</info>'); |
|
| 22 | + ->setDescription('Short information about AuditApplication') |
|
| 23 | + ->setHelp('<info>audit about</info>'); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | //-------------------------------------------------------------------------------------------------------------------- |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | $this->io->write(<<<EOT |
| 35 | 35 | <info>AuditApplication - Database Auditing</info> |
| 36 | 36 | <comment>Creates audit tables and triggers to track data changes in databases.</comment> |
| 37 | -EOT |
|
| 37 | +eot |
|
| 38 | 38 | ); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -73,9 +73,9 @@ |
||
| 73 | 73 | protected function configure() |
| 74 | 74 | { |
| 75 | 75 | $this->setName('diff') |
| 76 | - ->setDescription('Compares data tables and audit tables') |
|
| 77 | - ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json') |
|
| 78 | - ->addOption('full', 'f', InputOption::VALUE_NONE, 'Show all columns'); |
|
| 76 | + ->setDescription('Compares data tables and audit tables') |
|
| 77 | + ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json') |
|
| 78 | + ->addOption('full', 'f', InputOption::VALUE_NONE, 'Show all columns'); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | //-------------------------------------------------------------------------------------------------------------------- |
@@ -201,7 +201,7 @@ |
||
| 201 | 201 | // Removing audit columns. |
| 202 | 202 | $auditColumns = array_udiff($auditColumns, |
| 203 | 203 | $this->config['audit_columns'], |
| 204 | - function ($a, $b) |
|
| 204 | + function($a, $b) |
|
| 205 | 205 | { |
| 206 | 206 | return strcmp($a['column_name'], $b['column_name']); |
| 207 | 207 | }); |
@@ -70,8 +70,8 @@ |
||
| 70 | 70 | if ($mandatory) |
| 71 | 71 | { |
| 72 | 72 | throw new RuntimeException("Setting '%s' not found in section '%s' configuration file.", |
| 73 | - $settingName, |
|
| 74 | - $sectionName); |
|
| 73 | + $settingName, |
|
| 74 | + $sectionName); |
|
| 75 | 75 | } |
| 76 | 76 | else |
| 77 | 77 | { |
@@ -90,7 +90,7 @@ |
||
| 90 | 90 | { |
| 91 | 91 | $content = file_get_contents($this->configFileName); |
| 92 | 92 | |
| 93 | - $this->config = (array)json_decode($content, true); |
|
| 93 | + $this->config = (array) json_decode($content, true); |
|
| 94 | 94 | if (json_last_error()!=JSON_ERROR_NONE) |
| 95 | 95 | { |
| 96 | 96 | throw new RuntimeException("Error decoding JSON: '%s'.", json_last_error_msg()); |
@@ -137,7 +137,10 @@ |
||
| 137 | 137 | if (file_exists($filename)) |
| 138 | 138 | { |
| 139 | 139 | $old_data = file_get_contents($filename); |
| 140 | - if ($data==$old_data) $write_flag = false; |
|
| 140 | + if ($data==$old_data) |
|
| 141 | + { |
|
| 142 | + $write_flag = false; |
|
| 143 | + } |
|
| 141 | 144 | } |
| 142 | 145 | |
| 143 | 146 | if ($write_flag) |