@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @param array[] $columns The metadata of the columns. |
| 124 | 124 | * |
| 125 | - * @return array[] |
|
| 125 | + * @return \array[] |
|
| 126 | 126 | */ |
| 127 | 127 | private function addHighlighting($columns) |
| 128 | 128 | { |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | /** |
| 254 | 254 | * Add not null to audit columns if it not nullable. |
| 255 | 255 | * |
| 256 | - * @param array $theColumns Audit columns. |
|
| 256 | + * @param \array[] $theColumns Audit columns. |
|
| 257 | 257 | * |
| 258 | 258 | * @return array |
| 259 | 259 | */ |
@@ -21,70 +21,70 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class DiffCommand extends AuditCommand |
| 23 | 23 | { |
| 24 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 25 | - /** |
|
| 26 | - * Array with columns for each table. |
|
| 27 | - * array [ |
|
| 28 | - * table_name [ |
|
| 29 | - * column [ |
|
| 30 | - * data table type, |
|
| 31 | - * audit table type |
|
| 32 | - * ], |
|
| 33 | - * ... |
|
| 34 | - * ] |
|
| 35 | - * ] |
|
| 36 | - * |
|
| 37 | - * @var array[] |
|
| 38 | - */ |
|
| 39 | - private $diffColumns; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * If set all tables and columns are shown. |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - private $full; |
|
| 47 | - |
|
| 48 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 49 | - /** |
|
| 50 | - * Check full full and return array without new or obsolete columns if full not set. |
|
| 51 | - * |
|
| 52 | - * @param array[] $columns The metadata of the columns of a table. |
|
| 53 | - * |
|
| 54 | - * @return array[] |
|
| 55 | - */ |
|
| 56 | - private static function removeMatchingColumns($columns) |
|
| 57 | - { |
|
| 24 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 25 | + /** |
|
| 26 | + * Array with columns for each table. |
|
| 27 | + * array [ |
|
| 28 | + * table_name [ |
|
| 29 | + * column [ |
|
| 30 | + * data table type, |
|
| 31 | + * audit table type |
|
| 32 | + * ], |
|
| 33 | + * ... |
|
| 34 | + * ] |
|
| 35 | + * ] |
|
| 36 | + * |
|
| 37 | + * @var array[] |
|
| 38 | + */ |
|
| 39 | + private $diffColumns; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * If set all tables and columns are shown. |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + private $full; |
|
| 47 | + |
|
| 48 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 49 | + /** |
|
| 50 | + * Check full full and return array without new or obsolete columns if full not set. |
|
| 51 | + * |
|
| 52 | + * @param array[] $columns The metadata of the columns of a table. |
|
| 53 | + * |
|
| 54 | + * @return array[] |
|
| 55 | + */ |
|
| 56 | + private static function removeMatchingColumns($columns) |
|
| 57 | + { |
|
| 58 | 58 | $cleaned = []; |
| 59 | 59 | foreach ($columns as $column) |
| 60 | 60 | { |
| 61 | - if (($column['data_table_type']!=$column['audit_table_type'] && $column['audit_table_type']!=$column['config_type']) || ($column['audit_table_type']!=$column['config_type'] && !empty($column['config_type']))) |
|
| 62 | - { |
|
| 61 | + if (($column['data_table_type']!=$column['audit_table_type'] && $column['audit_table_type']!=$column['config_type']) || ($column['audit_table_type']!=$column['config_type'] && !empty($column['config_type']))) |
|
| 62 | + { |
|
| 63 | 63 | $cleaned[] = $column; |
| 64 | - } |
|
| 64 | + } |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | return $cleaned; |
| 68 | - } |
|
| 69 | - |
|
| 70 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 71 | - /** |
|
| 72 | - * {@inheritdoc} |
|
| 73 | - */ |
|
| 74 | - protected function configure() |
|
| 75 | - { |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 71 | + /** |
|
| 72 | + * {@inheritdoc} |
|
| 73 | + */ |
|
| 74 | + protected function configure() |
|
| 75 | + { |
|
| 76 | 76 | $this->setName('diff') |
| 77 | - ->setDescription('Compares data tables and audit tables') |
|
| 78 | - ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json') |
|
| 79 | - ->addOption('full', 'f', InputOption::VALUE_NONE, 'Show all columns'); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 83 | - /** |
|
| 84 | - * {@inheritdoc} |
|
| 85 | - */ |
|
| 86 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
| 87 | - { |
|
| 77 | + ->setDescription('Compares data tables and audit tables') |
|
| 78 | + ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json') |
|
| 79 | + ->addOption('full', 'f', InputOption::VALUE_NONE, 'Show all columns'); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 83 | + /** |
|
| 84 | + * {@inheritdoc} |
|
| 85 | + */ |
|
| 86 | + protected function execute(InputInterface $input, OutputInterface $output) |
|
| 87 | + { |
|
| 88 | 88 | $this->io = new StratumStyle($input, $output); |
| 89 | 89 | |
| 90 | 90 | // Style for column names with miss matched column types. |
@@ -114,239 +114,239 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | $this->getDiff(); |
| 116 | 116 | $this->printDiff($output); |
| 117 | - } |
|
| 118 | - |
|
| 119 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 120 | - /** |
|
| 121 | - * Add highlighting to columns. |
|
| 122 | - * |
|
| 123 | - * @param array[] $columns The metadata of the columns. |
|
| 124 | - * |
|
| 125 | - * @return array[] |
|
| 126 | - */ |
|
| 127 | - private function addHighlighting($columns) |
|
| 128 | - { |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 120 | + /** |
|
| 121 | + * Add highlighting to columns. |
|
| 122 | + * |
|
| 123 | + * @param array[] $columns The metadata of the columns. |
|
| 124 | + * |
|
| 125 | + * @return array[] |
|
| 126 | + */ |
|
| 127 | + private function addHighlighting($columns) |
|
| 128 | + { |
|
| 129 | 129 | $styledColumns = []; |
| 130 | 130 | foreach ($columns as $column) |
| 131 | 131 | { |
| 132 | - $styledColumn = $column; |
|
| 133 | - // Highlighting for data table column types and audit. |
|
| 134 | - if (!empty($column['data_table_type'])) |
|
| 135 | - { |
|
| 132 | + $styledColumn = $column; |
|
| 133 | + // Highlighting for data table column types and audit. |
|
| 134 | + if (!empty($column['data_table_type'])) |
|
| 135 | + { |
|
| 136 | 136 | if (isset($column['data_table_type']) && !isset($column['audit_table_type'])) |
| 137 | 137 | { |
| 138 | - $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
|
| 139 | - $styledColumn['data_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['data_table_type']); |
|
| 138 | + $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
|
| 139 | + $styledColumn['data_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['data_table_type']); |
|
| 140 | 140 | } |
| 141 | 141 | else if (!isset($column['data_table_type']) && isset($column['audit_table_type'])) |
| 142 | 142 | { |
| 143 | - $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['audit_table_type']); |
|
| 143 | + $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['audit_table_type']); |
|
| 144 | 144 | } |
| 145 | 145 | else if (strcmp($column['data_table_type'], $column['audit_table_type'])) |
| 146 | 146 | { |
| 147 | - $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
|
| 148 | - $styledColumn['data_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['data_table_type']); |
|
| 149 | - $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['audit_table_type']); |
|
| 147 | + $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
|
| 148 | + $styledColumn['data_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['data_table_type']); |
|
| 149 | + $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['audit_table_type']); |
|
| 150 | 150 | } |
| 151 | - } |
|
| 152 | - else |
|
| 153 | - { |
|
| 151 | + } |
|
| 152 | + else |
|
| 153 | + { |
|
| 154 | 154 | // Highlighting for audit table column types and audit_columns in config file. |
| 155 | 155 | $searchColumn = StaticDataLayer::searchInRowSet('column_name', $styledColumn['column_name'], $this->config['audit_columns']); |
| 156 | 156 | if (isset($searchColumn)) |
| 157 | 157 | { |
| 158 | - $configType = $this->config['audit_columns'][$searchColumn]['column_type']; |
|
| 159 | - if (isset($configType) && !isset($column['audit_table_type'])) |
|
| 160 | - { |
|
| 158 | + $configType = $this->config['audit_columns'][$searchColumn]['column_type']; |
|
| 159 | + if (isset($configType) && !isset($column['audit_table_type'])) |
|
| 160 | + { |
|
| 161 | 161 | $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
| 162 | 162 | $styledColumn['config_type'] = sprintf('<mm_type>%s</>', $styledColumn['config_type']); |
| 163 | - } |
|
| 164 | - else if (!isset($configType) && isset($column['audit_table_type'])) |
|
| 165 | - { |
|
| 163 | + } |
|
| 164 | + else if (!isset($configType) && isset($column['audit_table_type'])) |
|
| 165 | + { |
|
| 166 | 166 | $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $column['audit_table_type']); |
| 167 | - } |
|
| 168 | - else if (strcmp($configType, $column['audit_table_type'])) |
|
| 169 | - { |
|
| 167 | + } |
|
| 168 | + else if (strcmp($configType, $column['audit_table_type'])) |
|
| 169 | + { |
|
| 170 | 170 | $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
| 171 | 171 | $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $column['audit_table_type']); |
| 172 | 172 | $styledColumn['config_type'] = sprintf('<mm_type>%s</>', $styledColumn['config_type']); |
| 173 | - } |
|
| 173 | + } |
|
| 174 | + } |
|
| 174 | 175 | } |
| 175 | - } |
|
| 176 | - $styledColumns[] = $styledColumn; |
|
| 176 | + $styledColumns[] = $styledColumn; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | return $styledColumns; |
| 180 | - } |
|
| 181 | - |
|
| 182 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 183 | - /** |
|
| 184 | - * Get the difference between data and audit tables. |
|
| 185 | - * |
|
| 186 | - * @param Columns $dataColumns The table columns from data schema. |
|
| 187 | - * @param Columns $auditColumns The table columns from audit schema. |
|
| 188 | - * |
|
| 189 | - * @return array[] |
|
| 190 | - */ |
|
| 191 | - private function createDiffArray($dataColumns, $auditColumns) |
|
| 192 | - { |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 183 | + /** |
|
| 184 | + * Get the difference between data and audit tables. |
|
| 185 | + * |
|
| 186 | + * @param Columns $dataColumns The table columns from data schema. |
|
| 187 | + * @param Columns $auditColumns The table columns from audit schema. |
|
| 188 | + * |
|
| 189 | + * @return array[] |
|
| 190 | + */ |
|
| 191 | + private function createDiffArray($dataColumns, $auditColumns) |
|
| 192 | + { |
|
| 193 | 193 | $diff = []; |
| 194 | 194 | |
| 195 | 195 | foreach ($this->config['audit_columns'] as $column) |
| 196 | 196 | { |
| 197 | - $diff[$column['column_name']] = ['column_name' => $column['column_name'], |
|
| 198 | - 'data_table_type' => null, |
|
| 199 | - 'audit_table_type' => null, |
|
| 200 | - 'config_type' => $column['column_type']]; |
|
| 197 | + $diff[$column['column_name']] = ['column_name' => $column['column_name'], |
|
| 198 | + 'data_table_type' => null, |
|
| 199 | + 'audit_table_type' => null, |
|
| 200 | + 'config_type' => $column['column_type']]; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | foreach ($auditColumns->getColumns() as $column) |
| 204 | 204 | { |
| 205 | - $config_type = isset($diff[$column['column_name']]) ? $diff[$column['column_name']]['config_type'] : null; |
|
| 205 | + $config_type = isset($diff[$column['column_name']]) ? $diff[$column['column_name']]['config_type'] : null; |
|
| 206 | 206 | |
| 207 | - $diff[$column['column_name']] = ['column_name' => $column['column_name'], |
|
| 208 | - 'data_table_type' => null, |
|
| 209 | - 'audit_table_type' => $auditColumns->getColumnTypeWithCharSetCollation($column['column_name']), |
|
| 210 | - 'config_type' => $config_type]; |
|
| 207 | + $diff[$column['column_name']] = ['column_name' => $column['column_name'], |
|
| 208 | + 'data_table_type' => null, |
|
| 209 | + 'audit_table_type' => $auditColumns->getColumnTypeWithCharSetCollation($column['column_name']), |
|
| 210 | + 'config_type' => $config_type]; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | foreach ($dataColumns->getColumns() as $column) |
| 214 | 214 | { |
| 215 | - $config_type = isset($diff[$column['column_name']]) ? $diff[$column['column_name']]['config_type'] : null; |
|
| 216 | - $audit_table_type = isset($diff[$column['column_name']]) ? $diff[$column['column_name']]['audit_table_type'] : null; |
|
| 215 | + $config_type = isset($diff[$column['column_name']]) ? $diff[$column['column_name']]['config_type'] : null; |
|
| 216 | + $audit_table_type = isset($diff[$column['column_name']]) ? $diff[$column['column_name']]['audit_table_type'] : null; |
|
| 217 | 217 | |
| 218 | - $diff[$column['column_name']] = ['column_name' => $column['column_name'], |
|
| 219 | - 'data_table_type' => $dataColumns->getColumnTypeWithCharSetCollation($column['column_name']), |
|
| 220 | - 'audit_table_type' => $audit_table_type, |
|
| 221 | - 'config_type' => $config_type]; |
|
| 218 | + $diff[$column['column_name']] = ['column_name' => $column['column_name'], |
|
| 219 | + 'data_table_type' => $dataColumns->getColumnTypeWithCharSetCollation($column['column_name']), |
|
| 220 | + 'audit_table_type' => $audit_table_type, |
|
| 221 | + 'config_type' => $config_type]; |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | return $diff; |
| 225 | - } |
|
| 226 | - |
|
| 227 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 228 | - /** |
|
| 229 | - * Computes the difference between data and audit tables. |
|
| 230 | - */ |
|
| 231 | - private function getDiff() |
|
| 232 | - { |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 228 | + /** |
|
| 229 | + * Computes the difference between data and audit tables. |
|
| 230 | + */ |
|
| 231 | + private function getDiff() |
|
| 232 | + { |
|
| 233 | 233 | foreach ($this->dataSchemaTables as $table) |
| 234 | 234 | { |
| 235 | - if ($this->config['tables'][$table['table_name']]['audit']) |
|
| 236 | - { |
|
| 235 | + if ($this->config['tables'][$table['table_name']]['audit']) |
|
| 236 | + { |
|
| 237 | 237 | $res = StaticDataLayer::searchInRowSet('table_name', $table['table_name'], $this->auditSchemaTables); |
| 238 | 238 | if (isset($res)) |
| 239 | 239 | { |
| 240 | - $dataColumns = new Columns(DataLayer::getTableColumns($this->config['database']['data_schema'], $table['table_name'])); |
|
| 241 | - $auditColumns = DataLayer::getTableColumns($this->config['database']['audit_schema'], $table['table_name']); |
|
| 242 | - $auditColumns = $this->addNotNull($auditColumns); |
|
| 243 | - $auditColumns = new Columns($auditColumns); |
|
| 240 | + $dataColumns = new Columns(DataLayer::getTableColumns($this->config['database']['data_schema'], $table['table_name'])); |
|
| 241 | + $auditColumns = DataLayer::getTableColumns($this->config['database']['audit_schema'], $table['table_name']); |
|
| 242 | + $auditColumns = $this->addNotNull($auditColumns); |
|
| 243 | + $auditColumns = new Columns($auditColumns); |
|
| 244 | 244 | |
| 245 | - $this->diffColumns[$table['table_name']] = $this->createDiffArray($dataColumns, $auditColumns); |
|
| 245 | + $this->diffColumns[$table['table_name']] = $this->createDiffArray($dataColumns, $auditColumns); |
|
| 246 | + } |
|
| 246 | 247 | } |
| 247 | - } |
|
| 248 | 248 | } |
| 249 | - } |
|
| 250 | - |
|
| 251 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 252 | - /** |
|
| 253 | - * Add not null to audit columns if it not nullable. |
|
| 254 | - * |
|
| 255 | - * @param array $theColumns Audit columns. |
|
| 256 | - * |
|
| 257 | - * @return array |
|
| 258 | - */ |
|
| 259 | - private function addNotNull($theColumns) |
|
| 260 | - { |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 252 | + /** |
|
| 253 | + * Add not null to audit columns if it not nullable. |
|
| 254 | + * |
|
| 255 | + * @param array $theColumns Audit columns. |
|
| 256 | + * |
|
| 257 | + * @return array |
|
| 258 | + */ |
|
| 259 | + private function addNotNull($theColumns) |
|
| 260 | + { |
|
| 261 | 261 | $modifiedColumns = []; |
| 262 | 262 | foreach ($theColumns as $column) |
| 263 | 263 | { |
| 264 | - $modifiedColumn = $column; |
|
| 265 | - $auditColumn = StaticDataLayer::searchInRowSet('column_name', $modifiedColumn['column_name'], $this->config['audit_columns']); |
|
| 266 | - if (isset($auditColumn)) |
|
| 267 | - { |
|
| 264 | + $modifiedColumn = $column; |
|
| 265 | + $auditColumn = StaticDataLayer::searchInRowSet('column_name', $modifiedColumn['column_name'], $this->config['audit_columns']); |
|
| 266 | + if (isset($auditColumn)) |
|
| 267 | + { |
|
| 268 | 268 | if ($modifiedColumn['is_nullable']==='NO') |
| 269 | 269 | { |
| 270 | - $modifiedColumn['column_type'] = sprintf('%s not null', $modifiedColumn['column_type']); |
|
| 270 | + $modifiedColumn['column_type'] = sprintf('%s not null', $modifiedColumn['column_type']); |
|
| 271 | + } |
|
| 271 | 272 | } |
| 272 | - } |
|
| 273 | - $modifiedColumns[] = $modifiedColumn; |
|
| 273 | + $modifiedColumns[] = $modifiedColumn; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | return $modifiedColumns; |
| 277 | - } |
|
| 278 | - |
|
| 279 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 280 | - /** |
|
| 281 | - * Writes the difference between the audit tables and metadata tables to the output. |
|
| 282 | - * |
|
| 283 | - * @param OutputInterface $output The output. |
|
| 284 | - */ |
|
| 285 | - private function diffTables($output) |
|
| 286 | - { |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 280 | + /** |
|
| 281 | + * Writes the difference between the audit tables and metadata tables to the output. |
|
| 282 | + * |
|
| 283 | + * @param OutputInterface $output The output. |
|
| 284 | + */ |
|
| 285 | + private function diffTables($output) |
|
| 286 | + { |
|
| 287 | 287 | foreach ($this->config['tables'] as $tableName => $table) |
| 288 | 288 | { |
| 289 | - $res = StaticDataLayer::searchInRowSet('table_name', $tableName, $this->auditSchemaTables); |
|
| 290 | - if ($table['audit'] && !isset($res)) |
|
| 291 | - { |
|
| 289 | + $res = StaticDataLayer::searchInRowSet('table_name', $tableName, $this->auditSchemaTables); |
|
| 290 | + if ($table['audit'] && !isset($res)) |
|
| 291 | + { |
|
| 292 | 292 | $output->writeln(sprintf('<miss_table>%s</>', $tableName)); |
| 293 | - } |
|
| 294 | - else if (!$table['audit'] && isset($res)) |
|
| 295 | - { |
|
| 293 | + } |
|
| 294 | + else if (!$table['audit'] && isset($res)) |
|
| 295 | + { |
|
| 296 | 296 | $output->writeln(sprintf('<obsolete_table>%s</>', $tableName)); |
| 297 | - } |
|
| 297 | + } |
|
| 298 | + } |
|
| 298 | 299 | } |
| 299 | - } |
|
| 300 | - |
|
| 301 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 302 | - /** |
|
| 303 | - * Writes the difference between the audit and data tables to the output. |
|
| 304 | - * |
|
| 305 | - * @param OutputInterface $output The output. |
|
| 306 | - */ |
|
| 307 | - private function printDiff($output) |
|
| 308 | - { |
|
| 300 | + |
|
| 301 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 302 | + /** |
|
| 303 | + * Writes the difference between the audit and data tables to the output. |
|
| 304 | + * |
|
| 305 | + * @param OutputInterface $output The output. |
|
| 306 | + */ |
|
| 307 | + private function printDiff($output) |
|
| 308 | + { |
|
| 309 | 309 | $first = true; |
| 310 | 310 | if (isset($this->diffColumns)) |
| 311 | 311 | { |
| 312 | - foreach ($this->diffColumns as $tableName => $columns) |
|
| 313 | - { |
|
| 312 | + foreach ($this->diffColumns as $tableName => $columns) |
|
| 313 | + { |
|
| 314 | 314 | // Remove matching columns unless the full option is used. |
| 315 | 315 | if (!$this->full) |
| 316 | 316 | { |
| 317 | - $columns = self::removeMatchingColumns($columns); |
|
| 317 | + $columns = self::removeMatchingColumns($columns); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | if (!empty($columns)) |
| 321 | 321 | { |
| 322 | - // Add an empty line between tables. |
|
| 323 | - if ($first) |
|
| 324 | - { |
|
| 322 | + // Add an empty line between tables. |
|
| 323 | + if ($first) |
|
| 324 | + { |
|
| 325 | 325 | $first = false; |
| 326 | - } |
|
| 327 | - else |
|
| 328 | - { |
|
| 326 | + } |
|
| 327 | + else |
|
| 328 | + { |
|
| 329 | 329 | $output->writeln(''); |
| 330 | - } |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - // Write table name. |
|
| 333 | - $output->writeln($tableName); |
|
| 332 | + // Write table name. |
|
| 333 | + $output->writeln($tableName); |
|
| 334 | 334 | |
| 335 | - // Write table with columns. |
|
| 336 | - $columns = $this->addHighlighting($columns); |
|
| 337 | - $rows = new TableHelper($this->config['database']['data_schema'], $this->config['database']['audit_schema'], $tableName); |
|
| 338 | - $rows->appendRows($columns); |
|
| 339 | - $table = new Table($output); |
|
| 340 | - $table->setHeaders(['column', 'data table', 'audit table', 'config']) |
|
| 335 | + // Write table with columns. |
|
| 336 | + $columns = $this->addHighlighting($columns); |
|
| 337 | + $rows = new TableHelper($this->config['database']['data_schema'], $this->config['database']['audit_schema'], $tableName); |
|
| 338 | + $rows->appendRows($columns); |
|
| 339 | + $table = new Table($output); |
|
| 340 | + $table->setHeaders(['column', 'data table', 'audit table', 'config']) |
|
| 341 | 341 | ->setRows($rows->getRows()); |
| 342 | - $table->render(); |
|
| 342 | + $table->render(); |
|
| 343 | + } |
|
| 343 | 344 | } |
| 344 | - } |
|
| 345 | 345 | } |
| 346 | 346 | $this->diffTables($output); |
| 347 | - } |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 349 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | //---------------------------------------------------------------------------------------------------------------------- |
@@ -11,86 +11,86 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class TableHelper |
| 13 | 13 | { |
| 14 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 15 | - /** |
|
| 16 | - * Array with rows for table. |
|
| 17 | - * |
|
| 18 | - * @var \array[] |
|
| 19 | - */ |
|
| 20 | - private $rows = []; |
|
| 14 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 15 | + /** |
|
| 16 | + * Array with rows for table. |
|
| 17 | + * |
|
| 18 | + * @var \array[] |
|
| 19 | + */ |
|
| 20 | + private $rows = []; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Table options from audit schema. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - private $auditTableOptions; |
|
| 22 | + /** |
|
| 23 | + * Table options from audit schema. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + private $auditTableOptions; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Table options from data schema. |
|
| 31 | - * |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - private $dataTableOptions; |
|
| 29 | + /** |
|
| 30 | + * Table options from data schema. |
|
| 31 | + * |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + private $dataTableOptions; |
|
| 35 | 35 | |
| 36 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 37 | - /** |
|
| 38 | - * Object constructor. |
|
| 39 | - * |
|
| 40 | - * @param string $dataSchema Data schema name. |
|
| 41 | - * @param string $auditSchema Audit schema name. |
|
| 42 | - * @param string $tableName The table name. |
|
| 43 | - */ |
|
| 44 | - public function __construct($dataSchema, $auditSchema, $tableName) |
|
| 45 | - { |
|
| 36 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 37 | + /** |
|
| 38 | + * Object constructor. |
|
| 39 | + * |
|
| 40 | + * @param string $dataSchema Data schema name. |
|
| 41 | + * @param string $auditSchema Audit schema name. |
|
| 42 | + * @param string $tableName The table name. |
|
| 43 | + */ |
|
| 44 | + public function __construct($dataSchema, $auditSchema, $tableName) |
|
| 45 | + { |
|
| 46 | 46 | $this->auditTableOptions = DataLayer::getTableOptions($auditSchema, $tableName); |
| 47 | 47 | $this->dataTableOptions = DataLayer::getTableOptions($dataSchema, $tableName); |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 51 | - /** |
|
| 52 | - * Append row with table option. |
|
| 53 | - * |
|
| 54 | - * @param string $theOption |
|
| 55 | - */ |
|
| 56 | - public function appendTableOption($theOption) |
|
| 57 | - { |
|
| 50 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 51 | + /** |
|
| 52 | + * Append row with table option. |
|
| 53 | + * |
|
| 54 | + * @param string $theOption |
|
| 55 | + */ |
|
| 56 | + public function appendTableOption($theOption) |
|
| 57 | + { |
|
| 58 | 58 | $this->rows[$theOption] = ['column_name' => $theOption, |
| 59 | - 'data_table_type' => $this->dataTableOptions[$theOption], |
|
| 60 | - 'audit_table_type' => $this->auditTableOptions[$theOption], |
|
| 61 | - 'config_type' => null]; |
|
| 62 | - } |
|
| 59 | + 'data_table_type' => $this->dataTableOptions[$theOption], |
|
| 60 | + 'audit_table_type' => $this->auditTableOptions[$theOption], |
|
| 61 | + 'config_type' => null]; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 65 | - /** |
|
| 66 | - * Appends rows. |
|
| 67 | - * |
|
| 68 | - * @param \array[] $theRows |
|
| 69 | - */ |
|
| 70 | - public function appendRows($theRows) |
|
| 71 | - { |
|
| 64 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 65 | + /** |
|
| 66 | + * Appends rows. |
|
| 67 | + * |
|
| 68 | + * @param \array[] $theRows |
|
| 69 | + */ |
|
| 70 | + public function appendRows($theRows) |
|
| 71 | + { |
|
| 72 | 72 | foreach ($theRows as $row) |
| 73 | 73 | { |
| 74 | - $this->rows[] = $row; |
|
| 74 | + $this->rows[] = $row; |
|
| 75 | 75 | } |
| 76 | 76 | $this->rows[] = new TableSeparator(); |
| 77 | 77 | $this->appendTableOption('engine'); |
| 78 | 78 | $this->appendTableOption('character_set_name'); |
| 79 | - } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 82 | - /** |
|
| 83 | - * Get rows. |
|
| 84 | - * |
|
| 85 | - * @return \array[] |
|
| 86 | - */ |
|
| 87 | - public function getRows() |
|
| 88 | - { |
|
| 81 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 82 | + /** |
|
| 83 | + * Get rows. |
|
| 84 | + * |
|
| 85 | + * @return \array[] |
|
| 86 | + */ |
|
| 87 | + public function getRows() |
|
| 88 | + { |
|
| 89 | 89 | return $this->rows; |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | 92 | |
| 93 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 93 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | //---------------------------------------------------------------------------------------------------------------------- |