@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Add the functions implemented in this file to the $smcFunc array. |
@@ -23,8 +24,8 @@ discard block |
||
| 23 | 24 | { |
| 24 | 25 | global $smcFunc; |
| 25 | 26 | |
| 26 | - if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') |
|
| 27 | - $smcFunc += array( |
|
| 27 | + if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') { |
|
| 28 | + $smcFunc += array( |
|
| 28 | 29 | 'db_backup_table' => 'smf_db_backup_table', |
| 29 | 30 | 'db_optimize_table' => 'smf_db_optimize_table', |
| 30 | 31 | 'db_table_sql' => 'smf_db_table_sql', |
@@ -32,7 +33,8 @@ discard block |
||
| 32 | 33 | 'db_get_version' => 'smf_db_get_version', |
| 33 | 34 | 'db_get_vendor' => 'smf_db_get_vendor', |
| 34 | 35 | ); |
| 35 | -} |
|
| 36 | + } |
|
| 37 | + } |
|
| 36 | 38 | |
| 37 | 39 | /** |
| 38 | 40 | * Backup $table to $backup_table. |
@@ -74,8 +76,9 @@ discard block |
||
| 74 | 76 | )); |
| 75 | 77 | |
| 76 | 78 | // Old school or no school? |
| 77 | - if ($request) |
|
| 78 | - return $request; |
|
| 79 | + if ($request) { |
|
| 80 | + return $request; |
|
| 81 | + } |
|
| 79 | 82 | } |
| 80 | 83 | |
| 81 | 84 | // At this point, the quick method failed. |
@@ -99,8 +102,9 @@ discard block |
||
| 99 | 102 | foreach ($create as $k => $l) |
| 100 | 103 | { |
| 101 | 104 | // Get the name of the auto_increment column. |
| 102 | - if (strpos($l, 'auto_increment')) |
|
| 103 | - $auto_inc = trim($l); |
|
| 105 | + if (strpos($l, 'auto_increment')) { |
|
| 106 | + $auto_inc = trim($l); |
|
| 107 | + } |
|
| 104 | 108 | |
| 105 | 109 | // For the engine type, see if we can work out what it is. |
| 106 | 110 | if (strpos($l, 'ENGINE') !== false || strpos($l, 'TYPE') !== false) |
@@ -108,30 +112,36 @@ discard block |
||
| 108 | 112 | // Extract the engine type. |
| 109 | 113 | preg_match('~(ENGINE|TYPE)=(\w+)(\sDEFAULT)?(\sCHARSET=(\w+))?(\sCOLLATE=(\w+))?~', $l, $match); |
| 110 | 114 | |
| 111 | - if (!empty($match[1])) |
|
| 112 | - $engine = $match[1]; |
|
| 115 | + if (!empty($match[1])) { |
|
| 116 | + $engine = $match[1]; |
|
| 117 | + } |
|
| 113 | 118 | |
| 114 | - if (!empty($match[2])) |
|
| 115 | - $engine = $match[2]; |
|
| 119 | + if (!empty($match[2])) { |
|
| 120 | + $engine = $match[2]; |
|
| 121 | + } |
|
| 116 | 122 | |
| 117 | - if (!empty($match[5])) |
|
| 118 | - $charset = $match[5]; |
|
| 123 | + if (!empty($match[5])) { |
|
| 124 | + $charset = $match[5]; |
|
| 125 | + } |
|
| 119 | 126 | |
| 120 | - if (!empty($match[7])) |
|
| 121 | - $collate = $match[7]; |
|
| 127 | + if (!empty($match[7])) { |
|
| 128 | + $collate = $match[7]; |
|
| 129 | + } |
|
| 122 | 130 | } |
| 123 | 131 | |
| 124 | 132 | // Skip everything but keys... |
| 125 | - if (strpos($l, 'KEY') === false) |
|
| 126 | - unset($create[$k]); |
|
| 133 | + if (strpos($l, 'KEY') === false) { |
|
| 134 | + unset($create[$k]); |
|
| 135 | + } |
|
| 127 | 136 | } |
| 128 | 137 | |
| 129 | - if (!empty($create)) |
|
| 130 | - $create = '( |
|
| 138 | + if (!empty($create)) { |
|
| 139 | + $create = '( |
|
| 131 | 140 | ' . implode(' |
| 132 | 141 | ', $create) . ')'; |
| 133 | - else |
|
| 134 | - $create = ''; |
|
| 142 | + } else { |
|
| 143 | + $create = ''; |
|
| 144 | + } |
|
| 135 | 145 | |
| 136 | 146 | $request = $smcFunc['db_query']('', ' |
| 137 | 147 | CREATE TABLE {raw:backup_table} {raw:create} |
@@ -150,8 +160,9 @@ discard block |
||
| 150 | 160 | |
| 151 | 161 | if ($auto_inc != '') |
| 152 | 162 | { |
| 153 | - if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',') |
|
| 154 | - $auto_inc = substr($auto_inc, 0, -1); |
|
| 163 | + if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',') { |
|
| 164 | + $auto_inc = substr($auto_inc, 0, -1); |
|
| 165 | + } |
|
| 155 | 166 | |
| 156 | 167 | $smcFunc['db_query']('', ' |
| 157 | 168 | ALTER TABLE {raw:backup_table} |
@@ -195,8 +206,9 @@ discard block |
||
| 195 | 206 | 'table' => $table, |
| 196 | 207 | ) |
| 197 | 208 | ); |
| 198 | - if (!$request) |
|
| 199 | - return -1; |
|
| 209 | + if (!$request) { |
|
| 210 | + return -1; |
|
| 211 | + } |
|
| 200 | 212 | |
| 201 | 213 | // How much left? |
| 202 | 214 | $request = $smcFunc['db_query']('', ' |
@@ -239,8 +251,9 @@ discard block |
||
| 239 | 251 | ) |
| 240 | 252 | ); |
| 241 | 253 | $tables = array(); |
| 242 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 243 | - $tables[] = $row[0]; |
|
| 254 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 255 | + $tables[] = $row[0]; |
|
| 256 | + } |
|
| 244 | 257 | $smcFunc['db_free_result']($request); |
| 245 | 258 | |
| 246 | 259 | return $tables; |
@@ -284,8 +297,9 @@ discard block |
||
| 284 | 297 | if (!empty($row['Default']) || $row['Null'] !== 'YES') |
| 285 | 298 | { |
| 286 | 299 | // Make a special case of auto-timestamp. |
| 287 | - if ($row['Default'] == 'CURRENT_TIMESTAMP') |
|
| 288 | - $schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */'; |
|
| 300 | + if ($row['Default'] == 'CURRENT_TIMESTAMP') { |
|
| 301 | + $schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */'; |
|
| 302 | + } |
|
| 289 | 303 | // Text shouldn't have a default. |
| 290 | 304 | elseif ($row['Default'] !== null) |
| 291 | 305 | { |
@@ -320,14 +334,16 @@ discard block |
||
| 320 | 334 | $row['Key_name'] = $row['Key_name'] == 'PRIMARY' ? 'PRIMARY KEY' : (empty($row['Non_unique']) ? 'UNIQUE ' : ($row['Comment'] == 'FULLTEXT' || (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') ? 'FULLTEXT ' : 'KEY ')) . '`' . $row['Key_name'] . '`'; |
| 321 | 335 | |
| 322 | 336 | // Is this the first column in the index? |
| 323 | - if (empty($indexes[$row['Key_name']])) |
|
| 324 | - $indexes[$row['Key_name']] = array(); |
|
| 337 | + if (empty($indexes[$row['Key_name']])) { |
|
| 338 | + $indexes[$row['Key_name']] = array(); |
|
| 339 | + } |
|
| 325 | 340 | |
| 326 | 341 | // A sub part, like only indexing 15 characters of a varchar. |
| 327 | - if (!empty($row['Sub_part'])) |
|
| 328 | - $indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')'; |
|
| 329 | - else |
|
| 330 | - $indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`'; |
|
| 342 | + if (!empty($row['Sub_part'])) { |
|
| 343 | + $indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')'; |
|
| 344 | + } else { |
|
| 345 | + $indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`'; |
|
| 346 | + } |
|
| 331 | 347 | } |
| 332 | 348 | $smcFunc['db_free_result']($result); |
| 333 | 349 | |
@@ -365,8 +381,9 @@ discard block |
||
| 365 | 381 | { |
| 366 | 382 | static $ver; |
| 367 | 383 | |
| 368 | - if (!empty($ver)) |
|
| 369 | - return $ver; |
|
| 384 | + if (!empty($ver)) { |
|
| 385 | + return $ver; |
|
| 386 | + } |
|
| 370 | 387 | |
| 371 | 388 | global $smcFunc; |
| 372 | 389 | |
@@ -391,8 +408,9 @@ discard block |
||
| 391 | 408 | global $smcFunc; |
| 392 | 409 | static $db_type; |
| 393 | 410 | |
| 394 | - if (!empty($db_type)) |
|
| 395 | - return $db_type; |
|
| 411 | + if (!empty($db_type)) { |
|
| 412 | + return $db_type; |
|
| 413 | + } |
|
| 396 | 414 | |
| 397 | 415 | $request = $smcFunc['db_query']('', 'SELECT @@version_comment'); |
| 398 | 416 | list ($comment) = $smcFunc['db_fetch_row']($request); |
@@ -401,13 +419,15 @@ discard block |
||
| 401 | 419 | // Skip these if we don't have a comment. |
| 402 | 420 | if (!empty($comment)) |
| 403 | 421 | { |
| 404 | - if (stripos($comment, 'percona') !== false) |
|
| 405 | - return 'Percona'; |
|
| 406 | - if (stripos($comment, 'mariadb') !== false) |
|
| 407 | - return 'MariaDB'; |
|
| 422 | + if (stripos($comment, 'percona') !== false) { |
|
| 423 | + return 'Percona'; |
|
| 424 | + } |
|
| 425 | + if (stripos($comment, 'mariadb') !== false) { |
|
| 426 | + return 'MariaDB'; |
|
| 427 | + } |
|
| 428 | + } else { |
|
| 429 | + return 'fail'; |
|
| 408 | 430 | } |
| 409 | - else |
|
| 410 | - return 'fail'; |
|
| 411 | 431 | |
| 412 | 432 | return 'MySQL'; |
| 413 | 433 | } |