@@ -36,7 +36,7 @@ |
||
| 36 | 36 | * |
| 37 | 37 | * @param string $auditSchemaName The name of audit schema. |
| 38 | 38 | * @param string $tableName The name of the table. |
| 39 | - * @param array[] $columns The metadata of the new columns. |
|
| 39 | + * @param Columns $columns The metadata of the new columns. |
|
| 40 | 40 | */ |
| 41 | 41 | public static function addNewColumns($auditSchemaName, $tableName, $columns) |
| 42 | 42 | { |
@@ -15,90 +15,90 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class DataLayer |
| 17 | 17 | { |
| 18 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 19 | - /** |
|
| 20 | - * The connection to the MySQL instance. |
|
| 21 | - * |
|
| 22 | - * @var StaticDataLayer |
|
| 23 | - */ |
|
| 24 | - private static $dl; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * The Output decorator. |
|
| 28 | - * |
|
| 29 | - * @var StratumStyle |
|
| 30 | - */ |
|
| 31 | - private static $io; |
|
| 32 | - |
|
| 33 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 34 | - /** |
|
| 35 | - * Adds new columns to an audit table. |
|
| 36 | - * |
|
| 37 | - * @param string $auditSchemaName The name of audit schema. |
|
| 38 | - * @param string $tableName The name of the table. |
|
| 39 | - * @param array[] $columns The metadata of the new columns. |
|
| 40 | - */ |
|
| 41 | - public static function addNewColumns($auditSchemaName, $tableName, $columns) |
|
| 42 | - { |
|
| 18 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 19 | + /** |
|
| 20 | + * The connection to the MySQL instance. |
|
| 21 | + * |
|
| 22 | + * @var StaticDataLayer |
|
| 23 | + */ |
|
| 24 | + private static $dl; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * The Output decorator. |
|
| 28 | + * |
|
| 29 | + * @var StratumStyle |
|
| 30 | + */ |
|
| 31 | + private static $io; |
|
| 32 | + |
|
| 33 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 34 | + /** |
|
| 35 | + * Adds new columns to an audit table. |
|
| 36 | + * |
|
| 37 | + * @param string $auditSchemaName The name of audit schema. |
|
| 38 | + * @param string $tableName The name of the table. |
|
| 39 | + * @param array[] $columns The metadata of the new columns. |
|
| 40 | + */ |
|
| 41 | + public static function addNewColumns($auditSchemaName, $tableName, $columns) |
|
| 42 | + { |
|
| 43 | 43 | $helper = new AlterAuditTableAddColumns($auditSchemaName, $tableName, $columns); |
| 44 | 44 | $sql = $helper->buildStatement(); |
| 45 | 45 | |
| 46 | 46 | self::executeNone($sql); |
| 47 | - } |
|
| 48 | - |
|
| 49 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 50 | - /** |
|
| 51 | - * Connects to a MySQL instance. |
|
| 52 | - * |
|
| 53 | - * Wrapper around [mysqli::__construct](http://php.net/manual/mysqli.construct.php), however on failure an exception |
|
| 54 | - * is thrown. |
|
| 55 | - * |
|
| 56 | - * @param string $host The hostname. |
|
| 57 | - * @param string $user The MySQL user name. |
|
| 58 | - * @param string $passWord The password. |
|
| 59 | - * @param string $database The default database. |
|
| 60 | - * @param int $port The port number. |
|
| 61 | - */ |
|
| 62 | - public static function connect($host, $user, $passWord, $database, $port = 3306) |
|
| 63 | - { |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 50 | + /** |
|
| 51 | + * Connects to a MySQL instance. |
|
| 52 | + * |
|
| 53 | + * Wrapper around [mysqli::__construct](http://php.net/manual/mysqli.construct.php), however on failure an exception |
|
| 54 | + * is thrown. |
|
| 55 | + * |
|
| 56 | + * @param string $host The hostname. |
|
| 57 | + * @param string $user The MySQL user name. |
|
| 58 | + * @param string $passWord The password. |
|
| 59 | + * @param string $database The default database. |
|
| 60 | + * @param int $port The port number. |
|
| 61 | + */ |
|
| 62 | + public static function connect($host, $user, $passWord, $database, $port = 3306) |
|
| 63 | + { |
|
| 64 | 64 | self::$dl = new StaticDataLayer(); |
| 65 | 65 | |
| 66 | 66 | self::$dl->connect($host, $user, $passWord, $database, $port); |
| 67 | - } |
|
| 68 | - |
|
| 69 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 70 | - /** |
|
| 71 | - * Creates an audit table. |
|
| 72 | - * |
|
| 73 | - * @param string $dataSchemaName The name of the data schema. |
|
| 74 | - * @param string $auditSchemaName The name of the audit schema. |
|
| 75 | - * @param string $tableName The name of the table. |
|
| 76 | - * @param Columns $columns The metadata of the columns of the audit table (i.e. the audit columns and columns |
|
| 77 | - * of the data table). |
|
| 78 | - */ |
|
| 79 | - public static function createAuditTable($dataSchemaName, $auditSchemaName, $tableName, $columns) |
|
| 80 | - { |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 70 | + /** |
|
| 71 | + * Creates an audit table. |
|
| 72 | + * |
|
| 73 | + * @param string $dataSchemaName The name of the data schema. |
|
| 74 | + * @param string $auditSchemaName The name of the audit schema. |
|
| 75 | + * @param string $tableName The name of the table. |
|
| 76 | + * @param Columns $columns The metadata of the columns of the audit table (i.e. the audit columns and columns |
|
| 77 | + * of the data table). |
|
| 78 | + */ |
|
| 79 | + public static function createAuditTable($dataSchemaName, $auditSchemaName, $tableName, $columns) |
|
| 80 | + { |
|
| 81 | 81 | $helper = new CreateAuditTable($dataSchemaName, $auditSchemaName, $tableName, $columns); |
| 82 | 82 | $sql = $helper->buildStatement(); |
| 83 | 83 | |
| 84 | 84 | self::executeNone($sql); |
| 85 | - } |
|
| 86 | - |
|
| 87 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 88 | - /** |
|
| 89 | - * Creates a trigger on a table. |
|
| 90 | - * |
|
| 91 | - * @param string $dataSchemaName The name of the data schema. |
|
| 92 | - * @param string $auditSchemaName The name of the audit schema. |
|
| 93 | - * @param string $tableName The name of the table. |
|
| 94 | - * @param string $triggerAction The trigger action (i.e. INSERT, UPDATE, or DELETE). |
|
| 95 | - * @param string $triggerName The name of the trigger. |
|
| 96 | - * @param Columns $tableColumns The data table columns. |
|
| 97 | - * @param Columns $auditColumns The audit table columns. |
|
| 98 | - * @param string $skipVariable The skip variable. |
|
| 99 | - * @param string[] $additionSql Additional SQL statements. |
|
| 100 | - */ |
|
| 101 | - public static function createAuditTrigger($dataSchemaName, |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 88 | + /** |
|
| 89 | + * Creates a trigger on a table. |
|
| 90 | + * |
|
| 91 | + * @param string $dataSchemaName The name of the data schema. |
|
| 92 | + * @param string $auditSchemaName The name of the audit schema. |
|
| 93 | + * @param string $tableName The name of the table. |
|
| 94 | + * @param string $triggerAction The trigger action (i.e. INSERT, UPDATE, or DELETE). |
|
| 95 | + * @param string $triggerName The name of the trigger. |
|
| 96 | + * @param Columns $tableColumns The data table columns. |
|
| 97 | + * @param Columns $auditColumns The audit table columns. |
|
| 98 | + * @param string $skipVariable The skip variable. |
|
| 99 | + * @param string[] $additionSql Additional SQL statements. |
|
| 100 | + */ |
|
| 101 | + public static function createAuditTrigger($dataSchemaName, |
|
| 102 | 102 | $auditSchemaName, |
| 103 | 103 | $tableName, |
| 104 | 104 | $triggerAction, |
@@ -107,151 +107,151 @@ discard block |
||
| 107 | 107 | $auditColumns, |
| 108 | 108 | $skipVariable, |
| 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); |
| 123 | - } |
|
| 124 | - |
|
| 125 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 126 | - /** |
|
| 127 | - * Closes the connection to the MySQL instance, if connected. |
|
| 128 | - */ |
|
| 129 | - public static function disconnect() |
|
| 130 | - { |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 126 | + /** |
|
| 127 | + * Closes the connection to the MySQL instance, if connected. |
|
| 128 | + */ |
|
| 129 | + public static function disconnect() |
|
| 130 | + { |
|
| 131 | 131 | if (self::$dl!==null) |
| 132 | 132 | { |
| 133 | - self::$dl->disconnect(); |
|
| 134 | - self::$dl = null; |
|
| 133 | + self::$dl->disconnect(); |
|
| 134 | + self::$dl = null; |
|
| 135 | + } |
|
| 135 | 136 | } |
| 136 | - } |
|
| 137 | - |
|
| 138 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 139 | - /** |
|
| 140 | - * Drops a trigger. |
|
| 141 | - * |
|
| 142 | - * @param string $triggerSchema The name of the trigger schema. |
|
| 143 | - * @param string $triggerName The mame of trigger. |
|
| 144 | - */ |
|
| 145 | - public static function dropTrigger($triggerSchema, $triggerName) |
|
| 146 | - { |
|
| 137 | + |
|
| 138 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 139 | + /** |
|
| 140 | + * Drops a trigger. |
|
| 141 | + * |
|
| 142 | + * @param string $triggerSchema The name of the trigger schema. |
|
| 143 | + * @param string $triggerName The mame of trigger. |
|
| 144 | + */ |
|
| 145 | + public static function dropTrigger($triggerSchema, $triggerName) |
|
| 146 | + { |
|
| 147 | 147 | $sql = sprintf('drop trigger `%s`.`%s`', $triggerSchema, $triggerName); |
| 148 | 148 | |
| 149 | 149 | self::executeNone($sql); |
| 150 | - } |
|
| 151 | - |
|
| 152 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 153 | - /** |
|
| 154 | - * @param string $query The SQL statement. |
|
| 155 | - * |
|
| 156 | - * @return int The number of affected rows (if any). |
|
| 157 | - */ |
|
| 158 | - public static function executeNone($query) |
|
| 159 | - { |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 153 | + /** |
|
| 154 | + * @param string $query The SQL statement. |
|
| 155 | + * |
|
| 156 | + * @return int The number of affected rows (if any). |
|
| 157 | + */ |
|
| 158 | + public static function executeNone($query) |
|
| 159 | + { |
|
| 160 | 160 | self::logQuery($query); |
| 161 | 161 | |
| 162 | 162 | return self::$dl->executeNone($query); |
| 163 | - } |
|
| 164 | - |
|
| 165 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 166 | - /** |
|
| 167 | - * Executes a query that returns 0 or 1 row. |
|
| 168 | - * Throws an exception if the query selects 2 or more rows. |
|
| 169 | - * |
|
| 170 | - * @param string $query The SQL statement. |
|
| 171 | - * |
|
| 172 | - * @return array|null The selected row. |
|
| 173 | - */ |
|
| 174 | - public static function executeRow0($query) |
|
| 175 | - { |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 166 | + /** |
|
| 167 | + * Executes a query that returns 0 or 1 row. |
|
| 168 | + * Throws an exception if the query selects 2 or more rows. |
|
| 169 | + * |
|
| 170 | + * @param string $query The SQL statement. |
|
| 171 | + * |
|
| 172 | + * @return array|null The selected row. |
|
| 173 | + */ |
|
| 174 | + public static function executeRow0($query) |
|
| 175 | + { |
|
| 176 | 176 | self::logQuery($query); |
| 177 | 177 | |
| 178 | 178 | return self::$dl->executeRow0($query); |
| 179 | - } |
|
| 180 | - |
|
| 181 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 182 | - /** |
|
| 183 | - * Executes a query that returns 1 and only 1 row. |
|
| 184 | - * Throws an exception if the query selects none, 2 or more rows. |
|
| 185 | - * |
|
| 186 | - * @param string $query The SQL statement. |
|
| 187 | - * |
|
| 188 | - * @return array The selected row. |
|
| 189 | - */ |
|
| 190 | - public static function executeRow1($query) |
|
| 191 | - { |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 182 | + /** |
|
| 183 | + * Executes a query that returns 1 and only 1 row. |
|
| 184 | + * Throws an exception if the query selects none, 2 or more rows. |
|
| 185 | + * |
|
| 186 | + * @param string $query The SQL statement. |
|
| 187 | + * |
|
| 188 | + * @return array The selected row. |
|
| 189 | + */ |
|
| 190 | + public static function executeRow1($query) |
|
| 191 | + { |
|
| 192 | 192 | self::logQuery($query); |
| 193 | 193 | |
| 194 | 194 | return self::$dl->executeRow1($query); |
| 195 | - } |
|
| 196 | - |
|
| 197 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 198 | - /** |
|
| 199 | - * Executes a query that returns 0 or more rows. |
|
| 200 | - * |
|
| 201 | - * @param string $query The SQL statement. |
|
| 202 | - * |
|
| 203 | - * @return \array[] |
|
| 204 | - */ |
|
| 205 | - public static function executeRows($query) |
|
| 206 | - { |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 198 | + /** |
|
| 199 | + * Executes a query that returns 0 or more rows. |
|
| 200 | + * |
|
| 201 | + * @param string $query The SQL statement. |
|
| 202 | + * |
|
| 203 | + * @return \array[] |
|
| 204 | + */ |
|
| 205 | + public static function executeRows($query) |
|
| 206 | + { |
|
| 207 | 207 | self::logQuery($query); |
| 208 | 208 | |
| 209 | 209 | return self::$dl->executeRows($query); |
| 210 | - } |
|
| 211 | - |
|
| 212 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 213 | - /** |
|
| 214 | - * Executes a query that returns 0 or 1 row. |
|
| 215 | - * Throws an exception if the query selects 2 or more rows. |
|
| 216 | - * |
|
| 217 | - * @param string $query The SQL statement. |
|
| 218 | - * |
|
| 219 | - * @return int|string|null The selected row. |
|
| 220 | - */ |
|
| 221 | - public static function executeSingleton0($query) |
|
| 222 | - { |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 213 | + /** |
|
| 214 | + * Executes a query that returns 0 or 1 row. |
|
| 215 | + * Throws an exception if the query selects 2 or more rows. |
|
| 216 | + * |
|
| 217 | + * @param string $query The SQL statement. |
|
| 218 | + * |
|
| 219 | + * @return int|string|null The selected row. |
|
| 220 | + */ |
|
| 221 | + public static function executeSingleton0($query) |
|
| 222 | + { |
|
| 223 | 223 | self::logQuery($query); |
| 224 | 224 | |
| 225 | 225 | return self::$dl->executeSingleton0($query); |
| 226 | - } |
|
| 227 | - |
|
| 228 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 229 | - /** |
|
| 230 | - * Executes a query that returns 1 and only 1 row with 1 column. |
|
| 231 | - * Throws an exception if the query selects none, 2 or more rows. |
|
| 232 | - * |
|
| 233 | - * @param string $query The SQL statement. |
|
| 234 | - * |
|
| 235 | - * @return int|string The selected row. |
|
| 236 | - */ |
|
| 237 | - public static function executeSingleton1($query) |
|
| 238 | - { |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 229 | + /** |
|
| 230 | + * Executes a query that returns 1 and only 1 row with 1 column. |
|
| 231 | + * Throws an exception if the query selects none, 2 or more rows. |
|
| 232 | + * |
|
| 233 | + * @param string $query The SQL statement. |
|
| 234 | + * |
|
| 235 | + * @return int|string The selected row. |
|
| 236 | + */ |
|
| 237 | + public static function executeSingleton1($query) |
|
| 238 | + { |
|
| 239 | 239 | self::logQuery($query); |
| 240 | 240 | |
| 241 | 241 | return self::$dl->executeSingleton1($query); |
| 242 | - } |
|
| 243 | - |
|
| 244 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 245 | - /** |
|
| 246 | - * Selects metadata of all columns of table. |
|
| 247 | - * |
|
| 248 | - * @param string $schemaName The name of the table schema. |
|
| 249 | - * @param string $tableName The name of the table. |
|
| 250 | - * |
|
| 251 | - * @return \array[] |
|
| 252 | - */ |
|
| 253 | - public static function getTableColumns($schemaName, $tableName) |
|
| 254 | - { |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 245 | + /** |
|
| 246 | + * Selects metadata of all columns of table. |
|
| 247 | + * |
|
| 248 | + * @param string $schemaName The name of the table schema. |
|
| 249 | + * @param string $tableName The name of the table. |
|
| 250 | + * |
|
| 251 | + * @return \array[] |
|
| 252 | + */ |
|
| 253 | + public static function getTableColumns($schemaName, $tableName) |
|
| 254 | + { |
|
| 255 | 255 | $sql = sprintf(' |
| 256 | 256 | select COLUMN_NAME as column_name |
| 257 | 257 | , COLUMN_TYPE as column_type |
@@ -262,23 +262,23 @@ discard block |
||
| 262 | 262 | where TABLE_SCHEMA = %s |
| 263 | 263 | and TABLE_NAME = %s |
| 264 | 264 | order by ORDINAL_POSITION', |
| 265 | - self::$dl->quoteString($schemaName), |
|
| 266 | - self::$dl->quoteString($tableName)); |
|
| 265 | + self::$dl->quoteString($schemaName), |
|
| 266 | + self::$dl->quoteString($tableName)); |
|
| 267 | 267 | |
| 268 | 268 | return self::$dl->executeRows($sql); |
| 269 | - } |
|
| 270 | - |
|
| 271 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 272 | - /** |
|
| 273 | - * Selects table engine, character_set_name and table_collation. |
|
| 274 | - * |
|
| 275 | - * @param string $schemaName The name of the table schema. |
|
| 276 | - * @param string $tableName The name of the table. |
|
| 277 | - * |
|
| 278 | - * @return array |
|
| 279 | - */ |
|
| 280 | - public static function getTableOptions($schemaName, $tableName) |
|
| 281 | - { |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 272 | + /** |
|
| 273 | + * Selects table engine, character_set_name and table_collation. |
|
| 274 | + * |
|
| 275 | + * @param string $schemaName The name of the table schema. |
|
| 276 | + * @param string $tableName The name of the table. |
|
| 277 | + * |
|
| 278 | + * @return array |
|
| 279 | + */ |
|
| 280 | + public static function getTableOptions($schemaName, $tableName) |
|
| 281 | + { |
|
| 282 | 282 | $sql = sprintf(' |
| 283 | 283 | SELECT t1.TABLE_COLLATION as table_collation |
| 284 | 284 | , t1.ENGINE as engine |
@@ -287,45 +287,45 @@ discard block |
||
| 287 | 287 | inner join information_schema.COLLATION_CHARACTER_SET_APPLICABILITY t2 on t2.COLLATION_NAME = t1.TABLE_COLLATION |
| 288 | 288 | WHERE t1.TABLE_SCHEMA = %s |
| 289 | 289 | AND t1.TABLE_NAME = %s', |
| 290 | - self::$dl->quoteString($schemaName), |
|
| 291 | - self::$dl->quoteString($tableName)); |
|
| 290 | + self::$dl->quoteString($schemaName), |
|
| 291 | + self::$dl->quoteString($tableName)); |
|
| 292 | 292 | |
| 293 | 293 | return self::$dl->executeRow1($sql); |
| 294 | - } |
|
| 295 | - |
|
| 296 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 297 | - /** |
|
| 298 | - * Selects all triggers on a table. |
|
| 299 | - * |
|
| 300 | - * @param string $schemaName The name of the table schema. |
|
| 301 | - * @param string $tableName The name of the table. |
|
| 302 | - * |
|
| 303 | - * @return \array[] |
|
| 304 | - */ |
|
| 305 | - public static function getTableTriggers($schemaName, $tableName) |
|
| 306 | - { |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 297 | + /** |
|
| 298 | + * Selects all triggers on a table. |
|
| 299 | + * |
|
| 300 | + * @param string $schemaName The name of the table schema. |
|
| 301 | + * @param string $tableName The name of the table. |
|
| 302 | + * |
|
| 303 | + * @return \array[] |
|
| 304 | + */ |
|
| 305 | + public static function getTableTriggers($schemaName, $tableName) |
|
| 306 | + { |
|
| 307 | 307 | $sql = sprintf(' |
| 308 | 308 | select Trigger_Name as trigger_name |
| 309 | 309 | from information_schema.TRIGGERS |
| 310 | 310 | where TRIGGER_SCHEMA = %s |
| 311 | 311 | and EVENT_OBJECT_TABLE = %s |
| 312 | 312 | order by Trigger_Name', |
| 313 | - self::$dl->quoteString($schemaName), |
|
| 314 | - self::$dl->quoteString($tableName)); |
|
| 313 | + self::$dl->quoteString($schemaName), |
|
| 314 | + self::$dl->quoteString($tableName)); |
|
| 315 | 315 | |
| 316 | 316 | return self::$dl->executeRows($sql); |
| 317 | - } |
|
| 318 | - |
|
| 319 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 320 | - /** |
|
| 321 | - * Selects all table names in a schema. |
|
| 322 | - * |
|
| 323 | - * @param string $schemaName The name of the schema. |
|
| 324 | - * |
|
| 325 | - * @return \array[] |
|
| 326 | - */ |
|
| 327 | - public static function getTablesNames($schemaName) |
|
| 328 | - { |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 320 | + /** |
|
| 321 | + * Selects all table names in a schema. |
|
| 322 | + * |
|
| 323 | + * @param string $schemaName The name of the schema. |
|
| 324 | + * |
|
| 325 | + * @return \array[] |
|
| 326 | + */ |
|
| 327 | + public static function getTablesNames($schemaName) |
|
| 328 | + { |
|
| 329 | 329 | $sql = sprintf(" |
| 330 | 330 | select TABLE_NAME as table_name |
| 331 | 331 | from information_schema.TABLES |
@@ -334,67 +334,67 @@ discard block |
||
| 334 | 334 | order by TABLE_NAME", self::$dl->quoteString($schemaName)); |
| 335 | 335 | |
| 336 | 336 | return self::$dl->executeRows($sql); |
| 337 | - } |
|
| 338 | - |
|
| 339 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 340 | - /** |
|
| 341 | - * Acquires a write lock on a table. |
|
| 342 | - * |
|
| 343 | - * @param string $tableName The table name. |
|
| 344 | - */ |
|
| 345 | - public static function lockTable($tableName) |
|
| 346 | - { |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 340 | + /** |
|
| 341 | + * Acquires a write lock on a table. |
|
| 342 | + * |
|
| 343 | + * @param string $tableName The table name. |
|
| 344 | + */ |
|
| 345 | + public static function lockTable($tableName) |
|
| 346 | + { |
|
| 347 | 347 | $sql = sprintf('lock tables `%s` write', $tableName); |
| 348 | 348 | |
| 349 | 349 | self::$dl->executeNone($sql); |
| 350 | - } |
|
| 351 | - |
|
| 352 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 353 | - /** |
|
| 354 | - * Sets the Output decorator. |
|
| 355 | - * |
|
| 356 | - * @param StratumStyle $io The Output decorator. |
|
| 357 | - */ |
|
| 358 | - public static function setIo($io) |
|
| 359 | - { |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 353 | + /** |
|
| 354 | + * Sets the Output decorator. |
|
| 355 | + * |
|
| 356 | + * @param StratumStyle $io The Output decorator. |
|
| 357 | + */ |
|
| 358 | + public static function setIo($io) |
|
| 359 | + { |
|
| 360 | 360 | self::$io = $io; |
| 361 | - } |
|
| 362 | - |
|
| 363 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 364 | - /** |
|
| 365 | - * Releases all table locks. |
|
| 366 | - */ |
|
| 367 | - public static function unlockTables() |
|
| 368 | - { |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 364 | + /** |
|
| 365 | + * Releases all table locks. |
|
| 366 | + */ |
|
| 367 | + public static function unlockTables() |
|
| 368 | + { |
|
| 369 | 369 | $sql = 'unlock tables'; |
| 370 | 370 | |
| 371 | 371 | self::$dl->executeNone($sql); |
| 372 | - } |
|
| 373 | - |
|
| 374 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 375 | - /** |
|
| 376 | - * Logs the query on the console. |
|
| 377 | - * |
|
| 378 | - * @param string $query The query. |
|
| 379 | - */ |
|
| 380 | - private static function logQuery($query) |
|
| 381 | - { |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 375 | + /** |
|
| 376 | + * Logs the query on the console. |
|
| 377 | + * |
|
| 378 | + * @param string $query The query. |
|
| 379 | + */ |
|
| 380 | + private static function logQuery($query) |
|
| 381 | + { |
|
| 382 | 382 | $query = trim($query); |
| 383 | 383 | |
| 384 | 384 | if (strpos($query, "\n")!==false) |
| 385 | 385 | { |
| 386 | - // Query is a multi line query. |
|
| 387 | - self::$io->logVeryVerbose('Executing query:'); |
|
| 388 | - self::$io->logVeryVerbose('<sql>%s</sql>', $query); |
|
| 386 | + // Query is a multi line query. |
|
| 387 | + self::$io->logVeryVerbose('Executing query:'); |
|
| 388 | + self::$io->logVeryVerbose('<sql>%s</sql>', $query); |
|
| 389 | 389 | } |
| 390 | 390 | else |
| 391 | 391 | { |
| 392 | - // Query is a single line query. |
|
| 393 | - self::$io->logVeryVerbose('Executing query: <sql>%s</sql>', $query); |
|
| 392 | + // Query is a single line query. |
|
| 393 | + self::$io->logVeryVerbose('Executing query: <sql>%s</sql>', $query); |
|
| 394 | + } |
|
| 394 | 395 | } |
| 395 | - } |
|
| 396 | 396 | |
| 397 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 397 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | //---------------------------------------------------------------------------------------------------------------------- |
@@ -117,7 +117,7 @@ discard block |
||
| 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 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public static function disconnect() |
| 130 | 130 | { |
| 131 | - if (self::$dl!==null) |
|
| 131 | + if (self::$dl !== null) |
|
| 132 | 132 | { |
| 133 | 133 | self::$dl->disconnect(); |
| 134 | 134 | self::$dl = null; |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | { |
| 382 | 382 | $query = trim($query); |
| 383 | 383 | |
| 384 | - if (strpos($query, "\n")!==false) |
|
| 384 | + if (strpos($query, "\n") !== false) |
|
| 385 | 385 | { |
| 386 | 386 | // Query is a multi line query. |
| 387 | 387 | self::$io->logVeryVerbose('Executing query:'); |
@@ -386,8 +386,7 @@ |
||
| 386 | 386 | // Query is a multi line query. |
| 387 | 387 | self::$io->logVeryVerbose('Executing query:'); |
| 388 | 388 | self::$io->logVeryVerbose('<sql>%s</sql>', $query); |
| 389 | - } |
|
| 390 | - else |
|
| 389 | + } else |
|
| 391 | 390 | { |
| 392 | 391 | // Query is a single line query. |
| 393 | 392 | self::$io->logVeryVerbose('Executing query: <sql>%s</sql>', $query); |
@@ -8,164 +8,164 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Columns |
| 10 | 10 | { |
| 11 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 12 | - /** |
|
| 13 | - * The metadata of the columns. |
|
| 14 | - * |
|
| 15 | - * @var array[] |
|
| 16 | - */ |
|
| 17 | - private $columns = []; |
|
| 18 | - |
|
| 19 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 20 | - /** |
|
| 21 | - * Object constructor. |
|
| 22 | - * |
|
| 23 | - * @param array[] $columns The metadata of the columns. |
|
| 24 | - */ |
|
| 25 | - public function __construct($columns) |
|
| 26 | - { |
|
| 11 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 12 | + /** |
|
| 13 | + * The metadata of the columns. |
|
| 14 | + * |
|
| 15 | + * @var array[] |
|
| 16 | + */ |
|
| 17 | + private $columns = []; |
|
| 18 | + |
|
| 19 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 20 | + /** |
|
| 21 | + * Object constructor. |
|
| 22 | + * |
|
| 23 | + * @param array[] $columns The metadata of the columns. |
|
| 24 | + */ |
|
| 25 | + public function __construct($columns) |
|
| 26 | + { |
|
| 27 | 27 | foreach ($columns as $column) |
| 28 | 28 | { |
| 29 | - $this->columns[$column['column_name']] = [ |
|
| 29 | + $this->columns[$column['column_name']] = [ |
|
| 30 | 30 | 'column_name' => $column['column_name'], |
| 31 | 31 | 'column_type' => $column['column_type'], |
| 32 | 32 | 'character_set_name' => isset($column['character_set_name']) ? $column['character_set_name'] : null, |
| 33 | 33 | 'collation_name' => isset($column['collation_name']) ? $column['collation_name'] : null, |
| 34 | 34 | 'audit_expression' => isset($column['expression']) ? $column['expression'] : null, |
| 35 | 35 | 'audit_value_type' => isset($column['value_type']) ? $column['value_type'] : null |
| 36 | - ]; |
|
| 36 | + ]; |
|
| 37 | + } |
|
| 37 | 38 | } |
| 38 | - } |
|
| 39 | - |
|
| 40 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 41 | - /** |
|
| 42 | - * Generate array with audit columns and columns from data table. |
|
| 43 | - * |
|
| 44 | - * @param Columns $auditColumnsMetadata AuditApplication columns for adding to exist columns |
|
| 45 | - * @param Columns $currentColumnsMetadata Exist table columns |
|
| 46 | - * |
|
| 47 | - * @return Columns |
|
| 48 | - */ |
|
| 49 | - public static function combine($auditColumnsMetadata, $currentColumnsMetadata) |
|
| 50 | - { |
|
| 39 | + |
|
| 40 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 41 | + /** |
|
| 42 | + * Generate array with audit columns and columns from data table. |
|
| 43 | + * |
|
| 44 | + * @param Columns $auditColumnsMetadata AuditApplication columns for adding to exist columns |
|
| 45 | + * @param Columns $currentColumnsMetadata Exist table columns |
|
| 46 | + * |
|
| 47 | + * @return Columns |
|
| 48 | + */ |
|
| 49 | + public static function combine($auditColumnsMetadata, $currentColumnsMetadata) |
|
| 50 | + { |
|
| 51 | 51 | $columns = []; |
| 52 | 52 | |
| 53 | 53 | foreach ($auditColumnsMetadata->columns as $column) |
| 54 | 54 | { |
| 55 | - $columns[] = ['column_name' => $column['column_name'], |
|
| 55 | + $columns[] = ['column_name' => $column['column_name'], |
|
| 56 | 56 | 'column_type' => $column['column_type']]; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | foreach ($currentColumnsMetadata->columns as $column) |
| 60 | 60 | { |
| 61 | - if ($column['column_type']!='timestamp') |
|
| 62 | - { |
|
| 61 | + if ($column['column_type']!='timestamp') |
|
| 62 | + { |
|
| 63 | 63 | $columns[] = ['column_name' => $column['column_name'], |
| 64 | - 'column_type' => $column['column_type']]; |
|
| 65 | - } |
|
| 66 | - else |
|
| 67 | - { |
|
| 64 | + 'column_type' => $column['column_type']]; |
|
| 65 | + } |
|
| 66 | + else |
|
| 67 | + { |
|
| 68 | 68 | $columns[] = ['column_name' => $column['column_name'], |
| 69 | - 'column_type' => $column['column_type'].' NULL']; |
|
| 70 | - } |
|
| 69 | + 'column_type' => $column['column_type'].' NULL']; |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | return new Columns($columns); |
| 74 | - } |
|
| 75 | - |
|
| 76 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 77 | - /** |
|
| 78 | - * Compares two Columns objects and returns an array with columns that are in the first columns object and in the |
|
| 79 | - * second Columns object but have different types. |
|
| 80 | - * |
|
| 81 | - * @param Columns $columns1 The first Columns object. |
|
| 82 | - * @param Columns $columns2 The second Columns object. |
|
| 83 | - * |
|
| 84 | - * @return Columns |
|
| 85 | - */ |
|
| 86 | - public static function differentColumnTypes($columns1, $columns2) |
|
| 87 | - { |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 77 | + /** |
|
| 78 | + * Compares two Columns objects and returns an array with columns that are in the first columns object and in the |
|
| 79 | + * second Columns object but have different types. |
|
| 80 | + * |
|
| 81 | + * @param Columns $columns1 The first Columns object. |
|
| 82 | + * @param Columns $columns2 The second Columns object. |
|
| 83 | + * |
|
| 84 | + * @return Columns |
|
| 85 | + */ |
|
| 86 | + public static function differentColumnTypes($columns1, $columns2) |
|
| 87 | + { |
|
| 88 | 88 | $diff = []; |
| 89 | 89 | foreach ($columns2->columns as $column2) |
| 90 | 90 | { |
| 91 | - if (isset($columns1->columns[$column2['column_name']])) |
|
| 92 | - { |
|
| 91 | + if (isset($columns1->columns[$column2['column_name']])) |
|
| 92 | + { |
|
| 93 | 93 | $column1 = $columns1->columns[$column2['column_name']]; |
| 94 | 94 | if ($column2['column_type']!=$column1['column_type']) |
| 95 | 95 | { |
| 96 | - $diff[] = $column1; |
|
| 96 | + $diff[] = $column1; |
|
| 97 | + } |
|
| 97 | 98 | } |
| 98 | - } |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | return new Columns($diff); |
| 102 | - } |
|
| 103 | - |
|
| 104 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 105 | - /** |
|
| 106 | - * Compares two Columns objects and returns an array with columns that are in the first columns object but not in the |
|
| 107 | - * second Columns object. |
|
| 108 | - * |
|
| 109 | - * @param Columns $columns1 The first Columns object. |
|
| 110 | - * @param Columns $columns2 The second Columns object. |
|
| 111 | - * |
|
| 112 | - * @return Columns |
|
| 113 | - */ |
|
| 114 | - public static function notInOtherSet($columns1, $columns2) |
|
| 115 | - { |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 105 | + /** |
|
| 106 | + * Compares two Columns objects and returns an array with columns that are in the first columns object but not in the |
|
| 107 | + * second Columns object. |
|
| 108 | + * |
|
| 109 | + * @param Columns $columns1 The first Columns object. |
|
| 110 | + * @param Columns $columns2 The second Columns object. |
|
| 111 | + * |
|
| 112 | + * @return Columns |
|
| 113 | + */ |
|
| 114 | + public static function notInOtherSet($columns1, $columns2) |
|
| 115 | + { |
|
| 116 | 116 | $diff = []; |
| 117 | 117 | if (isset($columns1)) |
| 118 | 118 | { |
| 119 | - foreach ($columns1->columns as $column1) |
|
| 120 | - { |
|
| 119 | + foreach ($columns1->columns as $column1) |
|
| 120 | + { |
|
| 121 | 121 | if (!isset($columns2->columns[$column1['column_name']])) |
| 122 | 122 | { |
| 123 | - $diff[] = ['column_name' => $column1['column_name'], |
|
| 124 | - 'column_type' => $column1['column_type']]; |
|
| 123 | + $diff[] = ['column_name' => $column1['column_name'], |
|
| 124 | + 'column_type' => $column1['column_type']]; |
|
| 125 | + } |
|
| 125 | 126 | } |
| 126 | - } |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | return new Columns($diff); |
| 130 | - } |
|
| 131 | - |
|
| 132 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 133 | - /** |
|
| 134 | - * Returns the underlying array with metadata of the columns. |
|
| 135 | - * |
|
| 136 | - * @return array[] |
|
| 137 | - */ |
|
| 138 | - public function getColumns() |
|
| 139 | - { |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 133 | + /** |
|
| 134 | + * Returns the underlying array with metadata of the columns. |
|
| 135 | + * |
|
| 136 | + * @return array[] |
|
| 137 | + */ |
|
| 138 | + public function getColumns() |
|
| 139 | + { |
|
| 140 | 140 | return $this->columns; |
| 141 | - } |
|
| 142 | - |
|
| 143 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 144 | - /** |
|
| 145 | - * Return column type with character set and collation. |
|
| 146 | - * |
|
| 147 | - * @param string $columnName The column name. |
|
| 148 | - * |
|
| 149 | - * @return null|string |
|
| 150 | - */ |
|
| 151 | - public function getColumnTypeWithCharSetCollation($columnName) |
|
| 152 | - { |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 144 | + /** |
|
| 145 | + * Return column type with character set and collation. |
|
| 146 | + * |
|
| 147 | + * @param string $columnName The column name. |
|
| 148 | + * |
|
| 149 | + * @return null|string |
|
| 150 | + */ |
|
| 151 | + public function getColumnTypeWithCharSetCollation($columnName) |
|
| 152 | + { |
|
| 153 | 153 | $columns = array_keys($this->columns); |
| 154 | 154 | $key = array_search($columnName, $columns); |
| 155 | 155 | |
| 156 | 156 | if ($key!==false) |
| 157 | 157 | { |
| 158 | - $column = $this->columns[$columns[$key]]; |
|
| 159 | - $column['character_set_name'] = isset($column['character_set_name']) ? ' '.$column['character_set_name'] : ''; |
|
| 160 | - $column['collation_name'] = isset($column['collation_name']) ? ' '.$column['collation_name'] : ''; |
|
| 158 | + $column = $this->columns[$columns[$key]]; |
|
| 159 | + $column['character_set_name'] = isset($column['character_set_name']) ? ' '.$column['character_set_name'] : ''; |
|
| 160 | + $column['collation_name'] = isset($column['collation_name']) ? ' '.$column['collation_name'] : ''; |
|
| 161 | 161 | |
| 162 | - return sprintf('%s%s%s', $column['column_type'], $column['character_set_name'], $column['collation_name']); |
|
| 162 | + return sprintf('%s%s%s', $column['column_type'], $column['character_set_name'], $column['collation_name']); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | return null; |
| 166 | - } |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 168 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | //---------------------------------------------------------------------------------------------------------------------- |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | foreach ($currentColumnsMetadata->columns as $column) |
| 60 | 60 | { |
| 61 | - if ($column['column_type']!='timestamp') |
|
| 61 | + if ($column['column_type'] != 'timestamp') |
|
| 62 | 62 | { |
| 63 | 63 | $columns[] = ['column_name' => $column['column_name'], |
| 64 | 64 | 'column_type' => $column['column_type']]; |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | if (isset($columns1->columns[$column2['column_name']])) |
| 92 | 92 | { |
| 93 | 93 | $column1 = $columns1->columns[$column2['column_name']]; |
| 94 | - if ($column2['column_type']!=$column1['column_type']) |
|
| 94 | + if ($column2['column_type'] != $column1['column_type']) |
|
| 95 | 95 | { |
| 96 | 96 | $diff[] = $column1; |
| 97 | 97 | } |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | $columns = array_keys($this->columns); |
| 154 | 154 | $key = array_search($columnName, $columns); |
| 155 | 155 | |
| 156 | - if ($key!==false) |
|
| 156 | + if ($key !== false) |
|
| 157 | 157 | { |
| 158 | 158 | $column = $this->columns[$columns[$key]]; |
| 159 | 159 | $column['character_set_name'] = isset($column['character_set_name']) ? ' '.$column['character_set_name'] : ''; |
@@ -62,8 +62,7 @@ |
||
| 62 | 62 | { |
| 63 | 63 | $columns[] = ['column_name' => $column['column_name'], |
| 64 | 64 | 'column_type' => $column['column_type']]; |
| 65 | - } |
|
| 66 | - else |
|
| 65 | + } else |
|
| 67 | 66 | { |
| 68 | 67 | $columns[] = ['column_name' => $column['column_name'], |
| 69 | 68 | 'column_type' => $column['column_type'].' NULL']; |
@@ -20,70 +20,70 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class DiffCommand extends AuditCommand |
| 22 | 22 | { |
| 23 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 24 | - /** |
|
| 25 | - * Array with columns for each table. |
|
| 26 | - * array [ |
|
| 27 | - * table_name [ |
|
| 28 | - * column [ |
|
| 29 | - * data table type, |
|
| 30 | - * audit table type |
|
| 31 | - * ], |
|
| 32 | - * ... |
|
| 33 | - * ] |
|
| 34 | - * ] |
|
| 35 | - * |
|
| 36 | - * @var array[] |
|
| 37 | - */ |
|
| 38 | - private $diffColumns; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * If set all tables and columns are shown. |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - private $full; |
|
| 46 | - |
|
| 47 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 48 | - /** |
|
| 49 | - * Check full full and return array without new or obsolete columns if full not set. |
|
| 50 | - * |
|
| 51 | - * @param array[] $columns The metadata of the columns of a table. |
|
| 52 | - * |
|
| 53 | - * @return array[] |
|
| 54 | - */ |
|
| 55 | - private static function removeMatchingColumns($columns) |
|
| 56 | - { |
|
| 23 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 24 | + /** |
|
| 25 | + * Array with columns for each table. |
|
| 26 | + * array [ |
|
| 27 | + * table_name [ |
|
| 28 | + * column [ |
|
| 29 | + * data table type, |
|
| 30 | + * audit table type |
|
| 31 | + * ], |
|
| 32 | + * ... |
|
| 33 | + * ] |
|
| 34 | + * ] |
|
| 35 | + * |
|
| 36 | + * @var array[] |
|
| 37 | + */ |
|
| 38 | + private $diffColumns; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * If set all tables and columns are shown. |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + private $full; |
|
| 46 | + |
|
| 47 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 48 | + /** |
|
| 49 | + * Check full full and return array without new or obsolete columns if full not set. |
|
| 50 | + * |
|
| 51 | + * @param array[] $columns The metadata of the columns of a table. |
|
| 52 | + * |
|
| 53 | + * @return array[] |
|
| 54 | + */ |
|
| 55 | + private static function removeMatchingColumns($columns) |
|
| 56 | + { |
|
| 57 | 57 | $cleaned = []; |
| 58 | 58 | foreach ($columns as $column) |
| 59 | 59 | { |
| 60 | - 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']))) |
|
| 61 | - { |
|
| 60 | + 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']))) |
|
| 61 | + { |
|
| 62 | 62 | $cleaned[] = $column; |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | return $cleaned; |
| 67 | - } |
|
| 68 | - |
|
| 69 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 70 | - /** |
|
| 71 | - * {@inheritdoc} |
|
| 72 | - */ |
|
| 73 | - protected function configure() |
|
| 74 | - { |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 70 | + /** |
|
| 71 | + * {@inheritdoc} |
|
| 72 | + */ |
|
| 73 | + protected function configure() |
|
| 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'); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 82 | - /** |
|
| 83 | - * {@inheritdoc} |
|
| 84 | - */ |
|
| 85 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
| 86 | - { |
|
| 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 | + } |
|
| 80 | + |
|
| 81 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 82 | + /** |
|
| 83 | + * {@inheritdoc} |
|
| 84 | + */ |
|
| 85 | + protected function execute(InputInterface $input, OutputInterface $output) |
|
| 86 | + { |
|
| 87 | 87 | $this->io = new StratumStyle($input, $output); |
| 88 | 88 | |
| 89 | 89 | // Style for column names with miss matched column types. |
@@ -113,237 +113,237 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | $this->getDiff(); |
| 115 | 115 | $this->printDiff($output); |
| 116 | - } |
|
| 117 | - |
|
| 118 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 119 | - /** |
|
| 120 | - * Add highlighting to columns. |
|
| 121 | - * |
|
| 122 | - * @param array[] $columns The metadata of the columns. |
|
| 123 | - * |
|
| 124 | - * @return array[] |
|
| 125 | - */ |
|
| 126 | - private function addHighlighting($columns) |
|
| 127 | - { |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 119 | + /** |
|
| 120 | + * Add highlighting to columns. |
|
| 121 | + * |
|
| 122 | + * @param array[] $columns The metadata of the columns. |
|
| 123 | + * |
|
| 124 | + * @return array[] |
|
| 125 | + */ |
|
| 126 | + private function addHighlighting($columns) |
|
| 127 | + { |
|
| 128 | 128 | $styledColumns = []; |
| 129 | 129 | foreach ($columns as $column) |
| 130 | 130 | { |
| 131 | - $styledColumn = $column; |
|
| 132 | - // Highlighting for data table column types and audit. |
|
| 133 | - if (!empty($column['data_table_type'])) |
|
| 134 | - { |
|
| 131 | + $styledColumn = $column; |
|
| 132 | + // Highlighting for data table column types and audit. |
|
| 133 | + if (!empty($column['data_table_type'])) |
|
| 134 | + { |
|
| 135 | 135 | if (isset($column['data_table_type']) && !isset($column['audit_table_type'])) |
| 136 | 136 | { |
| 137 | - $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
|
| 138 | - $styledColumn['data_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['data_table_type']); |
|
| 137 | + $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
|
| 138 | + $styledColumn['data_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['data_table_type']); |
|
| 139 | 139 | } |
| 140 | 140 | else if (!isset($column['data_table_type']) && isset($column['audit_table_type'])) |
| 141 | 141 | { |
| 142 | - $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['audit_table_type']); |
|
| 142 | + $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['audit_table_type']); |
|
| 143 | 143 | } |
| 144 | 144 | else if (strcmp($column['data_table_type'], $column['audit_table_type'])) |
| 145 | 145 | { |
| 146 | - $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
|
| 147 | - $styledColumn['data_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['data_table_type']); |
|
| 148 | - $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['audit_table_type']); |
|
| 146 | + $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
|
| 147 | + $styledColumn['data_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['data_table_type']); |
|
| 148 | + $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['audit_table_type']); |
|
| 149 | 149 | } |
| 150 | - } |
|
| 151 | - else |
|
| 152 | - { |
|
| 150 | + } |
|
| 151 | + else |
|
| 152 | + { |
|
| 153 | 153 | // Highlighting for audit table column types and audit_columns in config file. |
| 154 | 154 | $searchColumn = StaticDataLayer::searchInRowSet('column_name', $styledColumn['column_name'], $this->config['audit_columns']); |
| 155 | 155 | if (isset($searchColumn)) |
| 156 | 156 | { |
| 157 | - $configType = $this->config['audit_columns'][$searchColumn]['column_type']; |
|
| 158 | - if (isset($configType) && !isset($column['audit_table_type'])) |
|
| 159 | - { |
|
| 157 | + $configType = $this->config['audit_columns'][$searchColumn]['column_type']; |
|
| 158 | + if (isset($configType) && !isset($column['audit_table_type'])) |
|
| 159 | + { |
|
| 160 | 160 | $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
| 161 | 161 | $styledColumn['config_type'] = sprintf('<mm_type>%s</>', $styledColumn['config_type']); |
| 162 | - } |
|
| 163 | - else if (!isset($configType) && isset($column['audit_table_type'])) |
|
| 164 | - { |
|
| 162 | + } |
|
| 163 | + else if (!isset($configType) && isset($column['audit_table_type'])) |
|
| 164 | + { |
|
| 165 | 165 | $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $column['audit_table_type']); |
| 166 | - } |
|
| 167 | - else if (strcmp($configType, $column['audit_table_type'])) |
|
| 168 | - { |
|
| 166 | + } |
|
| 167 | + else if (strcmp($configType, $column['audit_table_type'])) |
|
| 168 | + { |
|
| 169 | 169 | $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
| 170 | 170 | $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $column['audit_table_type']); |
| 171 | 171 | $styledColumn['config_type'] = sprintf('<mm_type>%s</>', $styledColumn['config_type']); |
| 172 | - } |
|
| 172 | + } |
|
| 173 | + } |
|
| 173 | 174 | } |
| 174 | - } |
|
| 175 | - $styledColumns[] = $styledColumn; |
|
| 175 | + $styledColumns[] = $styledColumn; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | return $styledColumns; |
| 179 | - } |
|
| 180 | - |
|
| 181 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 182 | - /** |
|
| 183 | - * Get the difference between data and audit tables. |
|
| 184 | - * |
|
| 185 | - * @param Columns $dataColumns The table columns from data schema. |
|
| 186 | - * @param Columns $auditColumns The table columns from audit schema. |
|
| 187 | - * |
|
| 188 | - * @return array[] |
|
| 189 | - */ |
|
| 190 | - private function createDiffArray($dataColumns, $auditColumns) |
|
| 191 | - { |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 182 | + /** |
|
| 183 | + * Get the difference between data and audit tables. |
|
| 184 | + * |
|
| 185 | + * @param Columns $dataColumns The table columns from data schema. |
|
| 186 | + * @param Columns $auditColumns The table columns from audit schema. |
|
| 187 | + * |
|
| 188 | + * @return array[] |
|
| 189 | + */ |
|
| 190 | + private function createDiffArray($dataColumns, $auditColumns) |
|
| 191 | + { |
|
| 192 | 192 | $diff = []; |
| 193 | 193 | |
| 194 | 194 | foreach ($this->config['audit_columns'] as $column) |
| 195 | 195 | { |
| 196 | - $diff[$column['column_name']] = ['column_name' => $column['column_name'], |
|
| 197 | - 'data_table_type' => null, |
|
| 198 | - 'audit_table_type' => null, |
|
| 199 | - 'config_type' => $column['column_type']]; |
|
| 196 | + $diff[$column['column_name']] = ['column_name' => $column['column_name'], |
|
| 197 | + 'data_table_type' => null, |
|
| 198 | + 'audit_table_type' => null, |
|
| 199 | + 'config_type' => $column['column_type']]; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | foreach ($auditColumns->getColumns() as $column) |
| 203 | 203 | { |
| 204 | - $config_type = isset($diff[$column['column_name']]) ? $diff[$column['column_name']]['config_type'] : null; |
|
| 204 | + $config_type = isset($diff[$column['column_name']]) ? $diff[$column['column_name']]['config_type'] : null; |
|
| 205 | 205 | |
| 206 | - $diff[$column['column_name']] = ['column_name' => $column['column_name'], |
|
| 207 | - 'data_table_type' => null, |
|
| 208 | - 'audit_table_type' => $auditColumns->getColumnTypeWithCharSetCollation($column['column_name']), |
|
| 209 | - 'config_type' => $config_type]; |
|
| 206 | + $diff[$column['column_name']] = ['column_name' => $column['column_name'], |
|
| 207 | + 'data_table_type' => null, |
|
| 208 | + 'audit_table_type' => $auditColumns->getColumnTypeWithCharSetCollation($column['column_name']), |
|
| 209 | + 'config_type' => $config_type]; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | foreach ($dataColumns->getColumns() as $column) |
| 213 | 213 | { |
| 214 | - $config_type = isset($diff[$column['column_name']]) ? $diff[$column['column_name']]['config_type'] : null; |
|
| 215 | - $audit_table_type = isset($diff[$column['column_name']]) ? $diff[$column['column_name']]['audit_table_type'] : null; |
|
| 214 | + $config_type = isset($diff[$column['column_name']]) ? $diff[$column['column_name']]['config_type'] : null; |
|
| 215 | + $audit_table_type = isset($diff[$column['column_name']]) ? $diff[$column['column_name']]['audit_table_type'] : null; |
|
| 216 | 216 | |
| 217 | - $diff[$column['column_name']] = ['column_name' => $column['column_name'], |
|
| 218 | - 'data_table_type' => $dataColumns->getColumnTypeWithCharSetCollation($column['column_name']), |
|
| 219 | - 'audit_table_type' => $audit_table_type, |
|
| 220 | - 'config_type' => $config_type]; |
|
| 217 | + $diff[$column['column_name']] = ['column_name' => $column['column_name'], |
|
| 218 | + 'data_table_type' => $dataColumns->getColumnTypeWithCharSetCollation($column['column_name']), |
|
| 219 | + 'audit_table_type' => $audit_table_type, |
|
| 220 | + 'config_type' => $config_type]; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | return $diff; |
| 224 | - } |
|
| 225 | - |
|
| 226 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 227 | - /** |
|
| 228 | - * Computes the difference between data and audit tables. |
|
| 229 | - */ |
|
| 230 | - private function getDiff() |
|
| 231 | - { |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 227 | + /** |
|
| 228 | + * Computes the difference between data and audit tables. |
|
| 229 | + */ |
|
| 230 | + private function getDiff() |
|
| 231 | + { |
|
| 232 | 232 | foreach ($this->dataSchemaTables as $table) |
| 233 | 233 | { |
| 234 | - if ($this->config['tables'][$table['table_name']]['audit']) |
|
| 235 | - { |
|
| 234 | + if ($this->config['tables'][$table['table_name']]['audit']) |
|
| 235 | + { |
|
| 236 | 236 | $res = StaticDataLayer::searchInRowSet('table_name', $table['table_name'], $this->auditSchemaTables); |
| 237 | 237 | if (isset($res)) |
| 238 | 238 | { |
| 239 | - $dataColumns = new Columns(DataLayer::getTableColumns($this->config['database']['data_schema'], $table['table_name'])); |
|
| 240 | - $auditColumns = DataLayer::getTableColumns($this->config['database']['audit_schema'], $table['table_name']); |
|
| 241 | - $auditColumns = $this->addNotNull($auditColumns); |
|
| 242 | - $auditColumns = new Columns($auditColumns); |
|
| 239 | + $dataColumns = new Columns(DataLayer::getTableColumns($this->config['database']['data_schema'], $table['table_name'])); |
|
| 240 | + $auditColumns = DataLayer::getTableColumns($this->config['database']['audit_schema'], $table['table_name']); |
|
| 241 | + $auditColumns = $this->addNotNull($auditColumns); |
|
| 242 | + $auditColumns = new Columns($auditColumns); |
|
| 243 | 243 | |
| 244 | - $this->diffColumns[$table['table_name']] = $this->createDiffArray($dataColumns, $auditColumns); |
|
| 244 | + $this->diffColumns[$table['table_name']] = $this->createDiffArray($dataColumns, $auditColumns); |
|
| 245 | + } |
|
| 245 | 246 | } |
| 246 | - } |
|
| 247 | 247 | } |
| 248 | - } |
|
| 249 | - |
|
| 250 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 251 | - /** |
|
| 252 | - * Add not null to audit columns if it not nullable. |
|
| 253 | - * |
|
| 254 | - * @param array $theColumns Audit columns. |
|
| 255 | - * |
|
| 256 | - * @return array |
|
| 257 | - */ |
|
| 258 | - private function addNotNull($theColumns) |
|
| 259 | - { |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 251 | + /** |
|
| 252 | + * Add not null to audit columns if it not nullable. |
|
| 253 | + * |
|
| 254 | + * @param array $theColumns Audit columns. |
|
| 255 | + * |
|
| 256 | + * @return array |
|
| 257 | + */ |
|
| 258 | + private function addNotNull($theColumns) |
|
| 259 | + { |
|
| 260 | 260 | $modifiedColumns = []; |
| 261 | 261 | foreach ($theColumns as $column) |
| 262 | 262 | { |
| 263 | - $modifiedColumn = $column; |
|
| 264 | - $auditColumn = StaticDataLayer::searchInRowSet('column_name', $modifiedColumn['column_name'], $this->config['audit_columns']); |
|
| 265 | - if (isset($auditColumn)) |
|
| 266 | - { |
|
| 263 | + $modifiedColumn = $column; |
|
| 264 | + $auditColumn = StaticDataLayer::searchInRowSet('column_name', $modifiedColumn['column_name'], $this->config['audit_columns']); |
|
| 265 | + if (isset($auditColumn)) |
|
| 266 | + { |
|
| 267 | 267 | if ($modifiedColumn['is_nullable']==='NO') |
| 268 | 268 | { |
| 269 | - $modifiedColumn['column_type'] = sprintf('%s not null', $modifiedColumn['column_type']); |
|
| 269 | + $modifiedColumn['column_type'] = sprintf('%s not null', $modifiedColumn['column_type']); |
|
| 270 | + } |
|
| 270 | 271 | } |
| 271 | - } |
|
| 272 | - $modifiedColumns[] = $modifiedColumn; |
|
| 272 | + $modifiedColumns[] = $modifiedColumn; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | return $modifiedColumns; |
| 276 | - } |
|
| 277 | - |
|
| 278 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 279 | - /** |
|
| 280 | - * Writes the difference between the audit tables and metadata tables to the output. |
|
| 281 | - * |
|
| 282 | - * @param OutputInterface $output The output. |
|
| 283 | - */ |
|
| 284 | - private function diffTables($output) |
|
| 285 | - { |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 279 | + /** |
|
| 280 | + * Writes the difference between the audit tables and metadata tables to the output. |
|
| 281 | + * |
|
| 282 | + * @param OutputInterface $output The output. |
|
| 283 | + */ |
|
| 284 | + private function diffTables($output) |
|
| 285 | + { |
|
| 286 | 286 | foreach ($this->config['tables'] as $tableName => $table) |
| 287 | 287 | { |
| 288 | - $res = StaticDataLayer::searchInRowSet('table_name', $tableName, $this->auditSchemaTables); |
|
| 289 | - if ($table['audit'] && !isset($res)) |
|
| 290 | - { |
|
| 288 | + $res = StaticDataLayer::searchInRowSet('table_name', $tableName, $this->auditSchemaTables); |
|
| 289 | + if ($table['audit'] && !isset($res)) |
|
| 290 | + { |
|
| 291 | 291 | $output->writeln(sprintf('<miss_table>%s</>', $tableName)); |
| 292 | - } |
|
| 293 | - else if (!$table['audit'] && isset($res)) |
|
| 294 | - { |
|
| 292 | + } |
|
| 293 | + else if (!$table['audit'] && isset($res)) |
|
| 294 | + { |
|
| 295 | 295 | $output->writeln(sprintf('<obsolete_table>%s</>', $tableName)); |
| 296 | - } |
|
| 296 | + } |
|
| 297 | + } |
|
| 297 | 298 | } |
| 298 | - } |
|
| 299 | - |
|
| 300 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 301 | - /** |
|
| 302 | - * Writes the difference between the audit and data tables to the output. |
|
| 303 | - * |
|
| 304 | - * @param OutputInterface $output The output. |
|
| 305 | - */ |
|
| 306 | - private function printDiff($output) |
|
| 307 | - { |
|
| 299 | + |
|
| 300 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 301 | + /** |
|
| 302 | + * Writes the difference between the audit and data tables to the output. |
|
| 303 | + * |
|
| 304 | + * @param OutputInterface $output The output. |
|
| 305 | + */ |
|
| 306 | + private function printDiff($output) |
|
| 307 | + { |
|
| 308 | 308 | $first = true; |
| 309 | 309 | if (isset($this->diffColumns)) |
| 310 | 310 | { |
| 311 | - foreach ($this->diffColumns as $tableName => $columns) |
|
| 312 | - { |
|
| 311 | + foreach ($this->diffColumns as $tableName => $columns) |
|
| 312 | + { |
|
| 313 | 313 | // Remove matching columns unless the full option is used. |
| 314 | 314 | if (!$this->full) |
| 315 | 315 | { |
| 316 | - $columns = self::removeMatchingColumns($columns); |
|
| 316 | + $columns = self::removeMatchingColumns($columns); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | if (!empty($columns)) |
| 320 | 320 | { |
| 321 | - // Add an empty line between tables. |
|
| 322 | - if ($first) |
|
| 323 | - { |
|
| 321 | + // Add an empty line between tables. |
|
| 322 | + if ($first) |
|
| 323 | + { |
|
| 324 | 324 | $first = false; |
| 325 | - } |
|
| 326 | - else |
|
| 327 | - { |
|
| 325 | + } |
|
| 326 | + else |
|
| 327 | + { |
|
| 328 | 328 | $output->writeln(''); |
| 329 | - } |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - // Write table name. |
|
| 332 | - $output->writeln($tableName); |
|
| 331 | + // Write table name. |
|
| 332 | + $output->writeln($tableName); |
|
| 333 | 333 | |
| 334 | - // Write table with columns. |
|
| 335 | - $columns = $this->addHighlighting($columns); |
|
| 336 | - $table = new Table($output); |
|
| 337 | - $table->setHeaders(['column', 'data table', 'audit table', 'config']) |
|
| 334 | + // Write table with columns. |
|
| 335 | + $columns = $this->addHighlighting($columns); |
|
| 336 | + $table = new Table($output); |
|
| 337 | + $table->setHeaders(['column', 'data table', 'audit table', 'config']) |
|
| 338 | 338 | ->setRows($columns); |
| 339 | - $table->render(); |
|
| 339 | + $table->render(); |
|
| 340 | + } |
|
| 340 | 341 | } |
| 341 | - } |
|
| 342 | 342 | } |
| 343 | 343 | $this->diffTables($output); |
| 344 | - } |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | - //-------------------------------------------------------------------------------------------------------------------- |
|
| 346 | + //-------------------------------------------------------------------------------------------------------------------- |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | //---------------------------------------------------------------------------------------------------------------------- |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | $cleaned = []; |
| 58 | 58 | foreach ($columns as $column) |
| 59 | 59 | { |
| 60 | - 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']))) |
|
| 60 | + 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']))) |
|
| 61 | 61 | { |
| 62 | 62 | $cleaned[] = $column; |
| 63 | 63 | } |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | $auditColumn = StaticDataLayer::searchInRowSet('column_name', $modifiedColumn['column_name'], $this->config['audit_columns']); |
| 265 | 265 | if (isset($auditColumn)) |
| 266 | 266 | { |
| 267 | - if ($modifiedColumn['is_nullable']==='NO') |
|
| 267 | + if ($modifiedColumn['is_nullable'] === 'NO') |
|
| 268 | 268 | { |
| 269 | 269 | $modifiedColumn['column_type'] = sprintf('%s not null', $modifiedColumn['column_type']); |
| 270 | 270 | } |
@@ -136,19 +136,16 @@ discard block |
||
| 136 | 136 | { |
| 137 | 137 | $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
| 138 | 138 | $styledColumn['data_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['data_table_type']); |
| 139 | - } |
|
| 140 | - else if (!isset($column['data_table_type']) && isset($column['audit_table_type'])) |
|
| 139 | + } else if (!isset($column['data_table_type']) && isset($column['audit_table_type'])) |
|
| 141 | 140 | { |
| 142 | 141 | $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['audit_table_type']); |
| 143 | - } |
|
| 144 | - else if (strcmp($column['data_table_type'], $column['audit_table_type'])) |
|
| 142 | + } else if (strcmp($column['data_table_type'], $column['audit_table_type'])) |
|
| 145 | 143 | { |
| 146 | 144 | $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
| 147 | 145 | $styledColumn['data_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['data_table_type']); |
| 148 | 146 | $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $styledColumn['audit_table_type']); |
| 149 | 147 | } |
| 150 | - } |
|
| 151 | - else |
|
| 148 | + } else |
|
| 152 | 149 | { |
| 153 | 150 | // Highlighting for audit table column types and audit_columns in config file. |
| 154 | 151 | $searchColumn = StaticDataLayer::searchInRowSet('column_name', $styledColumn['column_name'], $this->config['audit_columns']); |
@@ -159,12 +156,10 @@ discard block |
||
| 159 | 156 | { |
| 160 | 157 | $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
| 161 | 158 | $styledColumn['config_type'] = sprintf('<mm_type>%s</>', $styledColumn['config_type']); |
| 162 | - } |
|
| 163 | - else if (!isset($configType) && isset($column['audit_table_type'])) |
|
| 159 | + } else if (!isset($configType) && isset($column['audit_table_type'])) |
|
| 164 | 160 | { |
| 165 | 161 | $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $column['audit_table_type']); |
| 166 | - } |
|
| 167 | - else if (strcmp($configType, $column['audit_table_type'])) |
|
| 162 | + } else if (strcmp($configType, $column['audit_table_type'])) |
|
| 168 | 163 | { |
| 169 | 164 | $styledColumn['column_name'] = sprintf('<mm_column>%s</>', $styledColumn['column_name']); |
| 170 | 165 | $styledColumn['audit_table_type'] = sprintf('<mm_type>%s</>', $column['audit_table_type']); |
@@ -289,8 +284,7 @@ discard block |
||
| 289 | 284 | if ($table['audit'] && !isset($res)) |
| 290 | 285 | { |
| 291 | 286 | $output->writeln(sprintf('<miss_table>%s</>', $tableName)); |
| 292 | - } |
|
| 293 | - else if (!$table['audit'] && isset($res)) |
|
| 287 | + } else if (!$table['audit'] && isset($res)) |
|
| 294 | 288 | { |
| 295 | 289 | $output->writeln(sprintf('<obsolete_table>%s</>', $tableName)); |
| 296 | 290 | } |
@@ -322,8 +316,7 @@ discard block |
||
| 322 | 316 | if ($first) |
| 323 | 317 | { |
| 324 | 318 | $first = false; |
| 325 | - } |
|
| 326 | - else |
|
| 319 | + } else |
|
| 327 | 320 | { |
| 328 | 321 | $output->writeln(''); |
| 329 | 322 | } |