diff --git a/Languages/en_US/Maintenance.php b/Languages/en_US/Maintenance.php index 38b817e2426..3f3f4ee4477 100644 --- a/Languages/en_US/Maintenance.php +++ b/Languages/en_US/Maintenance.php @@ -65,13 +65,7 @@ $txt['maintenance_step'] = 'Step'; $txt['maintenance_overall_progress'] = 'Overall Progress'; $txt['maintenance_substep_progress'] = 'Step Progress'; -$txt['maintenance_time_elasped_ms'] = 'Time Elapsed {m, plural, - one {# minute} - other {# minutes} -} and {s, plural, - one {# second} - other {# seconds} -}'; +$txt['maintenance_time_elapsed'] = 'Time Elapsed: '; // File Permissions. $txt['chmod_linux_info'] = 'If you have a shell account, the following command can automatically correct permissions on these files'; diff --git a/Sources/Config.php b/Sources/Config.php index e25aa754927..f4aea7f9a7f 100644 --- a/Sources/Config.php +++ b/Sources/Config.php @@ -998,7 +998,7 @@ public static function set(array $settings): void } // Make sure the paths are correct... at least try to fix them. - if (empty(self::$boarddir) || !is_dir(realpath(self::$boarddir))) { + if (empty(self::$boarddir) || !is_dir((string) realpath(self::$boarddir))) { self::$boarddir = !empty($_SERVER['SCRIPT_FILENAME']) ? \dirname(realpath($_SERVER['SCRIPT_FILENAME'])) : \dirname(__DIR__); } diff --git a/Sources/Db/APIs/MySQL.php b/Sources/Db/APIs/MySQL.php index c1c5ed6c66c..d7a3e474977 100644 --- a/Sources/Db/APIs/MySQL.php +++ b/Sources/Db/APIs/MySQL.php @@ -256,7 +256,12 @@ public function quote(string $db_string, array $db_values, ?object $connection = if (str_contains($db_string, '{')) { // Do the quoting and escaping $db_string = preg_replace_callback( - '~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~', + [ + // The literal type can have arbitrary content. + '~{(literal):([^}]*)}~', + // Everything else needs to be a key in $db_values. + '~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~', + ], fn($matches) => $this->replacement__callback($matches, $db_values, $connection ?? $this->connection), $db_string, ); @@ -938,19 +943,29 @@ public function backup_table(string $table, string $backup_table): object|bool ], ); - // If this failed, we go old school. if ($result) { + $columns = []; + + // Do we have any generated columns to deal with? + foreach ($this->list_columns($table, true) as $column) { + // Skip generated columns in the insert statement. + if (empty($column['generation_expression'])) { + $columns[] = $column['name']; + } + } + $request = $this->query( 'INSERT INTO {raw:backup_table} - SELECT * + ({raw:columns}) + SELECT {raw:columns} FROM {raw:table}', [ 'backup_table' => $backup_table, 'table' => $table, + 'columns' => implode(', ', $columns), ], ); - // Old school or no school? if ($request) { return $request; } @@ -1047,6 +1062,13 @@ public function backup_table(string $table, string $backup_table): object|bool ); } + // Restore the generation expressions on any generated columns. + foreach ($this->list_columns($table, true) as $column) { + if (!empty($column['generation_expression'])) { + $this->change_column($backup_table, $column['name'], $column); + } + } + return $request; } @@ -1373,7 +1395,7 @@ public function add_column(string $table_name, array $column_info, array $parame $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null; // Now add the thing! - $this->query( + $result = $this->query( 'ALTER TABLE ' . $short_table_name . ' ADD ' . $this->create_query_column($column_info) . (empty($column_info['auto']) ? '' : ' primary key'), [ @@ -1381,7 +1403,7 @@ public function add_column(string $table_name, array $column_info, array $parame ], ); - return true; + return $result !== false; } /** @@ -1913,7 +1935,7 @@ public function create_table(string $table_name, array $columns, array $indexes } // Create the table! - $this->query( + $result = $this->query( $table_query, [ 'security_override' => true, @@ -1954,7 +1976,7 @@ public function create_table(string $table_name, array $columns, array $indexes $this->drop_table($short_table_name . '_old'); } - return true; + return $result !== false; } /** @@ -1980,15 +2002,14 @@ public function drop_table(string $table_name, array $parameters = [], string $e $tables = $this->list_tables($database); if (\in_array($full_table_name, $tables)) { - $query = 'DROP TABLE ' . $short_table_name; - $this->query( - $query, + $result = $this->query( + 'DROP TABLE ' . $short_table_name, [ 'security_override' => true, ], ); - return true; + return $result !== false; } // Otherwise do 'nout. @@ -2032,14 +2053,14 @@ public function rename_table(string $old_name, string $new_name, bool $allowed_r return false; } - $this->query( + $result = $this->query( 'ALTER TABLE ' . $short_old_name . ' RENAME ' . $short_new_name, [ 'security_override' => true, ], ); - return true; + return $result !== false; } /** @@ -2088,14 +2109,12 @@ public function list_columns(string $table_name, bool $detail = false, array $pa $database = !empty($match[2]) ? $match[2] : $this->name; $result = $this->query( - 'SELECT column_name "Field", COLUMN_TYPE "Type", is_nullable "Null", COLUMN_KEY "Key" , column_default "Default", extra "Extra", generation_expression "generation_expression" - FROM information_schema.columns - WHERE table_name = {string:table_name} - AND table_schema = {string:db_name} - ORDER BY ordinal_position', + 'SHOW COLUMNS + FROM {identifier:table_name} + IN {identifier:db}', [ + 'db' => strtr($database, ['`' => '']), 'table_name' => $real_table_name, - 'db_name' => $this->name, ], ); $columns = []; @@ -2109,8 +2128,7 @@ public function list_columns(string $table_name, bool $detail = false, array $pa // Can we split out the size? if (preg_match('~^(.+?)\s*\((\d+)\)$~', $row['Type'], $matches)) { - $type = $matches[1]; - $size = $matches[2]; + [$type, $size] = $this->calculate_type($matches[1], (int) $matches[2], true); } elseif (preg_match('~^(.+?)\s+unsigned$~', $row['Type'], $matches)) { $type = $matches[1]; $size = null; @@ -2135,12 +2153,32 @@ public function list_columns(string $table_name, bool $detail = false, array $pa unset($unsigned); } + // If this is a generated column, look up its generation expression. if (str_contains($row['Extra'], 'GENERATED')) { - $columns[$row['Field']]['generation_expression'] = $row['generation_expression']; + $result2 = $this->query( + 'SELECT generation_expression + FROM information_schema.columns + WHERE column_name = {string:field} + AND table_name = {string:table_name} + AND table_schema = {string:db}', + [ + 'db' => strtr($database, ['`' => '']), + 'table_name' => $real_table_name, + 'field' => $row['Field'], + ], + ); + + [$generation_expression] = $this->fetch_row($result2); + + $this->free_result($result2); + + $columns[$row['Field']]['generation_expression'] = $this->unescape_string($generation_expression); + $columns[$row['Field']]['stored'] = str_contains($row['Extra'], 'STORED'); } } } + $this->free_result($result); return $columns; @@ -2215,7 +2253,7 @@ public function remove_column(string $table_name, string $column_name, array $pa foreach ($columns as $column) { if ($column['name'] == $column_name) { - $this->query( + $result = $this->query( 'ALTER TABLE ' . $short_table_name . ' DROP COLUMN ' . $column_name, [ @@ -2223,7 +2261,7 @@ public function remove_column(string $table_name, string $column_name, array $pa ], ); - return true; + return $result !== false; } } @@ -2245,7 +2283,7 @@ public function remove_index(string $table_name, string $index_name, array $para // If the name is primary we want the primary key! if ($index['type'] == 'primary' && $index_name == 'primary') { // Dropping primary key? - $this->query( + $result = $this->query( 'ALTER TABLE ' . $short_table_name . ' DROP PRIMARY KEY', [ @@ -2253,12 +2291,12 @@ public function remove_index(string $table_name, string $index_name, array $para ], ); - return true; + return $result !== false; } if ($index['name'] == $index_name) { // Drop the bugger... - $this->query( + $result = $this->query( 'ALTER TABLE ' . $short_table_name . ' DROP INDEX ' . $index_name, [ @@ -2266,7 +2304,7 @@ public function remove_index(string $table_name, string $index_name, array $para ], ); - return true; + return $result !== false; } } @@ -2399,11 +2437,11 @@ public function setSqlMode(string $mode = 'default'): bool $sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT'; } - $this->query('SET SESSION sql_mode = {string:sql_mode}', [ + $result = $this->query('SET SESSION sql_mode = {string:sql_mode}', [ 'sql_mode' => $sql_mode, ]); - return true; + return $result !== false; } /** diff --git a/Sources/Db/APIs/PostgreSQL.php b/Sources/Db/APIs/PostgreSQL.php index d2550bff0be..86f9b974762 100644 --- a/Sources/Db/APIs/PostgreSQL.php +++ b/Sources/Db/APIs/PostgreSQL.php @@ -290,7 +290,12 @@ public function quote(string $db_string, array $db_values, ?object $connection = if (str_contains($db_string, '{')) { // Do the quoting and escaping $db_string = preg_replace_callback( - '~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~', + [ + // The literal type can have arbitrary content. + '~{(literal):([^}]*)}~', + // Everything else needs to be a key in $db_values. + '~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~', + ], fn($matches) => $this->replacement__callback($matches, $db_values, $connection ?? $this->connection), $db_string, ); @@ -1314,7 +1319,7 @@ public function add_column(string $table_name, array $column_info, array $parame } // Now add the thing! - $this->query( + $result = $this->query( 'ALTER TABLE ' . $short_table_name . ' ADD COLUMN ' . $column_info['name'] . ' ' . $type . $generated, [ @@ -1334,7 +1339,7 @@ public function add_column(string $table_name, array $column_info, array $parame return $this->change_column($table_name, $column_info['name'], $column_info); } - return true; + return $result !== false; } /** @@ -1876,7 +1881,7 @@ public function create_table(string $table_name, array $columns, array $indexes $table_query .= ')'; // Create the table! - $this->query( + $result = $this->query( $table_query, [ 'security_override' => true, @@ -1931,7 +1936,7 @@ public function create_table(string $table_name, array $columns, array $indexes $this->drop_table($table_name . '_old'); } - return true; + return $result !== false; } /** @@ -1966,7 +1971,7 @@ public function drop_table(string $table_name, array $parameters = [], string $e $sequence_query = 'DROP SEQUENCE IF EXISTS ' . $short_table_name . '_seq'; // drop them - $this->query( + $result = $this->query( $table_query, [ 'security_override' => true, @@ -1981,7 +1986,7 @@ public function drop_table(string $table_name, array $parameters = [], string $e $this->transaction('commit'); - return true; + return $result !== false; } // Otherwise do 'nout. @@ -2025,14 +2030,14 @@ public function rename_table(string $old_name, string $new_name, bool $allowed_r return false; } - $this->query( + $result = $this->query( 'ALTER TABLE ' . $short_old_name . ' RENAME TO ' . $short_new_name, [ 'security_override' => true, ], ); - return true; + return $result !== false; } /** @@ -2198,7 +2203,7 @@ public function remove_column(string $table_name, string $column_name, array $pa ); } - $this->query( + $result = $this->query( 'ALTER TABLE ' . $short_table_name . ' DROP COLUMN ' . $column_name, [ @@ -2206,7 +2211,7 @@ public function remove_column(string $table_name, string $column_name, array $pa ], ); - return true; + return $result !== false; } } @@ -2234,7 +2239,7 @@ public function remove_index(string $table_name, string $index_name, array $para // If the name is primary we want the primary key! if ($index['type'] == 'primary' && $index_name == 'primary') { // Dropping primary key? - $this->query( + $result = $this->query( 'ALTER TABLE ' . $real_table_name . ' DROP CONSTRAINT ' . $index['name'], [ @@ -2242,19 +2247,19 @@ public function remove_index(string $table_name, string $index_name, array $para ], ); - return true; + return $result !== false; } if ($index['name'] == $index_name) { // Drop the bugger... - $this->query( + $result = $this->query( 'DROP INDEX ' . $real_table_name . '_' . $index_name, [ 'security_override' => true, ], ); - return true; + return $result !== false; } } @@ -2616,7 +2621,7 @@ protected function replacement__callback(array $matches, array $db_values, objec } foreach ($replacement as $key => $value) { - $replacement[$key] = \sprintf('\'%1$s\'', pg_escape_string($this->connection, $value)); + $replacement[$key] = \sprintf('\'%1$s\'', pg_escape_string($this->connection, (string) $value)); } return implode(', ', $replacement); diff --git a/Sources/Db/DatabaseApi.php b/Sources/Db/DatabaseApi.php index 2e2bd1fee2b..2f68fc69f54 100644 --- a/Sources/Db/DatabaseApi.php +++ b/Sources/Db/DatabaseApi.php @@ -406,7 +406,7 @@ public function getTypeIndicators(string $table_name, array $column_values): arr // refers to any columns that are not defined in the schema file, then // we need to do a database query. if (array_diff_key($column_values, $column_types[$table_name]) !== []) { - foreach ($this->list_columns($table_name, true) as $col) { + foreach ($this->list_columns('{db_prefix}' . $table_name, true) as $col) { $column_types[$table_name][$col['name']] = $col['type']; } } diff --git a/Sources/Db/Schema/Column.php b/Sources/Db/Schema/Column.php index 63539d6f2c7..f5210c1cc9e 100644 --- a/Sources/Db/Schema/Column.php +++ b/Sources/Db/Schema/Column.php @@ -91,8 +91,6 @@ class Column * @var bool * * Set this to true to drop the default during an ALTER TABLE operation. - * - * This is not set by __construct(). It can be set afterward. */ public bool $drop_default = false; @@ -116,6 +114,8 @@ class Column * Only applicable to integer columns. * @param ?string $charset The character set for string data. * Only applicable to string types. If null, will be set automatically. + * @param bool $drop_default Whether to drop the column's default during + * ALTER TABLE operations. Default: false. */ public function __construct( string $name, @@ -126,6 +126,7 @@ public function __construct( string|float|int|bool|null $default = null, ?bool $auto = null, ?string $charset = null, + bool $drop_default = false, ) { $this->name = strtolower($name); $this->type = strtolower($type); @@ -134,7 +135,7 @@ public function __construct( $this->default = $default === 'NULL' ? null : $default; } - foreach (['auto', 'size', 'unsigned', 'not_null'] as $var) { + foreach (['auto', 'size', 'unsigned', 'not_null', 'drop_default'] as $var) { if (isset($var)) { $this->{$var} = ${$var}; } diff --git a/Sources/Db/Schema/Table.php b/Sources/Db/Schema/Table.php index 7bd02392126..c91e3e83225 100644 --- a/Sources/Db/Schema/Table.php +++ b/Sources/Db/Schema/Table.php @@ -22,7 +22,7 @@ /** * Represents a database table. */ -class Table +abstract class Table { /******************* * Public properties @@ -61,7 +61,20 @@ class Table * * The default character set for the table. */ - public ?string $default_charset; + public ?string $default_charset { + get { + // As of SMF 3.0, all tables always use four-byte UTF-8. + if ( + !isset($this->default_charset) + && preg_match('/\\\\v(\d+_\d+)\\\\/', $this::class, $matches) + && version_compare(strtr($matches[1], '_', '.'), '3.0', '>=') + ) { + $this->default_charset = Db::$db->title === MYSQL_TITLE ? 'utf8mb4' : 'utf8'; + } + + return $this->default_charset ?? null; + } + } /** * @var int @@ -76,22 +89,34 @@ class Table */ public ?int $auto_start; + /**************************** + * Internal static properties + ****************************/ + + /** + * @var array + * + * Cached output of Db::$db->list_tables + */ + protected static array $existing_tables = []; + /**************** * Public methods ****************/ /** - * Constructor. + * Checks whether a table with this name exists in the database. + * + * @param bool $force_refresh If true, force a refresh of the tables list. + * @return bool Whether this table exists. */ - public function __construct() + public function exists(bool $force_refresh = false) { - // As of SMF 3.0, all tables always use four-byte UTF-8. - if ( - preg_match('/\\\\v(\d+_\d+)\\\\/', $this::class, $matches) - && version_compare(strtr($matches[1], '_', '.'), '3.0', '>=') - ) { - $this->default_charset = Db::$db->title === MYSQL_TITLE ? 'utf8mb4' : 'utf8'; + if ($force_refresh || empty(self::$existing_tables)) { + self::$existing_tables = Db::$db->list_tables(); } + + return \in_array(Db::$db->prefix . $this->name, self::$existing_tables); } /** @@ -106,7 +131,7 @@ public function normalize(): bool return false; } - if (empty(Db::$db->list_tables(false, Db::$db->prefix . $this->name))) { + if (!$this->exists()) { return $this->create(); } @@ -287,13 +312,20 @@ public function create(array $parameters = [], string $if_exists = 'ignore'): bo return false; } - return Db::$db->create_table( + $success = Db::$db->create_table( '{db_prefix}' . $this->name, array_map('get_object_vars', array_values($this->columns)), array_map('get_object_vars', array_values($this->indexes)), $parameters, $if_exists, ); + + if ($success) { + // Force a refresh of the list of tables. + self::$existing_tables = []; + } + + return $success; } /** @@ -305,7 +337,14 @@ public function create(array $parameters = [], string $if_exists = 'ignore'): bo */ public function drop(): bool { - return Db::$db->drop_table('{db_prefix}' . $this->name); + $success = Db::$db->drop_table('{db_prefix}' . $this->name); + + if ($success) { + // Force a refresh of the list of tables. + self::$existing_tables = []; + } + + return $success; } /** @@ -636,23 +675,21 @@ final public static function find(string $table_name, string $schema_version): ? } /** - * Gets all known table schemas. + * Gets database initializer queries for the indicated SMF version. * + * @param string $schema_version E.g. 'v3_0'. * @return array All known table schemas. */ - final public static function getInitializers(string $schema_version, string $title): array + final public static function getInitializers(string $schema_version): array { - if (file_exists(__DIR__ . '/' . $schema_version . '/Initialize/' . $title . '.php')) { + if (file_exists(__DIR__ . '/' . $schema_version . '/Initialize/' . Db::$db->title . '.php')) { - $fully_qualified_class_name = __NAMESPACE__ . '\\' . $schema_version . '\\Initialize\\' . $title; + $fully_qualified_class_name = __NAMESPACE__ . '\\' . $schema_version . '\\Initialize\\' . Db::$db->title; if (!class_exists($fully_qualified_class_name)) { return []; } - /** - * @var \SMF\Db\Schema\v3_0\Initialize\Base - */ $intializer = new $fully_qualified_class_name(Db::$db->get_version()); return $intializer->getAll(); diff --git a/Sources/Db/Schema/v2_1/AdminInfoFiles.php b/Sources/Db/Schema/v2_1/AdminInfoFiles.php index 54b5910c86a..2ae4e0f8641 100644 --- a/Sources/Db/Schema/v2_1/AdminInfoFiles.php +++ b/Sources/Db/Schema/v2_1/AdminInfoFiles.php @@ -142,7 +142,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/ApprovalQueue.php b/Sources/Db/Schema/v2_1/ApprovalQueue.php index b3cf37c02ce..21c1eb86502 100644 --- a/Sources/Db/Schema/v2_1/ApprovalQueue.php +++ b/Sources/Db/Schema/v2_1/ApprovalQueue.php @@ -57,7 +57,5 @@ public function __construct() default: 0, ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Attachments.php b/Sources/Db/Schema/v2_1/Attachments.php index 1cbdb673dc0..ec42f9e84d0 100644 --- a/Sources/Db/Schema/v2_1/Attachments.php +++ b/Sources/Db/Schema/v2_1/Attachments.php @@ -187,7 +187,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/BackgroundTasks.php b/Sources/Db/Schema/v2_1/BackgroundTasks.php index 635ca8fe55a..34d3c1b8608 100644 --- a/Sources/Db/Schema/v2_1/BackgroundTasks.php +++ b/Sources/Db/Schema/v2_1/BackgroundTasks.php @@ -81,7 +81,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/BanGroups.php b/Sources/Db/Schema/v2_1/BanGroups.php index c9aec8cb9c5..9f2d29b4098 100644 --- a/Sources/Db/Schema/v2_1/BanGroups.php +++ b/Sources/Db/Schema/v2_1/BanGroups.php @@ -61,6 +61,9 @@ public function __construct() name: 'expire_time', type: 'int', unsigned: true, + not_null: false, + default: null, + drop_default: true, ), 'cannot_access' => new Column( name: 'cannot_access', @@ -114,7 +117,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/BanItems.php b/Sources/Db/Schema/v2_1/BanItems.php index 364d727ce4f..3f332e19353 100644 --- a/Sources/Db/Schema/v2_1/BanItems.php +++ b/Sources/Db/Schema/v2_1/BanItems.php @@ -54,11 +54,13 @@ public function __construct() name: 'ip_low', type: 'inet', size: 16, + default: null, ), 'ip_high' => new Column( name: 'ip_high', type: 'inet', size: 16, + default: null, ), 'hostname' => new Column( name: 'hostname', @@ -119,7 +121,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/BoardPermissions.php b/Sources/Db/Schema/v2_1/BoardPermissions.php index af42240baf3..c2c3a6ae95f 100644 --- a/Sources/Db/Schema/v2_1/BoardPermissions.php +++ b/Sources/Db/Schema/v2_1/BoardPermissions.php @@ -1629,7 +1629,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/BoardPermissionsView.php b/Sources/Db/Schema/v2_1/BoardPermissionsView.php index ac7f52e3a63..dfe7a72bf9d 100644 --- a/Sources/Db/Schema/v2_1/BoardPermissionsView.php +++ b/Sources/Db/Schema/v2_1/BoardPermissionsView.php @@ -98,7 +98,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Boards.php b/Sources/Db/Schema/v2_1/Boards.php index a30a89601d6..f0559dc8753 100644 --- a/Sources/Db/Schema/v2_1/Boards.php +++ b/Sources/Db/Schema/v2_1/Boards.php @@ -244,7 +244,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Calendar.php b/Sources/Db/Schema/v2_1/Calendar.php index a7e827271c4..21cb82f243e 100644 --- a/Sources/Db/Schema/v2_1/Calendar.php +++ b/Sources/Db/Schema/v2_1/Calendar.php @@ -142,7 +142,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/CalendarHolidays.php b/Sources/Db/Schema/v2_1/CalendarHolidays.php index 07d96e820cd..9b5c9f425fc 100644 --- a/Sources/Db/Schema/v2_1/CalendarHolidays.php +++ b/Sources/Db/Schema/v2_1/CalendarHolidays.php @@ -900,7 +900,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Categories.php b/Sources/Db/Schema/v2_1/Categories.php index e8d98f34976..3ddd0b53cc4 100644 --- a/Sources/Db/Schema/v2_1/Categories.php +++ b/Sources/Db/Schema/v2_1/Categories.php @@ -98,7 +98,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/CustomFields.php b/Sources/Db/Schema/v2_1/CustomFields.php index ccac78a5d94..4ef639294f6 100644 --- a/Sources/Db/Schema/v2_1/CustomFields.php +++ b/Sources/Db/Schema/v2_1/CustomFields.php @@ -278,7 +278,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/GroupModerators.php b/Sources/Db/Schema/v2_1/GroupModerators.php index 086b8a48853..80cfe89ab11 100644 --- a/Sources/Db/Schema/v2_1/GroupModerators.php +++ b/Sources/Db/Schema/v2_1/GroupModerators.php @@ -63,7 +63,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogActions.php b/Sources/Db/Schema/v2_1/LogActions.php index ff9f22a9808..b56c23d21cd 100644 --- a/Sources/Db/Schema/v2_1/LogActions.php +++ b/Sources/Db/Schema/v2_1/LogActions.php @@ -68,6 +68,7 @@ public function __construct() name: 'ip', type: 'inet', size: 16, + default: null, ), 'action' => new Column( name: 'action', @@ -165,7 +166,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogActivity.php b/Sources/Db/Schema/v2_1/LogActivity.php index 4a492a8ce6c..efc1bd978f6 100644 --- a/Sources/Db/Schema/v2_1/LogActivity.php +++ b/Sources/Db/Schema/v2_1/LogActivity.php @@ -88,7 +88,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogBanned.php b/Sources/Db/Schema/v2_1/LogBanned.php index f6fb686eed8..3f900168494 100644 --- a/Sources/Db/Schema/v2_1/LogBanned.php +++ b/Sources/Db/Schema/v2_1/LogBanned.php @@ -54,6 +54,7 @@ public function __construct() name: 'ip', type: 'inet', size: 16, + default: null, ), 'email' => new Column( name: 'email', @@ -89,7 +90,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogBoards.php b/Sources/Db/Schema/v2_1/LogBoards.php index 16a2f0fcc64..308c4ad153c 100644 --- a/Sources/Db/Schema/v2_1/LogBoards.php +++ b/Sources/Db/Schema/v2_1/LogBoards.php @@ -70,7 +70,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogComments.php b/Sources/Db/Schema/v2_1/LogComments.php index 32e4acc89bb..2aaabebd000 100644 --- a/Sources/Db/Schema/v2_1/LogComments.php +++ b/Sources/Db/Schema/v2_1/LogComments.php @@ -140,7 +140,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogDigest.php b/Sources/Db/Schema/v2_1/LogDigest.php index 0426c63b6cf..399c406d436 100644 --- a/Sources/Db/Schema/v2_1/LogDigest.php +++ b/Sources/Db/Schema/v2_1/LogDigest.php @@ -71,7 +71,5 @@ public function __construct() default: 0, ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogErrors.php b/Sources/Db/Schema/v2_1/LogErrors.php index fedebb7206f..ff079df5c5f 100644 --- a/Sources/Db/Schema/v2_1/LogErrors.php +++ b/Sources/Db/Schema/v2_1/LogErrors.php @@ -61,6 +61,7 @@ public function __construct() name: 'ip', type: 'inet', size: 16, + default: null, ), 'url' => new Column( name: 'url', @@ -143,7 +144,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogFloodcontrol.php b/Sources/Db/Schema/v2_1/LogFloodcontrol.php index d9e4eba42d8..dc8d43de0fe 100644 --- a/Sources/Db/Schema/v2_1/LogFloodcontrol.php +++ b/Sources/Db/Schema/v2_1/LogFloodcontrol.php @@ -40,6 +40,7 @@ public function __construct() name: 'ip', type: 'inet', size: 16, + not_null: true, ), 'log_time' => new Column( name: 'log_time', @@ -69,7 +70,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogGroupRequests.php b/Sources/Db/Schema/v2_1/LogGroupRequests.php index d96f4e337fd..78d28df28fd 100644 --- a/Sources/Db/Schema/v2_1/LogGroupRequests.php +++ b/Sources/Db/Schema/v2_1/LogGroupRequests.php @@ -125,7 +125,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogMarkRead.php b/Sources/Db/Schema/v2_1/LogMarkRead.php index 4bab7c5d9e0..221cd055f0c 100644 --- a/Sources/Db/Schema/v2_1/LogMarkRead.php +++ b/Sources/Db/Schema/v2_1/LogMarkRead.php @@ -70,7 +70,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogMemberNotices.php b/Sources/Db/Schema/v2_1/LogMemberNotices.php index 6095c5646e8..d78cb68a8dc 100644 --- a/Sources/Db/Schema/v2_1/LogMemberNotices.php +++ b/Sources/Db/Schema/v2_1/LogMemberNotices.php @@ -67,7 +67,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogNotify.php b/Sources/Db/Schema/v2_1/LogNotify.php index 74242bc0ed7..6b78b5fa474 100644 --- a/Sources/Db/Schema/v2_1/LogNotify.php +++ b/Sources/Db/Schema/v2_1/LogNotify.php @@ -98,7 +98,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogOnline.php b/Sources/Db/Schema/v2_1/LogOnline.php index 999a16a521e..176cb3117d6 100644 --- a/Sources/Db/Schema/v2_1/LogOnline.php +++ b/Sources/Db/Schema/v2_1/LogOnline.php @@ -66,6 +66,7 @@ public function __construct() name: 'ip', type: 'inet', size: 16, + default: null, ), 'url' => new Column( name: 'url', @@ -102,7 +103,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogPackages.php b/Sources/Db/Schema/v2_1/LogPackages.php index 7b9d7ced466..feb14eb4f6f 100644 --- a/Sources/Db/Schema/v2_1/LogPackages.php +++ b/Sources/Db/Schema/v2_1/LogPackages.php @@ -162,7 +162,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogPolls.php b/Sources/Db/Schema/v2_1/LogPolls.php index 453171779af..ea4484e6cf6 100644 --- a/Sources/Db/Schema/v2_1/LogPolls.php +++ b/Sources/Db/Schema/v2_1/LogPolls.php @@ -75,7 +75,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogReported.php b/Sources/Db/Schema/v2_1/LogReported.php index bae750ab459..809e7b50b3b 100644 --- a/Sources/Db/Schema/v2_1/LogReported.php +++ b/Sources/Db/Schema/v2_1/LogReported.php @@ -172,7 +172,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogReportedComments.php b/Sources/Db/Schema/v2_1/LogReportedComments.php index e37bc14b912..66463287ca3 100644 --- a/Sources/Db/Schema/v2_1/LogReportedComments.php +++ b/Sources/Db/Schema/v2_1/LogReportedComments.php @@ -65,6 +65,7 @@ public function __construct() name: 'member_ip', type: 'inet', size: 16, + default: null, ), 'comment' => new Column( name: 'comment', @@ -114,7 +115,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogScheduledTasks.php b/Sources/Db/Schema/v2_1/LogScheduledTasks.php index 1bc46d901cd..da222782bd4 100644 --- a/Sources/Db/Schema/v2_1/LogScheduledTasks.php +++ b/Sources/Db/Schema/v2_1/LogScheduledTasks.php @@ -72,7 +72,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogSearchMessages.php b/Sources/Db/Schema/v2_1/LogSearchMessages.php index 1683514bf3f..8bd2e6ab084 100644 --- a/Sources/Db/Schema/v2_1/LogSearchMessages.php +++ b/Sources/Db/Schema/v2_1/LogSearchMessages.php @@ -63,7 +63,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogSearchResults.php b/Sources/Db/Schema/v2_1/LogSearchResults.php index 7fa047b63fb..3d6d945678f 100644 --- a/Sources/Db/Schema/v2_1/LogSearchResults.php +++ b/Sources/Db/Schema/v2_1/LogSearchResults.php @@ -87,7 +87,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogSearchSubjects.php b/Sources/Db/Schema/v2_1/LogSearchSubjects.php index 85b4b03787c..60e79ae1a6f 100644 --- a/Sources/Db/Schema/v2_1/LogSearchSubjects.php +++ b/Sources/Db/Schema/v2_1/LogSearchSubjects.php @@ -71,7 +71,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogSearchTopics.php b/Sources/Db/Schema/v2_1/LogSearchTopics.php index 04a768eecd1..345edb06395 100644 --- a/Sources/Db/Schema/v2_1/LogSearchTopics.php +++ b/Sources/Db/Schema/v2_1/LogSearchTopics.php @@ -63,7 +63,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogSpiderHits.php b/Sources/Db/Schema/v2_1/LogSpiderHits.php index d3c57c98d26..75125a971f6 100644 --- a/Sources/Db/Schema/v2_1/LogSpiderHits.php +++ b/Sources/Db/Schema/v2_1/LogSpiderHits.php @@ -106,7 +106,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogSpiderStats.php b/Sources/Db/Schema/v2_1/LogSpiderStats.php index 67c2c54f3a3..964de3450d4 100644 --- a/Sources/Db/Schema/v2_1/LogSpiderStats.php +++ b/Sources/Db/Schema/v2_1/LogSpiderStats.php @@ -75,7 +75,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogSubscribed.php b/Sources/Db/Schema/v2_1/LogSubscribed.php index 00606af7a51..812917512a1 100644 --- a/Sources/Db/Schema/v2_1/LogSubscribed.php +++ b/Sources/Db/Schema/v2_1/LogSubscribed.php @@ -168,7 +168,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/LogTopics.php b/Sources/Db/Schema/v2_1/LogTopics.php index 15b088f21ac..8a7fa84c0fe 100644 --- a/Sources/Db/Schema/v2_1/LogTopics.php +++ b/Sources/Db/Schema/v2_1/LogTopics.php @@ -84,7 +84,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/MailQueue.php b/Sources/Db/Schema/v2_1/MailQueue.php index 6751fb879e1..35cb3e409c6 100644 --- a/Sources/Db/Schema/v2_1/MailQueue.php +++ b/Sources/Db/Schema/v2_1/MailQueue.php @@ -122,7 +122,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/MemberLogins.php b/Sources/Db/Schema/v2_1/MemberLogins.php index 448bedf8cf5..72d44dd7525 100644 --- a/Sources/Db/Schema/v2_1/MemberLogins.php +++ b/Sources/Db/Schema/v2_1/MemberLogins.php @@ -58,11 +58,13 @@ public function __construct() name: 'ip', type: 'inet', size: 16, + default: null, ), 'ip2' => new Column( name: 'ip2', type: 'inet', size: 16, + default: null, ), ]; @@ -92,7 +94,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Membergroups.php b/Sources/Db/Schema/v2_1/Membergroups.php index 908af6d2c30..d42ce72e8ea 100644 --- a/Sources/Db/Schema/v2_1/Membergroups.php +++ b/Sources/Db/Schema/v2_1/Membergroups.php @@ -210,7 +210,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Members.php b/Sources/Db/Schema/v2_1/Members.php index 7f1c3572c8b..81a884d7834 100644 --- a/Sources/Db/Schema/v2_1/Members.php +++ b/Sources/Db/Schema/v2_1/Members.php @@ -224,11 +224,13 @@ public function __construct() name: 'member_ip', type: 'inet', size: 16, + default: null, ), 'member_ip2' => new Column( name: 'member_ip2', type: 'inet', size: 16, + default: null, ), 'secret_question' => new Column( name: 'secret_question', @@ -514,7 +516,5 @@ public function __construct() ], ); } - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Mentions.php b/Sources/Db/Schema/v2_1/Mentions.php index cf0ecf647b2..1d3ac970851 100644 --- a/Sources/Db/Schema/v2_1/Mentions.php +++ b/Sources/Db/Schema/v2_1/Mentions.php @@ -102,7 +102,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/MessageIcons.php b/Sources/Db/Schema/v2_1/MessageIcons.php index 2a96064170a..bbc8280691c 100644 --- a/Sources/Db/Schema/v2_1/MessageIcons.php +++ b/Sources/Db/Schema/v2_1/MessageIcons.php @@ -168,7 +168,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Messages.php b/Sources/Db/Schema/v2_1/Messages.php index 2e6ed12f437..ec32c98dbb4 100644 --- a/Sources/Db/Schema/v2_1/Messages.php +++ b/Sources/Db/Schema/v2_1/Messages.php @@ -128,6 +128,7 @@ public function __construct() name: 'poster_ip', type: 'inet', size: 16, + default: null, ), 'smileys_enabled' => new Column( name: 'smileys_enabled', @@ -306,7 +307,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/ModeratorGroups.php b/Sources/Db/Schema/v2_1/ModeratorGroups.php index bb2cb04a7a4..0b48096a5e8 100644 --- a/Sources/Db/Schema/v2_1/ModeratorGroups.php +++ b/Sources/Db/Schema/v2_1/ModeratorGroups.php @@ -63,7 +63,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Moderators.php b/Sources/Db/Schema/v2_1/Moderators.php index 6f68363df52..ea10b8a00b9 100644 --- a/Sources/Db/Schema/v2_1/Moderators.php +++ b/Sources/Db/Schema/v2_1/Moderators.php @@ -63,7 +63,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/PackageServers.php b/Sources/Db/Schema/v2_1/PackageServers.php index da62ed09e7c..1af55082818 100644 --- a/Sources/Db/Schema/v2_1/PackageServers.php +++ b/Sources/Db/Schema/v2_1/PackageServers.php @@ -102,7 +102,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/PermissionProfiles.php b/Sources/Db/Schema/v2_1/PermissionProfiles.php index 78080e1bf45..c17d950ff55 100644 --- a/Sources/Db/Schema/v2_1/PermissionProfiles.php +++ b/Sources/Db/Schema/v2_1/PermissionProfiles.php @@ -89,7 +89,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Permissions.php b/Sources/Db/Schema/v2_1/Permissions.php index 789f9ab8f84..08f0f961d7f 100644 --- a/Sources/Db/Schema/v2_1/Permissions.php +++ b/Sources/Db/Schema/v2_1/Permissions.php @@ -284,7 +284,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/PersonalMessages.php b/Sources/Db/Schema/v2_1/PersonalMessages.php index 5da9e6248c0..75a2c484e4a 100644 --- a/Sources/Db/Schema/v2_1/PersonalMessages.php +++ b/Sources/Db/Schema/v2_1/PersonalMessages.php @@ -129,7 +129,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/PmLabeledMessages.php b/Sources/Db/Schema/v2_1/PmLabeledMessages.php index ce302fc216a..d3092e229bb 100644 --- a/Sources/Db/Schema/v2_1/PmLabeledMessages.php +++ b/Sources/Db/Schema/v2_1/PmLabeledMessages.php @@ -63,7 +63,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/PmLabels.php b/Sources/Db/Schema/v2_1/PmLabels.php index 6a2b9fdd900..47475c5c86d 100644 --- a/Sources/Db/Schema/v2_1/PmLabels.php +++ b/Sources/Db/Schema/v2_1/PmLabels.php @@ -69,7 +69,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/PmRecipients.php b/Sources/Db/Schema/v2_1/PmRecipients.php index 011cb258fec..2490c52db77 100644 --- a/Sources/Db/Schema/v2_1/PmRecipients.php +++ b/Sources/Db/Schema/v2_1/PmRecipients.php @@ -112,7 +112,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/PmRules.php b/Sources/Db/Schema/v2_1/PmRules.php index 61994d16ad4..de53f625aeb 100644 --- a/Sources/Db/Schema/v2_1/PmRules.php +++ b/Sources/Db/Schema/v2_1/PmRules.php @@ -108,7 +108,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/PollChoices.php b/Sources/Db/Schema/v2_1/PollChoices.php index 36f314dafce..bcdcd951e65 100644 --- a/Sources/Db/Schema/v2_1/PollChoices.php +++ b/Sources/Db/Schema/v2_1/PollChoices.php @@ -77,7 +77,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Polls.php b/Sources/Db/Schema/v2_1/Polls.php index 1271cfe6a66..80c155077b9 100644 --- a/Sources/Db/Schema/v2_1/Polls.php +++ b/Sources/Db/Schema/v2_1/Polls.php @@ -131,7 +131,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Qanda.php b/Sources/Db/Schema/v2_1/Qanda.php index 3864d43fe0b..bddb6c1563f 100644 --- a/Sources/Db/Schema/v2_1/Qanda.php +++ b/Sources/Db/Schema/v2_1/Qanda.php @@ -83,7 +83,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/ScheduledTasks.php b/Sources/Db/Schema/v2_1/ScheduledTasks.php index 317dd41e021..0d67d89aee1 100644 --- a/Sources/Db/Schema/v2_1/ScheduledTasks.php +++ b/Sources/Db/Schema/v2_1/ScheduledTasks.php @@ -247,7 +247,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Sessions.php b/Sources/Db/Schema/v2_1/Sessions.php index 9d087af6f72..bd141cf681b 100644 --- a/Sources/Db/Schema/v2_1/Sessions.php +++ b/Sources/Db/Schema/v2_1/Sessions.php @@ -67,7 +67,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Settings.php b/Sources/Db/Schema/v2_1/Settings.php index ae650e5f758..fc25eee96e5 100644 --- a/Sources/Db/Schema/v2_1/Settings.php +++ b/Sources/Db/Schema/v2_1/Settings.php @@ -888,9 +888,5 @@ public function __construct() ], ), ]; - - parent::__construct(); - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/SmileyFiles.php b/Sources/Db/Schema/v2_1/SmileyFiles.php index e4cd6004966..c78a1c9dad7 100644 --- a/Sources/Db/Schema/v2_1/SmileyFiles.php +++ b/Sources/Db/Schema/v2_1/SmileyFiles.php @@ -71,7 +71,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Smileys.php b/Sources/Db/Schema/v2_1/Smileys.php index b1da505ae38..138331eaeff 100644 --- a/Sources/Db/Schema/v2_1/Smileys.php +++ b/Sources/Db/Schema/v2_1/Smileys.php @@ -234,7 +234,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Spiders.php b/Sources/Db/Schema/v2_1/Spiders.php index 95f1ab2f1f6..e56c0683bec 100644 --- a/Sources/Db/Schema/v2_1/Spiders.php +++ b/Sources/Db/Schema/v2_1/Spiders.php @@ -198,7 +198,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Subscriptions.php b/Sources/Db/Schema/v2_1/Subscriptions.php index 451678630be..6ed5a51bf98 100644 --- a/Sources/Db/Schema/v2_1/Subscriptions.php +++ b/Sources/Db/Schema/v2_1/Subscriptions.php @@ -131,7 +131,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Themes.php b/Sources/Db/Schema/v2_1/Themes.php index 7fa4cf45bbe..9f5ed168b88 100644 --- a/Sources/Db/Schema/v2_1/Themes.php +++ b/Sources/Db/Schema/v2_1/Themes.php @@ -170,7 +170,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/Topics.php b/Sources/Db/Schema/v2_1/Topics.php index 7472a5cc9fd..3129dd822b0 100644 --- a/Sources/Db/Schema/v2_1/Topics.php +++ b/Sources/Db/Schema/v2_1/Topics.php @@ -269,7 +269,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/UserAlerts.php b/Sources/Db/Schema/v2_1/UserAlerts.php index eb7843586f8..ede222962ce 100644 --- a/Sources/Db/Schema/v2_1/UserAlerts.php +++ b/Sources/Db/Schema/v2_1/UserAlerts.php @@ -132,7 +132,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/UserAlertsPrefs.php b/Sources/Db/Schema/v2_1/UserAlertsPrefs.php index 02f632dfd9c..73cdab9a67f 100644 --- a/Sources/Db/Schema/v2_1/UserAlertsPrefs.php +++ b/Sources/Db/Schema/v2_1/UserAlertsPrefs.php @@ -226,7 +226,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/UserDrafts.php b/Sources/Db/Schema/v2_1/UserDrafts.php index ed155b228e3..6ce19d96cea 100644 --- a/Sources/Db/Schema/v2_1/UserDrafts.php +++ b/Sources/Db/Schema/v2_1/UserDrafts.php @@ -155,7 +155,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v2_1/UserLikes.php b/Sources/Db/Schema/v2_1/UserLikes.php index 7aa0cc676e7..e693698a011 100644 --- a/Sources/Db/Schema/v2_1/UserLikes.php +++ b/Sources/Db/Schema/v2_1/UserLikes.php @@ -98,7 +98,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/AdminInfoFiles.php b/Sources/Db/Schema/v3_0/AdminInfoFiles.php index 238643326e5..204f07c8708 100644 --- a/Sources/Db/Schema/v3_0/AdminInfoFiles.php +++ b/Sources/Db/Schema/v3_0/AdminInfoFiles.php @@ -142,7 +142,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/ApprovalQueue.php b/Sources/Db/Schema/v3_0/ApprovalQueue.php index 9443facdeb3..8ae34043242 100644 --- a/Sources/Db/Schema/v3_0/ApprovalQueue.php +++ b/Sources/Db/Schema/v3_0/ApprovalQueue.php @@ -57,7 +57,5 @@ public function __construct() default: 0, ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Attachments.php b/Sources/Db/Schema/v3_0/Attachments.php index 0ce9d2c2630..da9d498bd00 100644 --- a/Sources/Db/Schema/v3_0/Attachments.php +++ b/Sources/Db/Schema/v3_0/Attachments.php @@ -187,7 +187,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/BackgroundTasks.php b/Sources/Db/Schema/v3_0/BackgroundTasks.php index efdca3f210b..4b07f655b1a 100644 --- a/Sources/Db/Schema/v3_0/BackgroundTasks.php +++ b/Sources/Db/Schema/v3_0/BackgroundTasks.php @@ -81,7 +81,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/BanGroups.php b/Sources/Db/Schema/v3_0/BanGroups.php index 221135416a2..e043169946d 100644 --- a/Sources/Db/Schema/v3_0/BanGroups.php +++ b/Sources/Db/Schema/v3_0/BanGroups.php @@ -63,6 +63,7 @@ public function __construct() unsigned: true, not_null: false, default: null, + drop_default: true, ), 'cannot_access' => new Column( name: 'cannot_access', @@ -116,7 +117,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/BanItems.php b/Sources/Db/Schema/v3_0/BanItems.php index 9139af50560..a7b0a2b909a 100644 --- a/Sources/Db/Schema/v3_0/BanItems.php +++ b/Sources/Db/Schema/v3_0/BanItems.php @@ -54,11 +54,13 @@ public function __construct() name: 'ip_low', type: 'inet', size: 16, + default: null, ), 'ip_high' => new Column( name: 'ip_high', type: 'inet', size: 16, + default: null, ), 'hostname' => new Column( name: 'hostname', @@ -119,7 +121,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/BoardPermissions.php b/Sources/Db/Schema/v3_0/BoardPermissions.php index 0bc1b076a95..6cfa3a85b89 100644 --- a/Sources/Db/Schema/v3_0/BoardPermissions.php +++ b/Sources/Db/Schema/v3_0/BoardPermissions.php @@ -1632,7 +1632,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/BoardPermissionsView.php b/Sources/Db/Schema/v3_0/BoardPermissionsView.php index 66b9d4b42f5..f05aadd018a 100644 --- a/Sources/Db/Schema/v3_0/BoardPermissionsView.php +++ b/Sources/Db/Schema/v3_0/BoardPermissionsView.php @@ -98,7 +98,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Boards.php b/Sources/Db/Schema/v3_0/Boards.php index ee3eb54d40e..136fbab854c 100644 --- a/Sources/Db/Schema/v3_0/Boards.php +++ b/Sources/Db/Schema/v3_0/Boards.php @@ -244,7 +244,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Calendar.php b/Sources/Db/Schema/v3_0/Calendar.php index f0af14ee2e2..2ce6fe81f84 100644 --- a/Sources/Db/Schema/v3_0/Calendar.php +++ b/Sources/Db/Schema/v3_0/Calendar.php @@ -593,7 +593,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Categories.php b/Sources/Db/Schema/v3_0/Categories.php index 4058603d2ba..be2555becd7 100644 --- a/Sources/Db/Schema/v3_0/Categories.php +++ b/Sources/Db/Schema/v3_0/Categories.php @@ -99,7 +99,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/CustomFields.php b/Sources/Db/Schema/v3_0/CustomFields.php index eaefdf307a4..febd5f8a8c4 100644 --- a/Sources/Db/Schema/v3_0/CustomFields.php +++ b/Sources/Db/Schema/v3_0/CustomFields.php @@ -278,7 +278,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/GroupModerators.php b/Sources/Db/Schema/v3_0/GroupModerators.php index ae1a87dc946..c0aac55929f 100644 --- a/Sources/Db/Schema/v3_0/GroupModerators.php +++ b/Sources/Db/Schema/v3_0/GroupModerators.php @@ -65,7 +65,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Initialize/Base.php b/Sources/Db/Schema/v3_0/Initialize/Base.php index 498b91235d5..94cc1aed0a7 100644 --- a/Sources/Db/Schema/v3_0/Initialize/Base.php +++ b/Sources/Db/Schema/v3_0/Initialize/Base.php @@ -31,21 +31,41 @@ class Base * Public methods ****************/ - public function __construct(?string $version) + /** + * Constructor. + * + * @param string $version Version of the database engine. + */ + public function __construct(string $version) { $this->version = $version; } + /** + * Gets queries that create custom SQL functions and operators. + * + * @return array SQL queries. + */ public function getAll(): array { return $this->functions() + $this->operators(); } + /** + * Gets queries that create custom SQL functions. + * + * @return array SQL queries. + */ public function functions(): array { return []; } + /** + * Gets queries that create custom SQL operators. + * + * @return array SQL queries. + */ public function operators(): array { return []; diff --git a/Sources/Db/Schema/v3_0/LogActions.php b/Sources/Db/Schema/v3_0/LogActions.php index 416c399eb8c..34cb5751a9e 100644 --- a/Sources/Db/Schema/v3_0/LogActions.php +++ b/Sources/Db/Schema/v3_0/LogActions.php @@ -68,6 +68,7 @@ public function __construct() name: 'ip', type: 'inet', size: 16, + default: null, ), 'action' => new Column( name: 'action', @@ -165,7 +166,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogActivity.php b/Sources/Db/Schema/v3_0/LogActivity.php index 6d121e4c466..a2f9693e2d3 100644 --- a/Sources/Db/Schema/v3_0/LogActivity.php +++ b/Sources/Db/Schema/v3_0/LogActivity.php @@ -88,7 +88,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogBanned.php b/Sources/Db/Schema/v3_0/LogBanned.php index 0e0d7aa4dca..58de5bb6515 100644 --- a/Sources/Db/Schema/v3_0/LogBanned.php +++ b/Sources/Db/Schema/v3_0/LogBanned.php @@ -54,6 +54,7 @@ public function __construct() name: 'ip', type: 'inet', size: 16, + default: null, ), 'email' => new Column( name: 'email', @@ -89,7 +90,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogBoards.php b/Sources/Db/Schema/v3_0/LogBoards.php index 79942402cb0..a6b5f0ca43f 100644 --- a/Sources/Db/Schema/v3_0/LogBoards.php +++ b/Sources/Db/Schema/v3_0/LogBoards.php @@ -72,7 +72,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogComments.php b/Sources/Db/Schema/v3_0/LogComments.php index f7d2d8f4013..fb84d13e9bd 100644 --- a/Sources/Db/Schema/v3_0/LogComments.php +++ b/Sources/Db/Schema/v3_0/LogComments.php @@ -140,7 +140,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogDigest.php b/Sources/Db/Schema/v3_0/LogDigest.php index 94899261972..654fd786477 100644 --- a/Sources/Db/Schema/v3_0/LogDigest.php +++ b/Sources/Db/Schema/v3_0/LogDigest.php @@ -71,7 +71,5 @@ public function __construct() default: 0, ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogErrors.php b/Sources/Db/Schema/v3_0/LogErrors.php index bd8d2c7779d..3870599523f 100644 --- a/Sources/Db/Schema/v3_0/LogErrors.php +++ b/Sources/Db/Schema/v3_0/LogErrors.php @@ -61,6 +61,7 @@ public function __construct() name: 'ip', type: 'inet', size: 16, + default: null, ), 'url' => new Column( name: 'url', @@ -141,7 +142,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogFloodcontrol.php b/Sources/Db/Schema/v3_0/LogFloodcontrol.php index 4d4c05bcee4..f770dfe05a2 100644 --- a/Sources/Db/Schema/v3_0/LogFloodcontrol.php +++ b/Sources/Db/Schema/v3_0/LogFloodcontrol.php @@ -71,7 +71,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogGroupRequests.php b/Sources/Db/Schema/v3_0/LogGroupRequests.php index 889963caed9..c592571a03f 100644 --- a/Sources/Db/Schema/v3_0/LogGroupRequests.php +++ b/Sources/Db/Schema/v3_0/LogGroupRequests.php @@ -132,7 +132,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogMarkRead.php b/Sources/Db/Schema/v3_0/LogMarkRead.php index 7f9e498c064..ee6ceb8b1a4 100644 --- a/Sources/Db/Schema/v3_0/LogMarkRead.php +++ b/Sources/Db/Schema/v3_0/LogMarkRead.php @@ -72,7 +72,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogMemberNotices.php b/Sources/Db/Schema/v3_0/LogMemberNotices.php index 3631f61d880..6c61bf5b4dd 100644 --- a/Sources/Db/Schema/v3_0/LogMemberNotices.php +++ b/Sources/Db/Schema/v3_0/LogMemberNotices.php @@ -67,7 +67,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogNotify.php b/Sources/Db/Schema/v3_0/LogNotify.php index fce6b1f2e48..23373ae5f1b 100644 --- a/Sources/Db/Schema/v3_0/LogNotify.php +++ b/Sources/Db/Schema/v3_0/LogNotify.php @@ -101,7 +101,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogOnline.php b/Sources/Db/Schema/v3_0/LogOnline.php index 2fbe34210a5..006dfa087aa 100644 --- a/Sources/Db/Schema/v3_0/LogOnline.php +++ b/Sources/Db/Schema/v3_0/LogOnline.php @@ -67,6 +67,7 @@ public function __construct() name: 'ip', type: 'inet', size: 16, + default: null, ), 'url' => new Column( name: 'url', @@ -103,7 +104,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogPackages.php b/Sources/Db/Schema/v3_0/LogPackages.php index 3725188dc1b..b8e9e9c7b6e 100644 --- a/Sources/Db/Schema/v3_0/LogPackages.php +++ b/Sources/Db/Schema/v3_0/LogPackages.php @@ -182,7 +182,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogPolls.php b/Sources/Db/Schema/v3_0/LogPolls.php index 439d2b6d412..dfe6d70f7b1 100644 --- a/Sources/Db/Schema/v3_0/LogPolls.php +++ b/Sources/Db/Schema/v3_0/LogPolls.php @@ -75,7 +75,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogReported.php b/Sources/Db/Schema/v3_0/LogReported.php index 97409d59cc6..d623d092f79 100644 --- a/Sources/Db/Schema/v3_0/LogReported.php +++ b/Sources/Db/Schema/v3_0/LogReported.php @@ -172,7 +172,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogReportedComments.php b/Sources/Db/Schema/v3_0/LogReportedComments.php index 4ff9cc925d3..f78886777a7 100644 --- a/Sources/Db/Schema/v3_0/LogReportedComments.php +++ b/Sources/Db/Schema/v3_0/LogReportedComments.php @@ -65,6 +65,7 @@ public function __construct() name: 'member_ip', type: 'inet', size: 16, + default: null, ), 'comment' => new Column( name: 'comment', @@ -114,7 +115,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogScheduledTasks.php b/Sources/Db/Schema/v3_0/LogScheduledTasks.php index cfe871b95ed..502e70a1a2b 100644 --- a/Sources/Db/Schema/v3_0/LogScheduledTasks.php +++ b/Sources/Db/Schema/v3_0/LogScheduledTasks.php @@ -72,7 +72,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogSearchMessages.php b/Sources/Db/Schema/v3_0/LogSearchMessages.php index a276eded7a4..762dc5b5713 100644 --- a/Sources/Db/Schema/v3_0/LogSearchMessages.php +++ b/Sources/Db/Schema/v3_0/LogSearchMessages.php @@ -65,7 +65,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogSearchResults.php b/Sources/Db/Schema/v3_0/LogSearchResults.php index ffa380d8c42..db2a3d2ed4b 100644 --- a/Sources/Db/Schema/v3_0/LogSearchResults.php +++ b/Sources/Db/Schema/v3_0/LogSearchResults.php @@ -89,7 +89,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogSearchSubjects.php b/Sources/Db/Schema/v3_0/LogSearchSubjects.php index 6e82688886f..0cb1416ed12 100644 --- a/Sources/Db/Schema/v3_0/LogSearchSubjects.php +++ b/Sources/Db/Schema/v3_0/LogSearchSubjects.php @@ -73,7 +73,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogSearchTopics.php b/Sources/Db/Schema/v3_0/LogSearchTopics.php index 7284a2892ae..5686bcc8ebe 100644 --- a/Sources/Db/Schema/v3_0/LogSearchTopics.php +++ b/Sources/Db/Schema/v3_0/LogSearchTopics.php @@ -65,7 +65,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogSpiderHits.php b/Sources/Db/Schema/v3_0/LogSpiderHits.php index 0533b5479a4..41192ee2897 100644 --- a/Sources/Db/Schema/v3_0/LogSpiderHits.php +++ b/Sources/Db/Schema/v3_0/LogSpiderHits.php @@ -90,7 +90,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogSpiderStats.php b/Sources/Db/Schema/v3_0/LogSpiderStats.php index 9e31aaa7a82..d2464ae665b 100644 --- a/Sources/Db/Schema/v3_0/LogSpiderStats.php +++ b/Sources/Db/Schema/v3_0/LogSpiderStats.php @@ -77,7 +77,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogSubscribed.php b/Sources/Db/Schema/v3_0/LogSubscribed.php index 31da2bde37f..4bcb192df2a 100644 --- a/Sources/Db/Schema/v3_0/LogSubscribed.php +++ b/Sources/Db/Schema/v3_0/LogSubscribed.php @@ -156,7 +156,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/LogTopics.php b/Sources/Db/Schema/v3_0/LogTopics.php index 8b5fb6580f5..cc898a6a3f0 100644 --- a/Sources/Db/Schema/v3_0/LogTopics.php +++ b/Sources/Db/Schema/v3_0/LogTopics.php @@ -86,7 +86,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/MailQueue.php b/Sources/Db/Schema/v3_0/MailQueue.php index bd455e1d9a8..f2c218c348f 100644 --- a/Sources/Db/Schema/v3_0/MailQueue.php +++ b/Sources/Db/Schema/v3_0/MailQueue.php @@ -141,7 +141,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/MemberLogins.php b/Sources/Db/Schema/v3_0/MemberLogins.php index 8574710aa12..3b6957302aa 100644 --- a/Sources/Db/Schema/v3_0/MemberLogins.php +++ b/Sources/Db/Schema/v3_0/MemberLogins.php @@ -58,11 +58,13 @@ public function __construct() name: 'ip', type: 'inet', size: 16, + default: null, ), 'ip2' => new Column( name: 'ip2', type: 'inet', size: 16, + default: null, ), ]; @@ -92,7 +94,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Membergroups.php b/Sources/Db/Schema/v3_0/Membergroups.php index 247e01c4fef..2dc5c195f11 100644 --- a/Sources/Db/Schema/v3_0/Membergroups.php +++ b/Sources/Db/Schema/v3_0/Membergroups.php @@ -210,7 +210,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Members.php b/Sources/Db/Schema/v3_0/Members.php index 1c581787f68..e073da9005c 100644 --- a/Sources/Db/Schema/v3_0/Members.php +++ b/Sources/Db/Schema/v3_0/Members.php @@ -134,13 +134,6 @@ public function __construct() not_null: true, default: 0, ), - 'mod_prefs' => new Column( - name: 'mod_prefs', - type: 'varchar', - size: 20, - not_null: true, - default: '', - ), 'passwd' => new Column( name: 'passwd', type: 'varchar', @@ -224,11 +217,13 @@ public function __construct() name: 'member_ip', type: 'inet', size: 16, + default: null, ), 'member_ip2' => new Column( name: 'member_ip2', type: 'inet', size: 16, + default: null, ), 'secret_question' => new Column( name: 'secret_question', @@ -542,7 +537,5 @@ public function __construct() ], ); } - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Mentions.php b/Sources/Db/Schema/v3_0/Mentions.php index 6712e7bb23a..bc9ac69f275 100644 --- a/Sources/Db/Schema/v3_0/Mentions.php +++ b/Sources/Db/Schema/v3_0/Mentions.php @@ -102,7 +102,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/MessageIcons.php b/Sources/Db/Schema/v3_0/MessageIcons.php index af769018f9d..9e477b6e431 100644 --- a/Sources/Db/Schema/v3_0/MessageIcons.php +++ b/Sources/Db/Schema/v3_0/MessageIcons.php @@ -168,7 +168,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Messages.php b/Sources/Db/Schema/v3_0/Messages.php index fb0519ac288..a540f09d5bf 100644 --- a/Sources/Db/Schema/v3_0/Messages.php +++ b/Sources/Db/Schema/v3_0/Messages.php @@ -129,6 +129,7 @@ public function __construct() name: 'poster_ip', type: 'inet', size: 16, + default: null, ), 'smileys_enabled' => new Column( name: 'smileys_enabled', @@ -320,7 +321,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/ModeratorGroups.php b/Sources/Db/Schema/v3_0/ModeratorGroups.php index 82a9c2902b3..77205911d53 100644 --- a/Sources/Db/Schema/v3_0/ModeratorGroups.php +++ b/Sources/Db/Schema/v3_0/ModeratorGroups.php @@ -65,7 +65,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Moderators.php b/Sources/Db/Schema/v3_0/Moderators.php index 25dd7141d65..24535a275ad 100644 --- a/Sources/Db/Schema/v3_0/Moderators.php +++ b/Sources/Db/Schema/v3_0/Moderators.php @@ -63,7 +63,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/PackageServers.php b/Sources/Db/Schema/v3_0/PackageServers.php index 227e0c6c09b..a6f5d17001f 100644 --- a/Sources/Db/Schema/v3_0/PackageServers.php +++ b/Sources/Db/Schema/v3_0/PackageServers.php @@ -102,7 +102,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/PermissionProfiles.php b/Sources/Db/Schema/v3_0/PermissionProfiles.php index 20c51cf4fc6..c38e3810c9d 100644 --- a/Sources/Db/Schema/v3_0/PermissionProfiles.php +++ b/Sources/Db/Schema/v3_0/PermissionProfiles.php @@ -89,7 +89,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Permissions.php b/Sources/Db/Schema/v3_0/Permissions.php index 3842f480007..12f440b0520 100644 --- a/Sources/Db/Schema/v3_0/Permissions.php +++ b/Sources/Db/Schema/v3_0/Permissions.php @@ -278,7 +278,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/PersonalMessages.php b/Sources/Db/Schema/v3_0/PersonalMessages.php index ab4983a079e..6353eb2c01c 100644 --- a/Sources/Db/Schema/v3_0/PersonalMessages.php +++ b/Sources/Db/Schema/v3_0/PersonalMessages.php @@ -136,7 +136,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/PmLabeledMessages.php b/Sources/Db/Schema/v3_0/PmLabeledMessages.php index 7dc8d2a1e94..0da586f0e19 100644 --- a/Sources/Db/Schema/v3_0/PmLabeledMessages.php +++ b/Sources/Db/Schema/v3_0/PmLabeledMessages.php @@ -65,7 +65,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/PmLabels.php b/Sources/Db/Schema/v3_0/PmLabels.php index f20e4107e61..dd5929aaee8 100644 --- a/Sources/Db/Schema/v3_0/PmLabels.php +++ b/Sources/Db/Schema/v3_0/PmLabels.php @@ -69,7 +69,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/PmRecipients.php b/Sources/Db/Schema/v3_0/PmRecipients.php index 94568ae0bfa..74ad5947c16 100644 --- a/Sources/Db/Schema/v3_0/PmRecipients.php +++ b/Sources/Db/Schema/v3_0/PmRecipients.php @@ -115,7 +115,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/PmRules.php b/Sources/Db/Schema/v3_0/PmRules.php index 1556ed77eb9..6310d6af893 100644 --- a/Sources/Db/Schema/v3_0/PmRules.php +++ b/Sources/Db/Schema/v3_0/PmRules.php @@ -108,7 +108,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/PollChoices.php b/Sources/Db/Schema/v3_0/PollChoices.php index d91a48f59a7..cd4ec9f36a2 100644 --- a/Sources/Db/Schema/v3_0/PollChoices.php +++ b/Sources/Db/Schema/v3_0/PollChoices.php @@ -79,7 +79,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Polls.php b/Sources/Db/Schema/v3_0/Polls.php index 62e325b3a81..15fe43979be 100644 --- a/Sources/Db/Schema/v3_0/Polls.php +++ b/Sources/Db/Schema/v3_0/Polls.php @@ -132,7 +132,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Qanda.php b/Sources/Db/Schema/v3_0/Qanda.php index 6de1a883a7c..579c4912a59 100644 --- a/Sources/Db/Schema/v3_0/Qanda.php +++ b/Sources/Db/Schema/v3_0/Qanda.php @@ -83,7 +83,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/ScheduledTasks.php b/Sources/Db/Schema/v3_0/ScheduledTasks.php index 0a590e642b7..d8012af83f8 100644 --- a/Sources/Db/Schema/v3_0/ScheduledTasks.php +++ b/Sources/Db/Schema/v3_0/ScheduledTasks.php @@ -247,7 +247,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Sessions.php b/Sources/Db/Schema/v3_0/Sessions.php index c69cf0ca6d8..9082dee99b4 100644 --- a/Sources/Db/Schema/v3_0/Sessions.php +++ b/Sources/Db/Schema/v3_0/Sessions.php @@ -67,7 +67,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Settings.php b/Sources/Db/Schema/v3_0/Settings.php index c117a02ced0..96d78a48350 100644 --- a/Sources/Db/Schema/v3_0/Settings.php +++ b/Sources/Db/Schema/v3_0/Settings.php @@ -893,7 +893,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/SmileyFiles.php b/Sources/Db/Schema/v3_0/SmileyFiles.php index d9a989b74a8..d370915cf3d 100644 --- a/Sources/Db/Schema/v3_0/SmileyFiles.php +++ b/Sources/Db/Schema/v3_0/SmileyFiles.php @@ -303,7 +303,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Smileys.php b/Sources/Db/Schema/v3_0/Smileys.php index a3ef276d46e..8d4e222ce4b 100644 --- a/Sources/Db/Schema/v3_0/Smileys.php +++ b/Sources/Db/Schema/v3_0/Smileys.php @@ -278,7 +278,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Spiders.php b/Sources/Db/Schema/v3_0/Spiders.php index f39abd760b6..2e2498b7a46 100644 --- a/Sources/Db/Schema/v3_0/Spiders.php +++ b/Sources/Db/Schema/v3_0/Spiders.php @@ -198,7 +198,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Subscriptions.php b/Sources/Db/Schema/v3_0/Subscriptions.php index 38dac28db31..5d70c275476 100644 --- a/Sources/Db/Schema/v3_0/Subscriptions.php +++ b/Sources/Db/Schema/v3_0/Subscriptions.php @@ -131,7 +131,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Themes.php b/Sources/Db/Schema/v3_0/Themes.php index 7f479afe11c..bfbf8bb7e5b 100644 --- a/Sources/Db/Schema/v3_0/Themes.php +++ b/Sources/Db/Schema/v3_0/Themes.php @@ -150,7 +150,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/Topics.php b/Sources/Db/Schema/v3_0/Topics.php index cc0588310ab..c174fdb0136 100644 --- a/Sources/Db/Schema/v3_0/Topics.php +++ b/Sources/Db/Schema/v3_0/Topics.php @@ -269,7 +269,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/UserAlerts.php b/Sources/Db/Schema/v3_0/UserAlerts.php index 80e5dc358a3..169f11d477a 100644 --- a/Sources/Db/Schema/v3_0/UserAlerts.php +++ b/Sources/Db/Schema/v3_0/UserAlerts.php @@ -132,7 +132,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/UserAlertsPrefs.php b/Sources/Db/Schema/v3_0/UserAlertsPrefs.php index 39217ce40f2..55cc55f49ac 100644 --- a/Sources/Db/Schema/v3_0/UserAlertsPrefs.php +++ b/Sources/Db/Schema/v3_0/UserAlertsPrefs.php @@ -228,7 +228,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/UserDrafts.php b/Sources/Db/Schema/v3_0/UserDrafts.php index 52ac28dd992..9f72b50f41b 100644 --- a/Sources/Db/Schema/v3_0/UserDrafts.php +++ b/Sources/Db/Schema/v3_0/UserDrafts.php @@ -155,7 +155,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Db/Schema/v3_0/UserLikes.php b/Sources/Db/Schema/v3_0/UserLikes.php index 6fbd37d72c9..a49cb9ebc81 100644 --- a/Sources/Db/Schema/v3_0/UserLikes.php +++ b/Sources/Db/Schema/v3_0/UserLikes.php @@ -101,7 +101,5 @@ public function __construct() ], ), ]; - - parent::__construct(); } } diff --git a/Sources/Maintenance/Cleanup/CleanupBase.php b/Sources/Maintenance/Cleanup/CleanupBase.php index 4f37911097c..7bdce49640d 100644 --- a/Sources/Maintenance/Cleanup/CleanupBase.php +++ b/Sources/Maintenance/Cleanup/CleanupBase.php @@ -38,9 +38,7 @@ abstract class CleanupBase implements SubStepInterface ****************/ /** - * Check if the task should be performed or not. * - * @return bool True if this task needs to be run, false otherwise. */ public function isCandidate(): bool { diff --git a/Sources/Maintenance/Cleanup/v3_0/OldFiles.php b/Sources/Maintenance/Cleanup/OldFilesBase.php similarity index 91% rename from Sources/Maintenance/Cleanup/v3_0/OldFiles.php rename to Sources/Maintenance/Cleanup/OldFilesBase.php index 1f04f87e288..7d376fea788 100644 --- a/Sources/Maintenance/Cleanup/v3_0/OldFiles.php +++ b/Sources/Maintenance/Cleanup/OldFilesBase.php @@ -13,13 +13,16 @@ declare(strict_types=1); -namespace SMF\Maintenance\Cleanup\v3_0; +namespace SMF\Maintenance\Cleanup; use SMF\Config; -use SMF\Maintenance\Cleanup\CleanupBase; use SMF\Utils; -class OldFiles extends CleanupBase +/** + * Base class for cleanup tasks that delete files that have been removed in a + * new version of SMF. + */ +abstract class OldFilesBase extends CleanupBase { /******************* * Public properties @@ -37,7 +40,7 @@ class OldFiles extends CleanupBase /** * @var array * - * List of files removed in SMF 3.0. + * List of files removed in the relevant version of SMF. */ protected array $removed = [ // Files in the Themes directory. @@ -57,9 +60,7 @@ class OldFiles extends CleanupBase ****************/ /** - * Check if the task should be performed or not. * - * @return bool True if this task needs to be run, false otherwise. */ public function isCandidate(): bool { diff --git a/Sources/Maintenance/Cleanup/v2_1/OldFiles.php b/Sources/Maintenance/Cleanup/v2_1/OldFiles.php index e69755f6632..7b0717e3426 100644 --- a/Sources/Maintenance/Cleanup/v2_1/OldFiles.php +++ b/Sources/Maintenance/Cleanup/v2_1/OldFiles.php @@ -15,10 +15,10 @@ namespace SMF\Maintenance\Cleanup\v2_1; -use SMF\Maintenance\Cleanup\v3_0\OldFiles as OldFilesBase; +use SMF\Maintenance\Cleanup\OldFilesBase; /** - * Just like the v3_0 version of OldFiles, but with a different list of files. + * Deletes files that were present in SMF 2.0 but not in SMF 2.1. */ class OldFiles extends OldFilesBase { diff --git a/Sources/Maintenance/Cleanup/v3_0/TasksDirCase.php b/Sources/Maintenance/Cleanup/v3_0/TasksDirCase.php index 6bf62068a1b..140713af43f 100644 --- a/Sources/Maintenance/Cleanup/v3_0/TasksDirCase.php +++ b/Sources/Maintenance/Cleanup/v3_0/TasksDirCase.php @@ -35,9 +35,7 @@ class TasksDirCase extends CleanupBase ****************/ /** - * Check if the task should be performed or not. * - * @return bool True if this task needs to be run, false otherwise. */ public function isCandidate(): bool { diff --git a/Sources/Maintenance/Maintenance.php b/Sources/Maintenance/Maintenance.php index 2043f292640..5c9997a6396 100644 --- a/Sources/Maintenance/Maintenance.php +++ b/Sources/Maintenance/Maintenance.php @@ -228,7 +228,7 @@ class Maintenance public function __construct() { Security::frameOptionsHeader('SAMEORIGIN'); - self::$theme_dir = \dirname(SMF_SETTINGS_FILE) . '/Themes/default'; + self::$theme_dir = self::getBaseDir() . '/Themes/default'; // This might be overwritten by the tool, but we need a default value. self::$context['started'] = (int) TIME_START; @@ -744,12 +744,17 @@ public static function loginWithDatabasePassword( */ public static function getTimeElapsed(): string { - // How long have we been running this? - $elapsed = time() - (int) self::$context['started']; - $mins = (int) ($elapsed / 60); - $seconds = $elapsed - $mins * 60; + $duration = (new \DateTime('@' . self::$context['started']))->diff(new \DateTime()); - return Lang::getTxt('maintenance_time_elasped_ms', ['m' => $mins, 's' => $seconds]); + if ((int) $duration->format('%a') > 0) { + return \strval((int) $duration->format('%h') + ((int) $duration->format('%a') * 24)) . $duration->format(':%I:%S'); + } + + if ((int) $duration->format('%h') > 0) { + return $duration->format('%h:%I:%S'); + } + + return $duration->format('%i:%S'); } /** diff --git a/Sources/Maintenance/Migration/MigrationBase.php b/Sources/Maintenance/Migration/MigrationBase.php index 22d668627de..9612bb56ac7 100644 --- a/Sources/Maintenance/Migration/MigrationBase.php +++ b/Sources/Maintenance/Migration/MigrationBase.php @@ -64,7 +64,8 @@ public function execute(): bool /** * Wrapper for the tool to handle timeout protection. * - * If a timeout needs to occur, it is handled, ensure that prior to this call, all variables are updated.. + * @param ?int $start If set, the current start value will be set to this + * value before the timeout check itself occurs. */ protected function handleTimeout(?int $start = null): void { @@ -72,7 +73,16 @@ protected function handleTimeout(?int $start = null): void Maintenance::setCurrentStart($start); } - Maintenance::$tool->checkAndHandleTimeout(); + Maintenance::$tool->checkAndHandleTimeout([ + 'name' => $this->name, + 'completed' => false, + 'substep' => Maintenance::getCurrentSubStep(), + 'start' => Maintenance::getCurrentStart(), + 'total' => Maintenance::$total_substeps, + 'debug' => [ + 'call' => $this::class, + ], + ]); } /** diff --git a/Sources/Maintenance/Migration/v2_1/AgreementUpdate.php b/Sources/Maintenance/Migration/v2_1/AgreementUpdate.php index adf662aaacc..eaae86caec4 100644 --- a/Sources/Maintenance/Migration/v2_1/AgreementUpdate.php +++ b/Sources/Maintenance/Migration/v2_1/AgreementUpdate.php @@ -110,7 +110,7 @@ public function execute(): bool $this->handleTimeout($start); $extras = []; - $request = Db::$db->query( + $request = $this->query( 'SELECT id_action, extra FROM {db_prefix}log_actions WHERE id_member = {int:blank_id} @@ -145,7 +145,7 @@ public function execute(): bool } if (!empty($extra['applicator'])) { - $request = Db::$db->query( + $request = $this->query( 'UPDATE {db_prefix}log_actions SET id_member = {int:id_member} WHERE id_action = {int:id_action}', diff --git a/Sources/Maintenance/Migration/v2_1/BoardDescriptions.php b/Sources/Maintenance/Migration/v2_1/BoardDescriptions.php index 0d4e7f52ead..4d40134110c 100644 --- a/Sources/Maintenance/Migration/v2_1/BoardDescriptions.php +++ b/Sources/Maintenance/Migration/v2_1/BoardDescriptions.php @@ -68,7 +68,7 @@ public function execute(): bool $this->query( 'UPDATE {db_prefix}boards SET name = {string:name}, description = {string:description} - WHERE id = {int:id}', + WHERE id_board = {int:id}', [ 'id' => $row['id_board'], 'name' => Utils::htmlspecialchars(strip_tags(Parser::transform($row['name'], Parser::OUTPUT_BBC))), diff --git a/Sources/Maintenance/Migration/v2_1/BoardPermissionsView.php b/Sources/Maintenance/Migration/v2_1/BoardPermissionsView.php index b77b509c141..04bec7f32bc 100644 --- a/Sources/Maintenance/Migration/v2_1/BoardPermissionsView.php +++ b/Sources/Maintenance/Migration/v2_1/BoardPermissionsView.php @@ -15,7 +15,6 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Config; use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; use SMF\Maintenance\Maintenance; @@ -46,11 +45,7 @@ public function execute(): bool // Create table board_permissions_view if ($start <= 0) { $table = new Schema\v2_1\BoardPermissionsView(); - $existing_tables = Db::$db->list_tables(); - - if (!\in_array(Config::$db_prefix . $table->name, $existing_tables)) { - $table->create(); - } + $table->create(); $this->handleTimeout(++$start); } diff --git a/Sources/Maintenance/Migration/v2_1/CreateAlerts.php b/Sources/Maintenance/Migration/v2_1/CreateAlerts.php index cfe950fc98c..5fab23bd87f 100644 --- a/Sources/Maintenance/Migration/v2_1/CreateAlerts.php +++ b/Sources/Maintenance/Migration/v2_1/CreateAlerts.php @@ -60,15 +60,8 @@ public function execute(): bool $user_alert_table = new Schema\v2_1\UserAlerts(); $user_alert_prefs_table = new Schema\v2_1\UserAlertsPrefs(); - $tables = Db::$db->list_tables(); - - if (!\in_array($user_alert_table->name, $tables)) { - $user_alert_table->create(); - } - - if (!\in_array($user_alert_prefs_table->name, $tables)) { - $user_alert_prefs_table->create(); - } + $user_alert_table->create(); + $user_alert_prefs_table->create(); $existing_structure = $members_table->getCurrentStructure(); @@ -150,25 +143,10 @@ public function execute(): bool } while (Maintenance::getCurrentStart() < Maintenance::$total_items); } - if (\in_array('notify_send_body', $member_columns)) { - Db::$db->remove_column('{db_prefix}members', 'notify_send_body'); - $this->handleTimeout(); - } - - if (\in_array('notify_types', $member_columns)) { - Db::$db->remove_column('{db_prefix}members', 'notify_types'); - $this->handleTimeout(); - } - - if (\in_array('notify_regularity', $member_columns)) { - Db::$db->remove_column('{db_prefix}members', 'notify_regularity'); - $this->handleTimeout(); - } - - if (\in_array('notify_announcements', $member_columns)) { - Db::$db->remove_column('{db_prefix}members', 'notify_announcements'); - $this->handleTimeout(); - } + $members_table->dropColumn('notify_send_body'); + $members_table->dropColumn('notify_types'); + $members_table->dropColumn('notify_regularity'); + $members_table->dropColumn('notify_announcements'); return true; } diff --git a/Sources/Maintenance/Migration/v2_1/CreateBackgroundTasks.php b/Sources/Maintenance/Migration/v2_1/CreateBackgroundTasks.php index 6f4d5c0dde7..f0bdc1b2051 100644 --- a/Sources/Maintenance/Migration/v2_1/CreateBackgroundTasks.php +++ b/Sources/Maintenance/Migration/v2_1/CreateBackgroundTasks.php @@ -15,8 +15,6 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Config; -use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; use SMF\Maintenance\Migration\MigrationBase; @@ -41,12 +39,7 @@ class CreateBackgroundTasks extends MigrationBase public function execute(): bool { $background_tasks_table = new Schema\v2_1\BackgroundTasks(); - - $tables = Db::$db->list_tables(); - - if (!\in_array(Config::$db_prefix . $background_tasks_table->name, $tables)) { - $background_tasks_table->create(); - } + $background_tasks_table->create(); return true; } diff --git a/Sources/Maintenance/Migration/v2_1/CreateMemberLogins.php b/Sources/Maintenance/Migration/v2_1/CreateMemberLogins.php index 10a6ccae776..26a91fb77d0 100644 --- a/Sources/Maintenance/Migration/v2_1/CreateMemberLogins.php +++ b/Sources/Maintenance/Migration/v2_1/CreateMemberLogins.php @@ -15,8 +15,6 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Config; -use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; use SMF\Maintenance\Migration\MigrationBase; @@ -40,12 +38,8 @@ class CreateMemberLogins extends MigrationBase */ public function execute(): bool { - $tables = Db::$db->list_tables(); - - if (!\in_array(Config::$db_prefix . 'member_logins', $tables)) { - $member_logins = new Schema\v2_1\MemberLogins(); - $member_logins->create(); - } + $member_logins = new Schema\v2_1\MemberLogins(); + $member_logins->create(); return true; } diff --git a/Sources/Maintenance/Migration/v2_1/FixDates.php b/Sources/Maintenance/Migration/v2_1/FixDates.php index 81e46379c62..3f9b22e7f77 100644 --- a/Sources/Maintenance/Migration/v2_1/FixDates.php +++ b/Sources/Maintenance/Migration/v2_1/FixDates.php @@ -19,6 +19,12 @@ use SMF\Maintenance\Maintenance; use SMF\Maintenance\Migration\MigrationBase; +/** + * @todo Find a SQL standard way of handling this. + * Maybe DATEADD with a calc on YEAR() to find what it takes to make it 1004? + * PostgreSQL does not have DATEFROMPARTS, but does have make_date (9.4>), + * which would be similar the more standard DATEFROMPARTS. + */ class FixDates extends MigrationBase { /******************* @@ -39,121 +45,61 @@ class FixDates extends MigrationBase */ public function execute(): bool { - // @@ TODO: Find a SQL standard way of handling this. Maybe DATEADD with a calc on YEAR() to find what it takes to make it 1004? - // PostgreSQL does not have DATEFROMPARTS, but does have make_date (9.4>), which would be similar the more standard DATEFROMPARTS. - - // PostgreSQL does the query a bit different. - $is_pgsql = Db::$db->title === POSTGRE_TITLE; - - if (Maintenance::getCurrentStart() < 1 && $is_pgsql) { - $this->query( - 'UPDATE {db_prefix}calendar - SET start_date = concat_ws({literal:-}, CASE WHEN EXTRACT(YEAR FROM start_date) < 1004 THEN 1004 END, EXTRACT(MONTH FROM start_date), EXTRACT(DAY FROM start_date))::date - WHERE EXTRACT(YEAR FROM start_date) < 1004', - [], - ); - } elseif (Maintenance::getCurrentStart() < 1) { - $this->query( - 'UPDATE {db_prefix}calendar - SET start_date = DATE(CONCAT(1004, {literal:-}, MONTH(start_date), {literal:-}, DAY(start_date))) - WHERE YEAR(start_date) < 1004', - [], - ); + if (Db::$db->title === POSTGRE_TITLE) { + $boilerplate = 'UPDATE {db_prefix}%1$s + SET %2$s = concat_ws({literal:-}, CASE WHEN EXTRACT(YEAR FROM %2$s) < 1004 THEN 1004 END, EXTRACT(MONTH FROM %2$s), EXTRACT(DAY FROM %2$s))::date + WHERE EXTRACT(YEAR FROM %2$s) < 1004'; + + $bday_query = 'UPDATE {db_prefix}members + SET birthdate = concat_ws({literal:-}, CASE WHEN EXTRACT(YEAR FROM birthdate) < 1004 THEN 1004 END, CASE WHEN EXTRACT(MONTH FROM birthdate) < 1 THEN 1 ELSE EXTRACT(MONTH FROM birthdate) END, CASE WHEN EXTRACT(DAY FROM birthdate) < 1 THEN 1 ELSE EXTRACT(DAY FROM birthdate) END)::date + WHERE EXTRACT(YEAR FROM birthdate) < 1004 OR EXTRACT(MONTH FROM birthdate) < 1 OR EXTRACT(DAY FROM birthdate) < 1'; + + } else { + $boilerplate = 'UPDATE {db_prefix}%1$s + SET %2$s = DATE(CONCAT(1004, {literal:-}, MONTH(%2$s), {literal:-}, DAY(%2$s))) + WHERE YEAR(%2$s) < 1004'; + + $bday_query = 'UPDATE {db_prefix}members + SET birthdate = DATE(CONCAT(IF(YEAR(birthdate) < 1004, 1004, YEAR(birthdate)), {literal:-}, IF(MONTH(birthdate) < 1, 1, MONTH(birthdate)), {literal:-}, IF(DAY(birthdate) < 1, 1, DAY(birthdate)))) + WHERE YEAR(birthdate) < 1004 OR MONTH(birthdate) < 1 OR DAY(birthdate) < 1'; } - Maintenance::setCurrentStart(); - $this->handleTimeout(); - - if (Maintenance::getCurrentStart() < 2 && $is_pgsql) { - $this->query( - 'UPDATE {db_prefix}calendar - SET end_date = concat_ws({literal:-}, CASE WHEN EXTRACT(YEAR FROM end_date) < 1004 THEN 1004 END, EXTRACT(MONTH FROM end_date), EXTRACT(DAY FROM end_date))::date - WHERE EXTRACT(YEAR FROM end_date) < 1004', - [], - ); - } elseif (Maintenance::getCurrentStart() < 2) { - $this->query( - 'UPDATE {db_prefix}calendar - SET end_date = DATE(CONCAT(1004, {literal:-}, MONTH(end_date), {literal:-}, DAY(end_date))) - WHERE YEAR(end_date) < 1004', - [], - ); + + if (Maintenance::getCurrentStart() < 1) { + $this->query(\sprintf($boilerplate, 'calendar', 'start_date')); + + Maintenance::setCurrentStart(); + $this->handleTimeout(); } - Maintenance::setCurrentStart(); - $this->handleTimeout(); - - if (Maintenance::getCurrentStart() < 3 && $is_pgsql) { - $this->query( - 'UPDATE {db_prefix}calendar_holidays - SET event_date = concat_ws({literal:-}, CASE WHEN EXTRACT(YEAR FROM event_date) < 1004 THEN 1004 END, EXTRACT(MONTH FROM event_date), EXTRACT(DAY FROM event_date))::date - WHERE EXTRACT(YEAR FROM event_date) < 1004', - [], - ); - } elseif (Maintenance::getCurrentStart() < 3) { - $this->query( - 'UPDATE {db_prefix}calendar_holidays - SET event_date = DATE(CONCAT(1004, {literal:-}, MONTH(event_date), {literal:-}, DAY(event_date))) - WHERE YEAR(event_date) < 1004', - [], - ); + + if (Maintenance::getCurrentStart() < 2) { + $this->query(\sprintf($boilerplate, 'calendar', 'end_date')); + + Maintenance::setCurrentStart(); + $this->handleTimeout(); } - Maintenance::setCurrentStart(); - $this->handleTimeout(); - - if (Maintenance::getCurrentStart() < 4 && $is_pgsql) { - $this->query( - 'UPDATE {db_prefix}log_spider_stats - SET stat_date = concat_ws({literal:-}, CASE WHEN EXTRACT(YEAR FROM stat_date) < 1004 THEN 1004 END, EXTRACT(MONTH FROM stat_date), EXTRACT(DAY FROM stat_date))::date - WHERE EXTRACT(YEAR FROM stat_date) < 1004', - [], - ); - } elseif (Maintenance::getCurrentStart() < 4) { - $this->query( - 'UPDATE {db_prefix}log_spider_stats - SET stat_date = DATE(CONCAT(1004, {literal:-}, MONTH(stat_date), {literal:-}, DAY(stat_date))) - WHERE YEAR(stat_date) < 1004', - [], - ); + + if (Maintenance::getCurrentStart() < 3) { + $this->query(\sprintf($boilerplate, 'calendar_holidays', 'event_date')); + + Maintenance::setCurrentStart(); + $this->handleTimeout(); } - Maintenance::setCurrentStart(); - $this->handleTimeout(); - if (Maintenance::getCurrentStart() < 5 && $is_pgsql) { - $this->query( - 'UPDATE {db_prefix}log_spider_stats - SET birthdate = concat_ws({literal:-}, CASE WHEN EXTRACT(YEAR FROM birthdate) < 1004 THEN 1004 END, CASE WHEN EXTRACT(MONTH FROM birthdate) < 1 THEN 1 ELSE EXTRACT(MONTH FROM birthdate) END, CASE WHEN EXTRACT(DAY FROM birthdate) < 1 THEN 1 ELSE EXTRACT(DAY FROM birthdate) END)::date - WHERE EXTRACT(YEAR FROM birthdate) < 1004 OR EXTRACT(MONTH FROM birthdate) < 1 OR EXTRACT(DAY FROM birthdate) < 1', - [], - ); - } elseif (Maintenance::getCurrentStart() < 5) { - $this->query( - 'UPDATE {db_prefix}members - SET birthdate = DATE(CONCAT(IF(YEAR(birthdate) < 1004, 1004, YEAR(birthdate)), {literal:-}, IF(MONTH(birthdate) < 1, 1, MONTH(birthdate)), {literal:-}, IF(DAY(birthdate) < 1, 1, DAY(birthdate)))) - WHERE YEAR(birthdate) < 1004 OR MONTH(birthdate) < 1 OR DAY(birthdate) < 1', - [], - ); + if (Maintenance::getCurrentStart() < 4) { + $this->query(\sprintf($boilerplate, 'log_spider_stats', 'stat_date')); + + Maintenance::setCurrentStart(); + $this->handleTimeout(); } - Maintenance::setCurrentStart(); - $this->handleTimeout(); - if (Maintenance::getCurrentStart() < 6 && $is_pgsql) { - $this->query( - 'UPDATE {db_prefix}members - SET birthdate = concat_ws({literal:-}, CASE WHEN EXTRACT(YEAR FROM birthdate) < 1004 THEN 1004 END, CASE WHEN EXTRACT(MONTH FROM birthdate) < 1 THEN 1 ELSE EXTRACT(MONTH FROM birthdate) END, CASE WHEN EXTRACT(DAY FROM birthdate) < 1 THEN 1 ELSE EXTRACT(DAY FROM birthdate) END)::date - WHERE EXTRACT(YEAR FROM birthdate) < 1004 OR EXTRACT(MONTH FROM birthdate) < 1 OR EXTRACT(DAY FROM birthdate) < 1', - [], - ); - } elseif (Maintenance::getCurrentStart() < 6) { - $this->query( - 'UPDATE {db_prefix}members - SET birthdate = DATE(CONCAT(IF(YEAR(birthdate) < 1004, 1004, YEAR(birthdate)), {literal:-}, IF(MONTH(birthdate) < 1, 1, MONTH(birthdate)), {literal:-}, IF(DAY(birthdate) < 1, 1, DAY(birthdate)))) - WHERE YEAR(birthdate) < 1004 OR MONTH(birthdate) < 1 OR DAY(birthdate) < 1', - [], - ); + if (Maintenance::getCurrentStart() < 5) { + $this->query($bday_query); + + Maintenance::setCurrentStart(); + $this->handleTimeout(); } - Maintenance::setCurrentStart(); - $this->handleTimeout(); - if (Maintenance::getCurrentStart() < 7) { + if (Maintenance::getCurrentStart() < 6) { Db::$db->change_column( '{db_prefix}log_activity', 'DATE', @@ -162,22 +108,63 @@ public function execute(): bool 'default' => null, ], ); + + Maintenance::setCurrentStart(); + $this->handleTimeout(); + } + + if (Maintenance::getCurrentStart() < 7) { + Db::$db->change_column( + '{db_prefix}calendar', + 'start_date', + ['default' => '1004-01-01'], + ); + + Maintenance::setCurrentStart(); + $this->handleTimeout(); + } + + if (Maintenance::getCurrentStart() < 8) { + Db::$db->change_column( + '{db_prefix}calendar', + 'end_date', + ['default' => '1004-01-01'], + ); + + Maintenance::setCurrentStart(); + $this->handleTimeout(); + } + + if (Maintenance::getCurrentStart() < 9) { + Db::$db->change_column( + '{db_prefix}calendar_holidays', + 'event_date', + ['default' => '1004-01-01'], + ); + + Maintenance::setCurrentStart(); + $this->handleTimeout(); } - Maintenance::setCurrentStart(); - $this->handleTimeout(); - $fixes = [ - ['tbl' => '{db_prefix}calendar', 'col' => 'start_date'], - ['tbl' => '{db_prefix}calendar', 'col' => 'end_date'], - ['tbl' => '{db_prefix}calendar_holidays', 'col' => 'event_date'], - ['tbl' => '{db_prefix}log_spider_stats', 'col' => 'stat_date'], - ['tbl' => '{db_prefix}members', 'col' => 'birthdate'], - ]; + if (Maintenance::getCurrentStart() < 10) { + Db::$db->change_column( + '{db_prefix}log_spider_stats', + 'stat_date', + ['default' => '1004-01-01'], + ); + + Maintenance::setCurrentStart(); + $this->handleTimeout(); + } - for ($key = Maintenance::getCurrentStart(); $key < \count($fixes); Maintenance::setCurrentStart()) { - $fix = $fixes[$key - 7]; + if (Maintenance::getCurrentStart() < 11) { + Db::$db->change_column( + '{db_prefix}members', + 'stat_date', + ['birthdate' => '1004-01-01'], + ); - Db::$db->change_column($fix['tbl'], $fix['col'], ['default' => '1004-01-01']); + Maintenance::setCurrentStart(); $this->handleTimeout(); } diff --git a/Sources/Maintenance/Migration/v2_1/Ipv6BanItem.php b/Sources/Maintenance/Migration/v2_1/Ipv6BanItem.php index 20edf01d352..f752f035d44 100644 --- a/Sources/Maintenance/Migration/v2_1/Ipv6BanItem.php +++ b/Sources/Maintenance/Migration/v2_1/Ipv6BanItem.php @@ -22,6 +22,8 @@ class Ipv6BanItem extends MigrationBase { + use IPv6Converter; + /******************* * Public properties *******************/ @@ -29,7 +31,7 @@ class Ipv6BanItem extends MigrationBase /** * */ - public string $name = 'Update ban ip with ipv6 support'; + public string $name = 'Updating ban_items table with IPv6 support'; /**************** * Public methods @@ -43,7 +45,16 @@ public function isCandidate(): bool $table = new Schema\v2_1\BanItems(); $existing_structure = $table->getCurrentStructure(); - return !isset($existing_structure['columns']['ip_low']) || !isset($existing_structure['columns']['ip_high']); + return ( + isset($existing_structure['columns']['ip_low1']) + || isset($existing_structure['columns']['ip_low2']) + || isset($existing_structure['columns']['ip_low3']) + || isset($existing_structure['columns']['ip_low4']) + || isset($existing_structure['columns']['ip_high1']) + || isset($existing_structure['columns']['ip_high2']) + || isset($existing_structure['columns']['ip_high3']) + || isset($existing_structure['columns']['ip_high4']) + ); } /** @@ -58,17 +69,12 @@ public function execute(): bool // Add columns to ban_items if ($start <= 0) { - foreach ($table->columns as $column) { - if ( - ( - $column->name === 'ip_low' - || $column->name === 'ip_high' - ) - && !isset($existing_structure['columns'][$column->name]) - ) { - $table->addColumn($column); - continue; - } + if (!isset($existing_structure['columns']['ip_low'])) { + $table->addColumn($table->columns['ip_low']); + } + + if (!isset($existing_structure['columns']['ip_high'])) { + $table->addColumn($table->columns['ip_high']); } $this->handleTimeout(++$start); @@ -80,48 +86,19 @@ public function execute(): bool if (Db::$db->title == POSTGRE_TITLE) { $this->query( 'UPDATE {db_prefix}ban_items - SET ip_low = (ip_low1||{literal:.}||ip_low2||{literal:.}||ip_low3||{literal:.}||ip_low4)::inet, + SET + ip_low = (ip_low1||{literal:.}||ip_low2||{literal:.}||ip_low3||{literal:.}||ip_low4)::inet, ip_high = (ip_high1||{literal:.}||ip_high2||{literal:.}||ip_high3||{literal:.}||ip_high4)::inet WHERE ip_low1 > 0', ); } else { - // Note, We now support MySQL 8+, which means we could use INET6_ATON. - // The upgrade logic was built this way and should remain the same. - // If changed, a full upgrade from 2.0 to 3.0 would need to be tested. - $this->quote( - 'UPDATE IGNORE {db_prefix}ban_items - SET ip_low = - UNHEX( - hex( - INET_ATON(concat(ip_low1,{literal:.},ip_low2,{literal:.},ip_low3,{literal:.},ip_low4)) - ) - ), - ip_high = - UNHEX( - hex( - INET_ATON(concat(ip_high1,{literal:.},ip_high2,{literal:.},ip_high3,{literal:.},ip_high4)) - ) - ) - WHERE ip_low1 > 0', - ); - $this->query( 'UPDATE IGNORE {db_prefix}ban_items - SET ip_low = - UNHEX( - hex( - INET_ATON(concat(ip_low1,{literal:.},ip_low2,{literal:.},ip_low3,{literal:.},ip_low4)) - ) - ), - ip_high = - UNHEX( - hex( - INET_ATON(concat(ip_high1,{literal:.},ip_high2,{literal:.},ip_high3,{literal:.},ip_high4)) - ) - ) + SET + ip_low = UNHEX(HEX(INET_ATON(CONCAT_WS({literal:.}, ip_low1, ip_low2, ip_low3, ip_low4)))), + ip_high = UNHEX(HEX(INET_ATON(CONCAT_WS({literal:.}, ip_high1, ip_high2, ip_high3, ip_high4)))) WHERE ip_low1 > 0', ); - } $this->handleTimeout(++$start); @@ -129,14 +106,8 @@ public function execute(): bool // Create new index on ban_items. if ($start <= 2) { - foreach ($table->indexes as $idx) { - if ( - $idx->name === 'idx_id_ban_ip' - && !isset($existing_structure['indexes'][$column->name]) - ) { - $table->addIndex($idx); - continue; - } + if (!isset($existing_structure['indexes']['idx_id_ban_ip'])) { + $table->addIndex($table->indexes['idx_id_ban_ip']); } $this->handleTimeout(++$start); @@ -144,16 +115,9 @@ public function execute(): bool // Dropping columns from ban_items if ($start <= 3) { - foreach ($table->columns as $column) { - if ( - ( - $column->name === 'ip_low1' || $column->name === 'ip_low2' || $column->name === 'ip_low3' || $column->name === 'ip_low4' - || $column->name === 'ip_high1' || $column->name === 'ip_high2' || $column->name === 'ip_high3' || $column->name === 'ip_high4' - ) - && !isset($existing_structure['columns'][$column->name]) - ) { - $table->dropColumn($column); - continue; + foreach (['ip_low1', 'ip_low2', 'ip_low3', 'ip_low4', 'ip_high1', 'ip_high2', 'ip_high3', 'ip_high4'] as $col_name) { + if (isset($existing_structure['columns'][$col_name])) { + $table->dropColumn($col_name); } } diff --git a/Sources/Maintenance/Migration/v2_1/Ipv6Base.php b/Sources/Maintenance/Migration/v2_1/Ipv6Base.php deleted file mode 100644 index 68ff0e508d2..00000000000 --- a/Sources/Maintenance/Migration/v2_1/Ipv6Base.php +++ /dev/null @@ -1,343 +0,0 @@ -query( - ' - SELECT COUNT(DISTINCT {raw:col}) - FROM {db_prefix}{raw:table}', - [ - 'col' => $col . '_old', - 'table' => $table, - ], - ); - - // failed? We may have not renamed yet. - if ($request === false) { - $request = $this->query( - ' - SELECT COUNT(DISTINCT {raw:col}) - FROM {db_prefix}{raw:table}', - [ - 'col' => $col, - 'table' => $table, - ], - ); - } - - if ($request === false) { - return 0; - } - - list($items) = Db::$db->fetch_row($request); - - return (int) $items; - } - - public function convertData(string $targetTable, string $oldCol, string $newCol, int $limit = 50000, int $setSize = 100): bool - { - // mysql default max length is 1mb https://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html - $arIp = []; - - $request = $this->query( - ' - SELECT DISTINCT {raw:old_col} - FROM {db_prefix}{raw:table_name} - WHERE {raw:new_col} = {string:empty} - LIMIT {int:limit}', - [ - 'old_col' => $oldCol, - 'new_col' => $newCol, - 'table_name' => $targetTable, - 'empty' => '', - 'limit' => $limit, - ], - ); - - while ($row = Db::$db->fetch_assoc($request)) { - $arIp[] = $row[$oldCol]; - } - - Db::$db->free_result($request); - - if (empty($arIp)) { - return true; - } - - $updates = []; - $new_ips = []; - $cases = []; - $count = \count($arIp); - - for ($i = 0; $i < $count; $i++) { - $new_ip = trim($arIp[$i]); - - $new_ip = filter_var($new_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6); - - if ($new_ip === false) { - $new_ip = ''; - } - - $updates['ip' . $i] = $arIp[$i]; - $new_ips['newip' . $i] = $new_ip; - $cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:newip' . $i . '}'; - - // Execute updates every $setSize & also when done with contents of $arIp - if ((($i + 1) == $count) || (($i + 1) % $setSize === 0)) { - $updates['whereSet'] = array_values($updates); - Db::$db->query( - 'UPDATE {db_prefix}' . $targetTable . ' - SET ' . $newCol . ' = CASE ' . - implode(' - ', $cases) . ' - ELSE NULL - END - WHERE ' . $oldCol . ' IN ({array_string:whereSet})', - array_merge($updates, $new_ips), - ); - - $updates = []; - $new_ips = []; - $cases = []; - } - } - - return false; - } - - public function migrateData(Table $table, string $col): bool - { - $start = Maintenance::getCurrentStart(); - - // Get our total items. - Maintenance::$total_items = $this->getTotalItems('members', 'member_ip2'); - - $existing_structure = $table->getCurrentStructure(); - - // PostgreSQL we use a migration function. - if (Db::$db->title === POSTGRE_TITLE) { - $this->query( - 'ALTER TABLE {db_prefix}{raw:table} - ALTER {raw:col} DROP not null, - ALTER {raw:col} DROP default, - ALTER {raw:col} TYPE inet USING migrate_inet({raw:col})', - [ - 'table' => $table->name, - 'col' => $col, - ], - ); - - return true; - } - - // Add columns to ban_items - if ($start >= 0) { - // Does the old IP exist? - foreach ($table->columns as $column) { - if ( - $column->name === $col - && !isset($existing_structure['columns'][$col . '_old']) - ) { - $this->query( - 'ALTER TABLE {db_prefix}{raw:table} - CHANGE {raw:col} {raw:col}_old varchar(200)', - [ - 'table' => $table->name, - 'col' => $col, - ], - ); - } - } - - $this->handleTimeout(++$start); - } - - if ($start >= 1 || !isset($existing_structure['columns'][$col])) { - if (isset($existing_structure['columns'][$col . '_old']) && !isset($existing_structure['columns'][$col])) { - $table->addColumn($table->columns[$col]); - } - - $this->handleTimeout(++$start); - } - - // Make sure our temp index exists. - if ($start >= 2) { - if (!isset($existing_structure['indexes']['temp_old_' . $col])) { - $this->query( - 'CREATE INDEX {db_prefix}temp_old_{raw:col} ON {db_prefix}{raw:table} ({raw:col}_old)', - [ - 'table' => $table->name, - 'col' => $col, - ], - ); - } - - $this->handleTimeout(++$start); - } - - // Initialize new ip column. - if ($start >= 3) { - $this->query( - 'UPDATE {db_prefix}{raw:table} - SET {raw:col} = {empty}', - [ - 'table' => $table->name, - 'col' => $col, - ], - ); - - $this->handleTimeout(++$start); - } - - if ($start >= 4) { - $is_done = false; - - while (!$is_done) { - $this->handleTimeout(); - $is_done = $this->convertData($table->name, $col . '_old', $col); - } - - $this->handleTimeout(++$start); - } - - // Remove the temporary ip indexes. - if ($start >= 5) { - if (isset($existing_structure['indexes']['temp_old_' . $col])) { - $this->query( - 'DROP INDEX {db_prefix}temp_old_{raw:col} ON {db_prefix}{raw:table}', - [ - 'table' => $table->name, - 'col' => $col, - ], - ); - } - - $this->handleTimeout(++$start); - } - - // Remove the old member columns. - if ($start >= 6) { - if (isset($existing_structure['columns'][$col . '_old'])) { - $this->query( - 'ALTER TABLE {db_prefix}{raw:table} - DROP COLUMN {raw:col}_old', - [ - 'table' => $table->name, - 'col' => $col, - ], - ); - } - - $this->handleTimeout(++$start); - } - - return true; - } - - public function truncateAndConvert(Table $table, string|array $columns, bool $force = false): bool - { - $start = Maintenance::getCurrentStart(); - - // PostgreSQL we use a migration function. - if (Db::$db->title !== POSTGRE_TITLE && !$force) { - return $this->postgreSQLmigrate($table, $columns); - } - - if ($start <= 0) { - $this->query( - 'TRUNCATE TABLE {db_prefix}{raw:table}', - [ - 'table' => $table->name, - ], - ); - - $this->handleTimeout(++$start); - } - - if ($start <= 1) { - // Modify ip size - foreach ($table->columns as $col) { - if (\in_array($col->name, (array) $columns)) { - $table->alterColumn($col); - } - } - - $this->handleTimeout(++$start); - } - - return true; - } - - public function convertWithNoDataPreservation(Table $table, string|array $columns, bool $force = false): bool - { - $start = Maintenance::getCurrentStart(); - - // PostgreSQL we use a migration function. - if (Db::$db->title !== POSTGRE_TITLE && !$force) { - return $this->postgreSQLmigrate($table, $columns); - } - - $existing_structure = $table->getCurrentStructure(); - - foreach ($columns as $column) { - foreach ($table->columns as $col) { - if ($col->name == $column && $existing_structure['columns'][$col->name]['type'] !== (Db::$db->title === POSTGRE_TITLE ? 'inet' : 'varbinary')) { - $table->dropColumn($col); - $table->addColumn($col); - - $this->handleTimeout(++$start); - } - } - } - - return true; - } - - /****************** - * Internal methods - ******************/ - - private function postgreSQLmigrate(Table $table, string|array $columns) - { - foreach ($columns as $column) { - $this->query( - 'ALTER TABLE {db_prefix}{raw:table} - ALTER {raw:col} DROP not null, - ALTER {raw:col} DROP default, - ALTER {raw:col} TYPE inet USING migrate_inet({raw:col})', - [ - 'table' => $table->name, - 'col' => $column, - ], - ); - } - - return true; - } -} diff --git a/Sources/Maintenance/Migration/v2_1/Ipv6Converter.php b/Sources/Maintenance/Migration/v2_1/Ipv6Converter.php new file mode 100644 index 00000000000..7b684992492 --- /dev/null +++ b/Sources/Maintenance/Migration/v2_1/Ipv6Converter.php @@ -0,0 +1,135 @@ +title === POSTGRE_TITLE) { + $this->query( + 'ALTER TABLE {db_prefix}{raw:table} + ALTER {raw:column} DROP not null, + ALTER {raw:column} DROP default, + ALTER {raw:column} TYPE inet USING migrate_inet({raw:column})', + [ + 'table' => $table->name, + 'column' => $column->name, + ], + ); + } else { + $table->addColumn(new Column( + name: 'temp', + type: 'inet', + size: 16, + )); + + $this->query( + 'UPDATE {db_prefix}{raw:table} + SET + {raw:temp} = CASE + WHEN TRIM({raw:column}) = {empty} THEN NULL + ELSE INET6_ATON({raw:column}) + END', + [ + 'table' => $table->name, + 'column' => $column->name, + 'temp' => 'temp', + ], + ); + + $table->alterColumn($column); + + $this->query( + 'UPDATE {db_prefix}{raw:table} + SET {raw:column} = {raw:temp}', + [ + 'table' => $table->name, + 'column' => $column->name, + 'temp' => 'temp', + ], + ); + + $table->dropColumn('temp'); + } + } + + /** + * Converts integer columns that stored IP addresses. + * + * @param Table $table The table containing the column to convert. + * @param Column $column The column to convert. + */ + protected function convertIntegerColumnToInet(Table $table, Column $column): void + { + if (Db::$db->title === POSTGRE_TITLE) { + $this->query( + 'ALTER TABLE {db_prefix}{raw:table} + ALTER {raw:column} DROP not null, + ALTER {raw:column} DROP default, + ALTER {raw:column} TYPE inet USING migrate_inet({raw:column})', + [ + 'table' => $table->name, + 'column' => $column->name, + ], + ); + } else { + $table->addColumn(new Column( + name: 'temp', + type: 'inet', + size: 16, + )); + + $this->query( + 'UPDATE {db_prefix}{raw:table} + SET {raw:temp} = UNHEX(HEX({raw:column}))', + [ + 'table' => $table->name, + 'column' => $column->name, + 'temp' => 'temp', + ], + ); + + $table->alterColumn($column); + + $this->query( + 'UPDATE {db_prefix}{raw:table} + SET {raw:column} = {raw:temp}', + [ + 'table' => $table->name, + 'column' => $column->name, + 'temp' => 'temp', + ], + ); + + $table->dropColumn('temp'); + } + } +} diff --git a/Sources/Maintenance/Migration/v2_1/Ipv6LogAction.php b/Sources/Maintenance/Migration/v2_1/Ipv6LogAction.php index 698cc90aaf0..2985f6ca58e 100644 --- a/Sources/Maintenance/Migration/v2_1/Ipv6LogAction.php +++ b/Sources/Maintenance/Migration/v2_1/Ipv6LogAction.php @@ -15,11 +15,13 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Db\DatabaseApi as Db; +use SMF\Db\Schema; use SMF\Maintenance\Migration\MigrationBase; class Ipv6LogAction extends MigrationBase { + use IPv6Converter; + /******************* * Public properties *******************/ @@ -27,35 +29,21 @@ class Ipv6LogAction extends MigrationBase /** * */ - public string $name = 'Update log_action ip with ipv6 support'; + public string $name = 'Updating log_action table with IPv6 support'; /**************** * Public methods ****************/ - /** - * - */ - public function __construct() - { - if (Db::$db->title !== POSTGRE_TITLE) { - $this->name .= ' without converting'; - } - } - /** * */ public function isCandidate(): bool { - $table = new \SMF\Db\Schema\v2_1\LogActions(); + $table = new Schema\v2_1\LogActions(); $existing_structure = $table->getCurrentStructure(); - if (Db::$db->title === POSTGRE_TITLE) { - return $existing_structure['columns']['ip']['type'] !== 'inet'; - } - - return $existing_structure['columns']['ip']['type'] !== 'varbinary'; + return $existing_structure['columns']['ip']['type'] !== 'inet'; } /** @@ -63,25 +51,11 @@ public function isCandidate(): bool */ public function execute(): bool { - $table = new \SMF\Db\Schema\v2_1\LogActions(); - $existing_structure = $table->getCurrentStructure(); + $table = new Schema\v2_1\LogActions(); + + $this->convertStringColumnToInet($table, $table->columns['ip']); - if (Db::$db->title === POSTGRE_TITLE) { - $this->query( - 'ALTER TABLE {db_prefix}log_actions - ALTER ip DROP not null, - ALTER ip DROP default, - ALTER ip TYPE inet USING migrate_inet(ip)', - ); - } else { - foreach ($table->columns as $column) { - if ($column->name === 'ip' && $existing_structure['columns'][$column->name]['type'] !== 'varbinary') { - $table->dropColumn($column); - $table->addColumn($column); - continue; - } - } - } + $this->handleTimeout(); return true; } diff --git a/Sources/Maintenance/Migration/v2_1/Ipv6LogBanned.php b/Sources/Maintenance/Migration/v2_1/Ipv6LogBanned.php index 529fe3ad221..a221957c493 100644 --- a/Sources/Maintenance/Migration/v2_1/Ipv6LogBanned.php +++ b/Sources/Maintenance/Migration/v2_1/Ipv6LogBanned.php @@ -15,11 +15,13 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Db\DatabaseApi as Db; +use SMF\Db\Schema; use SMF\Maintenance\Migration\MigrationBase; class Ipv6LogBanned extends MigrationBase { + use IPv6Converter; + /******************* * Public properties *******************/ @@ -27,35 +29,21 @@ class Ipv6LogBanned extends MigrationBase /** * */ - public string $name = 'Update log_banned ip with ipv6 support'; + public string $name = 'Updating log_banned table with IPv6 support'; /**************** * Public methods ****************/ - /** - * - */ - public function __construct() - { - if (Db::$db->title !== POSTGRE_TITLE) { - $this->name .= ' without converting'; - } - } - /** * */ public function isCandidate(): bool { - $table = new \SMF\Db\Schema\v2_1\LogBanned(); + $table = new Schema\v2_1\LogBanned(); $existing_structure = $table->getCurrentStructure(); - if (Db::$db->title === POSTGRE_TITLE) { - return $existing_structure['columns']['ip']['type'] !== 'inet'; - } - - return $existing_structure['columns']['ip']['type'] !== 'varbinary'; + return $existing_structure['columns']['ip']['type'] !== 'inet'; } /** @@ -63,25 +51,11 @@ public function isCandidate(): bool */ public function execute(): bool { - $table = new \SMF\Db\Schema\v2_1\LogBanned(); - $existing_structure = $table->getCurrentStructure(); + $table = new Schema\v2_1\LogBanned(); + + $this->convertStringColumnToInet($table, $table->columns['ip']); - if (Db::$db->title === POSTGRE_TITLE) { - $this->query( - 'ALTER TABLE {db_prefix}log_banned - ALTER ip DROP not null, - ALTER ip DROP default, - ALTER ip TYPE inet USING migrate_inet(ip)', - ); - } else { - foreach ($table->columns as $column) { - if ($column->name === 'ip' && $existing_structure['columns'][$column->name]['type'] !== 'varbinary') { - $table->dropColumn($column); - $table->addColumn($column); - continue; - } - } - } + $this->handleTimeout(); return true; } diff --git a/Sources/Maintenance/Migration/v2_1/Ipv6LogErrors.php b/Sources/Maintenance/Migration/v2_1/Ipv6LogErrors.php index e4ac499c3f9..737f090940e 100644 --- a/Sources/Maintenance/Migration/v2_1/Ipv6LogErrors.php +++ b/Sources/Maintenance/Migration/v2_1/Ipv6LogErrors.php @@ -15,11 +15,13 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Db\DatabaseApi as Db; +use SMF\Db\Schema; use SMF\Maintenance\Migration\MigrationBase; class Ipv6LogErrors extends MigrationBase { + use IPv6Converter; + /******************* * Public properties *******************/ @@ -27,35 +29,21 @@ class Ipv6LogErrors extends MigrationBase /** * */ - public string $name = 'Update log_errors ip with ipv6 support'; + public string $name = 'Updating log_errors table with IPv6 support'; /**************** * Public methods ****************/ - /** - * - */ - public function __construct() - { - if (Db::$db->title !== POSTGRE_TITLE) { - $this->name .= ' without converting'; - } - } - /** * */ public function isCandidate(): bool { - $table = new \SMF\Db\Schema\v2_1\LogErrors(); + $table = new Schema\v2_1\LogErrors(); $existing_structure = $table->getCurrentStructure(); - if (Db::$db->title === POSTGRE_TITLE) { - return $existing_structure['columns']['ip']['type'] !== 'inet'; - } - - return $existing_structure['columns']['ip']['type'] !== 'varbinary'; + return $existing_structure['columns']['ip']['type'] !== 'inet'; } /** @@ -63,35 +51,14 @@ public function isCandidate(): bool */ public function execute(): bool { - $table = new \SMF\Db\Schema\v2_1\LogErrors(); - $existing_structure = $table->getCurrentStructure(); + $table = new Schema\v2_1\LogErrors(); + + $this->convertStringColumnToInet($table, $table->columns['ip']); - if (Db::$db->title === POSTGRE_TITLE) { - $this->query( - 'ALTER TABLE {db_prefix}log_errors - ALTER ip DROP not null, - ALTER ip DROP default, - ALTER ip TYPE inet USING migrate_inet(ip)', - ); - } else { - foreach ($table->columns as $column) { - if ($column->name === 'ip' && $existing_structure['columns'][$column->name]['type'] !== 'varbinary') { - $table->dropColumn($column); - $table->addColumn($column); - continue; - } - } - } + // Fix indices. + $table->normalize(); - foreach ($table->indexes as $idx) { - if ( - $idx->name === 'idx_ip' - && !isset($existing_structure['indexes'][$column->name]) - ) { - $table->addIndex($idx); - continue; - } - } + $this->handleTimeout(); return true; } diff --git a/Sources/Maintenance/Migration/v2_1/Ipv6LogFloodControl.php b/Sources/Maintenance/Migration/v2_1/Ipv6LogFloodControl.php index a7fc15829d1..bd414ba2c86 100644 --- a/Sources/Maintenance/Migration/v2_1/Ipv6LogFloodControl.php +++ b/Sources/Maintenance/Migration/v2_1/Ipv6LogFloodControl.php @@ -15,12 +15,13 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; -use SMF\Maintenance\Maintenance; +use SMF\Maintenance\Migration\MigrationBase; -class Ipv6LogFloodControl extends Ipv6Base +class Ipv6LogFloodControl extends MigrationBase { + use IPv6Converter; + /******************* * Public properties *******************/ @@ -28,7 +29,7 @@ class Ipv6LogFloodControl extends Ipv6Base /** * */ - public string $name = 'Update log_floodcontrol ip with ipv6 support without converting'; + public string $name = 'Updating log_floodcontrol table with IPv6 support'; /**************** * Public methods @@ -42,11 +43,7 @@ public function isCandidate(): bool $table = new Schema\v2_1\LogFloodcontrol(); $existing_structure = $table->getCurrentStructure(); - if (Db::$db->title === POSTGRE_TITLE) { - return $existing_structure['columns']['ip']['type'] !== 'inet'; - } - - return $existing_structure['columns']['ip']['type'] !== 'varbinary'; + return $existing_structure['columns']['ip']['type'] !== 'inet'; } /** @@ -56,28 +53,13 @@ public function execute(): bool { $table = new Schema\v2_1\LogFloodcontrol(); - $start = Maintenance::getCurrentStart(); - - // Prep floodcontrol - if ($start <= 0) { - $this->query('TRUNCATE TABLE {db_prefix}log_floodcontrol'); - - $this->handleTimeout(++$start); - } - - if ($start <= 1) { - // Add the new floodcontrol ip column - $table->dropIndex($table->indexes['primary']); - - // Modify log_type size - $table->alterColumn($table->columns['ip']); - $table->alterColumn($table->columns['log_type']); + $this->query('TRUNCATE TABLE {db_prefix}log_floodcontrol'); - // Create primary key for floodcontrol - $table->addIndex($table->indexes['primary']); + $table->dropIndex($table->indexes['primary']); + $this->convertStringColumnToInet($table, $table->columns['ip']); + $table->normalize(); - $this->handleTimeout(++$start); - } + $this->handleTimeout(); return true; } diff --git a/Sources/Maintenance/Migration/v2_1/Ipv6LogOnline.php b/Sources/Maintenance/Migration/v2_1/Ipv6LogOnline.php index 491342cdd7e..c683524eec5 100644 --- a/Sources/Maintenance/Migration/v2_1/Ipv6LogOnline.php +++ b/Sources/Maintenance/Migration/v2_1/Ipv6LogOnline.php @@ -15,12 +15,13 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; -use SMF\Maintenance\Maintenance; +use SMF\Maintenance\Migration\MigrationBase; -class Ipv6LogOnline extends Ipv6Base +class Ipv6LogOnline extends MigrationBase { + use IPv6Converter; + /******************* * Public properties *******************/ @@ -42,11 +43,7 @@ public function isCandidate(): bool $table = new Schema\v2_1\LogOnline(); $existing_structure = $table->getCurrentStructure(); - if (Db::$db->title === POSTGRE_TITLE) { - return $existing_structure['columns']['ip']['type'] !== 'inet'; - } - - return $existing_structure['columns']['ip']['type'] !== 'varbinary'; + return $existing_structure['columns']['ip']['type'] !== 'inet'; } /** @@ -55,10 +52,14 @@ public function isCandidate(): bool public function execute(): bool { $table = new Schema\v2_1\LogOnline(); - $existing_structure = $table->getCurrentStructure(); - $start = Maintenance::getCurrentStart(); + $this->query('TRUNCATE TABLE {db_prefix}log_online'); + + $table->dropColumn($table->columns['ip']); + $table->addColumn($table->columns['ip']); + + $this->handleTimeout(); - return $this->truncateAndConvert($table, 'ip', true); + return true; } } diff --git a/Sources/Maintenance/Migration/v2_1/Ipv6LogReportedComments.php b/Sources/Maintenance/Migration/v2_1/Ipv6LogReportedComments.php index baa8b584f8f..c9bd02d2208 100644 --- a/Sources/Maintenance/Migration/v2_1/Ipv6LogReportedComments.php +++ b/Sources/Maintenance/Migration/v2_1/Ipv6LogReportedComments.php @@ -15,11 +15,13 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; +use SMF\Maintenance\Migration\MigrationBase; -class Ipv6LogReportedComments extends Ipv6Base +class Ipv6LogReportedComments extends MigrationBase { + use IPv6Converter; + /******************* * Public properties *******************/ @@ -27,35 +29,21 @@ class Ipv6LogReportedComments extends Ipv6Base /** * */ - public string $name = 'Update log_reported_comments member_ip with ipv6 support'; + public string $name = 'Updating log_reported_comments table with IPv6 support'; /**************** * Public methods ****************/ - /** - * - */ - public function __construct() - { - if (Db::$db->title !== POSTGRE_TITLE) { - $this->name .= ' without converting'; - } - } - /** * */ public function isCandidate(): bool { - $table = new Schema\v2_1\LogFloodcontrol(); + $table = new Schema\v2_1\LogReportedComments(); $existing_structure = $table->getCurrentStructure(); - if (Db::$db->title === POSTGRE_TITLE) { - return $existing_structure['columns']['ip']['type'] !== 'inet'; - } - - return $existing_structure['columns']['ip']['type'] !== 'varbinary'; + return $existing_structure['columns']['member_ip']['type'] !== 'inet'; } /** @@ -63,8 +51,12 @@ public function isCandidate(): bool */ public function execute(): bool { - $table = new Schema\v2_1\LogFloodcontrol(); + $table = new Schema\v2_1\LogReportedComments(); + + $this->convertStringColumnToInet($table, $table->columns['member_ip']); + + $this->handleTimeout(); - return $this->convertWithNoDataPreservation($table, 'ip'); + return true; } } diff --git a/Sources/Maintenance/Migration/v2_1/Ipv6MemberLogins.php b/Sources/Maintenance/Migration/v2_1/Ipv6MemberLogins.php index 52a8911859a..3daf95764c5 100644 --- a/Sources/Maintenance/Migration/v2_1/Ipv6MemberLogins.php +++ b/Sources/Maintenance/Migration/v2_1/Ipv6MemberLogins.php @@ -15,11 +15,13 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; +use SMF\Maintenance\Migration\MigrationBase; -class Ipv6MemberLogins extends Ipv6Base +class Ipv6MemberLogins extends MigrationBase { + use IPv6Converter; + /******************* * Public properties *******************/ @@ -27,22 +29,12 @@ class Ipv6MemberLogins extends Ipv6Base /** * */ - public string $name = 'Update member_logins ip with ipv6 support'; + public string $name = 'Updating member_logins table with IPv6 support'; /**************** * Public methods ****************/ - /** - * - */ - public function __construct() - { - if (Db::$db->title !== POSTGRE_TITLE) { - $this->name .= ' without converting'; - } - } - /** * */ @@ -51,11 +43,10 @@ public function isCandidate(): bool $table = new Schema\v2_1\MemberLogins(); $existing_structure = $table->getCurrentStructure(); - if (Db::$db->title === POSTGRE_TITLE) { - return $existing_structure['columns']['ip']['type'] !== 'inet'; - } - - return $existing_structure['columns']['ip']['type'] !== 'varbinary'; + return ( + $existing_structure['columns']['ip']['type'] !== 'inet' + || $existing_structure['columns']['ip2']['type'] !== 'inet' + ); } /** @@ -64,7 +55,26 @@ public function isCandidate(): bool public function execute(): bool { $table = new Schema\v2_1\MemberLogins(); + $existing_structure = $table->getCurrentStructure(); + + foreach (['ip', 'ip2'] as $col) { + if ($existing_structure['columns'][$col]['type'] !== 'inet') { + // This table was added in 2.1 and never had the 'CHAR' type. So if + // these columns are somehow the wrong type, their data is useless. + $this->query( + 'UPDATE {db_prefix}{raw:table} + SET {identifier:column} = {empty}', + [ + 'table' => $table->name, + 'column' => $col, + ], + ); + + $table->alterColumn($table->columns[$col]); + $this->handleTimeout(); + } + } - return $this->convertWithNoDataPreservation($table, 'ip') && $this->convertWithNoDataPreservation($table, 'ip2'); + return true; } } diff --git a/Sources/Maintenance/Migration/v2_1/Ipv6MembersIP.php b/Sources/Maintenance/Migration/v2_1/Ipv6MembersIP.php index 3cff8e413ac..2287a0f17a6 100644 --- a/Sources/Maintenance/Migration/v2_1/Ipv6MembersIP.php +++ b/Sources/Maintenance/Migration/v2_1/Ipv6MembersIP.php @@ -15,11 +15,13 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; +use SMF\Maintenance\Migration\MigrationBase; -class Ipv6MembersIP extends Ipv6Base +class Ipv6MembersIP extends MigrationBase { + use IPv6Converter; + /******************* * Public properties *******************/ @@ -27,7 +29,7 @@ class Ipv6MembersIP extends Ipv6Base /** * */ - public string $name = 'Update members with ipv6 support (IP)'; + public string $name = 'Updating members table with IPv6 support (part 1)'; /**************** * Public methods @@ -41,12 +43,7 @@ public function isCandidate(): bool $table = new Schema\v2_1\Members(); $existing_structure = $table->getCurrentStructure(); - if (Db::$db->title === POSTGRE_TITLE) { - return $existing_structure['columns']['member_ip']['type'] !== 'inet'; - } - - return isset($existing_structure['columns']['member_ip_old']) - || $existing_structure['columns']['member_ip']['type'] !== 'varbinary'; + return $existing_structure['columns']['member_ip']['type'] !== 'inet'; } /** @@ -56,6 +53,9 @@ public function execute(): bool { $table = new Schema\v2_1\Members(); - return $this->migrateData($table, 'member_ip'); + $this->convertStringColumnToInet($table, $table->columns['member_ip']); + $this->handleTimeout(); + + return true; } } diff --git a/Sources/Maintenance/Migration/v2_1/Ipv6MembersIP2.php b/Sources/Maintenance/Migration/v2_1/Ipv6MembersIP2.php index 89c9907f6a1..e115a441fa2 100644 --- a/Sources/Maintenance/Migration/v2_1/Ipv6MembersIP2.php +++ b/Sources/Maintenance/Migration/v2_1/Ipv6MembersIP2.php @@ -15,11 +15,13 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; +use SMF\Maintenance\Migration\MigrationBase; -class Ipv6MembersIP2 extends Ipv6Base +class Ipv6MembersIP2 extends MigrationBase { + use IPv6Converter; + /******************* * Public properties *******************/ @@ -27,7 +29,7 @@ class Ipv6MembersIP2 extends Ipv6Base /** * */ - public string $name = 'Update members with ipv6 support (IP2)'; + public string $name = 'Updating members table with IPv6 support (part 2)'; /**************** * Public methods @@ -41,12 +43,7 @@ public function isCandidate(): bool $table = new Schema\v2_1\Members(); $existing_structure = $table->getCurrentStructure(); - if (Db::$db->title === POSTGRE_TITLE) { - return $existing_structure['columns']['member_ip2']['type'] !== 'inet'; - } - - return isset($existing_structure['columns']['member_ip2_old']) - || $existing_structure['columns']['member_ip2']['type'] !== 'varbinary'; + return $existing_structure['columns']['member_ip2']['type'] !== 'inet'; } /** @@ -56,6 +53,9 @@ public function execute(): bool { $table = new Schema\v2_1\Members(); - return $this->migrateData($table, 'member_ip2'); + $this->convertStringColumnToInet($table, $table->columns['member_ip2']); + $this->handleTimeout(); + + return true; } } diff --git a/Sources/Maintenance/Migration/v2_1/Ipv6Messages.php b/Sources/Maintenance/Migration/v2_1/Ipv6Messages.php index 474669499a4..4788169c232 100644 --- a/Sources/Maintenance/Migration/v2_1/Ipv6Messages.php +++ b/Sources/Maintenance/Migration/v2_1/Ipv6Messages.php @@ -15,12 +15,13 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; -use SMF\Maintenance\Maintenance; +use SMF\Maintenance\Migration\MigrationBase; -class Ipv6Messages extends Ipv6Base +class Ipv6Messages extends MigrationBase { + use IPv6Converter; + /******************* * Public properties *******************/ @@ -28,7 +29,7 @@ class Ipv6Messages extends Ipv6Base /** * */ - public string $name = 'Update messages poster_ip with ipv6 support (May take a while)'; + public string $name = 'Updating messages table with IPv6 support'; /**************** * Public methods @@ -42,12 +43,7 @@ public function isCandidate(): bool $table = new Schema\v2_1\Messages(); $existing_structure = $table->getCurrentStructure(); - if (Db::$db->title === POSTGRE_TITLE) { - return $existing_structure['columns']['poster_ip']['type'] !== 'inet'; - } - - return isset($existing_structure['columns']['poster_ip_old']) - || $existing_structure['columns']['poster_ip']['type'] !== 'varbinary'; + return $existing_structure['columns']['poster_ip']['type'] !== 'inet'; } /** @@ -57,22 +53,8 @@ public function execute(): bool { $table = new Schema\v2_1\Messages(); - // This will return true once its done, but we need to do a few more things. - $this->migrateData($table, 'poster_ip'); - - $start = Maintenance::getCurrentStart(); - - if ($start <= 7) { - $table->addIndex($table->indexes['idx_ip_index']); - - $this->handleTimeout(++$start); - } - - if ($start <= 8) { - $table->addIndex($table->indexes['idx_related_ip']); - - $this->handleTimeout(++$start); - } + $this->convertStringColumnToInet($table, $table->columns['poster_ip']); + $this->handleTimeout(); return true; } diff --git a/Sources/Maintenance/Migration/v2_1/Likes.php b/Sources/Maintenance/Migration/v2_1/Likes.php index 61a58668711..7ff4bf2e401 100644 --- a/Sources/Maintenance/Migration/v2_1/Likes.php +++ b/Sources/Maintenance/Migration/v2_1/Likes.php @@ -15,8 +15,7 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Config; -use SMF\Db\DatabaseApi as Db; +use SMF\Db\Schema; use SMF\Maintenance\Maintenance; use SMF\Maintenance\Migration\MigrationBase; @@ -40,9 +39,9 @@ class Likes extends MigrationBase */ public function isCandidate(): bool { - $tables = Db::$db->list_tables(); + $table = new Schema\v2_1\UserLikes(); - return !\in_array(Config::$db_prefix . 'user_likes', $tables); + return !$table->exists(); } /** @@ -52,27 +51,19 @@ public function execute(): bool { $start = Maintenance::getCurrentStart(); - $LikesTable = new \SMF\Db\Schema\v2_1\UserLikes(); - - $tables = Db::$db->list_tables(); - - // Creating draft table. - if ($start <= 0 && !\in_array(Config::$db_prefix . 'user_likes', $tables)) { - $LikesTable->create(); - + if ($start <= 0) { + $likes_table = new Schema\v2_1\UserLikes(); + $likes_table->create(); $this->handleTimeout(++$start); } // Adding likes column to the messages table. (May take a while) if ($start <= 1) { - $MessagesTable = new \SMF\Db\Schema\v2_1\Messages(); - $existing_structure = $MessagesTable->getCurrentStructure(); + $messages_table = new Schema\v2_1\Messages(); + $existing_structure = $messages_table->getCurrentStructure(); - foreach ($MessagesTable->columns as $column) { - // Add the columns. - if ($column->name === 'likes' && !isset($existing_structure['columns'][$column->name])) { - $MessagesTable->addColumn($column); - } + if (!isset($existing_structure['columns']['likes'])) { + $messages_table->addColumn($messages_table->columns['likes']); } $this->handleTimeout(++$start); diff --git a/Sources/Maintenance/Migration/v2_1/Mentions.php b/Sources/Maintenance/Migration/v2_1/Mentions.php index de32bc69fa1..61222eb5c50 100644 --- a/Sources/Maintenance/Migration/v2_1/Mentions.php +++ b/Sources/Maintenance/Migration/v2_1/Mentions.php @@ -15,8 +15,6 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Config; -use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; use SMF\Maintenance\Migration\MigrationBase; @@ -40,9 +38,9 @@ class Mentions extends MigrationBase */ public function isCandidate(): bool { - $tables = Db::$db->list_tables(); + $table = new Schema\v2_1\Mentions(); - return !\in_array(Config::$db_prefix . 'mentions', $tables); + return !$table->exists(); } /** diff --git a/Sources/Maintenance/Migration/v2_1/ModeratorGroups.php b/Sources/Maintenance/Migration/v2_1/ModeratorGroups.php index 70be7572da7..7c160bcdf0e 100644 --- a/Sources/Maintenance/Migration/v2_1/ModeratorGroups.php +++ b/Sources/Maintenance/Migration/v2_1/ModeratorGroups.php @@ -15,8 +15,6 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Config; -use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; use SMF\Maintenance\Migration\MigrationBase; @@ -40,9 +38,9 @@ class ModeratorGroups extends MigrationBase */ public function isCandidate(): bool { - $tables = Db::$db->list_tables(); + $table = new Schema\v2_1\ModeratorGroups(); - return !\in_array(Config::$db_prefix . 'moderator_groups', $tables); + return !$table->exists(); } /** diff --git a/Sources/Maintenance/Migration/v2_1/Permissions.php b/Sources/Maintenance/Migration/v2_1/Permissions.php index 0c8cbcfa903..f7f543ae7c3 100644 --- a/Sources/Maintenance/Migration/v2_1/Permissions.php +++ b/Sources/Maintenance/Migration/v2_1/Permissions.php @@ -248,7 +248,7 @@ public function execute(): bool ); } - Db::$db->query( + $this->query( 'DELETE FROM {db_prefix}settings WHERE variable = {string:warning_show}', [ @@ -306,7 +306,7 @@ public function execute(): bool $this->handleTimeout(++$start); - Db::$db->query( + $this->query( 'DELETE FROM {db_prefix}permissions WHERE id_group = {int:guests} AND permission IN ({array_string:illegal_perms})', diff --git a/Sources/Maintenance/Migration/v2_1/PersonalMessageLabels.php b/Sources/Maintenance/Migration/v2_1/PersonalMessageLabels.php index d307db54142..6eacbc7b075 100644 --- a/Sources/Maintenance/Migration/v2_1/PersonalMessageLabels.php +++ b/Sources/Maintenance/Migration/v2_1/PersonalMessageLabels.php @@ -15,7 +15,6 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Config; use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; use SMF\Db\Schema\Column; @@ -75,15 +74,13 @@ public function execute(): bool $pm_labels_table = new Schema\v2_1\PmLabels(); $pm_labeled_messages_table = new Schema\v2_1\PmLabeledMessages(); - $tables = Db::$db->list_tables(); - if ($start <= 0) { - if (!\in_array(Config::$db_prefix . 'pm_labels', $tables)) { + if (!$pm_labels_table->exists()) { $pm_labels_table->create(); $this->handleTimeout(0); } - if (!\in_array(Config::$db_prefix . 'pm_labeled_messages', $tables)) { + if (!$pm_labeled_messages_table->exists()) { $pm_labeled_messages_table->create(); $this->handleTimeout(0); } @@ -116,10 +113,12 @@ public function execute(): bool while (!$is_done) { $this->handleTimeout($start); + $label_info = []; + $member_list = []; $inserts = []; // Pull the label info - $get_labels = Db::$db->query( + $get_labels = $this->query( 'SELECT id_member, message_labels FROM {db_prefix}members WHERE message_labels != {string:blank} @@ -131,9 +130,6 @@ public function execute(): bool ], ); - $label_info = []; - $member_list = []; - while ($row = Db::$db->fetch_assoc($get_labels)) { $member_list[] = $row['id_member']; @@ -149,6 +145,11 @@ public function execute(): bool Db::$db->free_result($get_labels); + if (empty($member_list)) { + $is_done = true; + break; + } + foreach ($label_info as $id_member => $labels) { foreach ($labels as $label => $index) { $inserts[] = [$id_member, $label]; @@ -172,7 +173,7 @@ public function execute(): bool } // This is the easy part - update the inbox stuff - Db::$db->query( + $this->query( 'UPDATE {db_prefix}pm_recipients SET in_inbox = {int:in_inbox} WHERE FIND_IN_SET({int:minusone}, labels) @@ -185,7 +186,7 @@ public function execute(): bool ); // Now we go pull the new IDs for each label - $get_new_label_ids = Db::$db->query( + $get_new_label_ids = $this->query( 'SELECT * FROM {db_prefix}pm_labels WHERE id_member IN ({array_int:member_list})', @@ -206,7 +207,7 @@ public function execute(): bool // Pull label info from pm_recipients // Ignore any that are only in the inbox - $get_pm_labels = Db::$db->query( + $get_pm_labels = $this->query( 'SELECT id_pm, id_member, labels FROM {db_prefix}pm_recipients WHERE deleted = {int:not_deleted} @@ -249,7 +250,7 @@ public function execute(): bool } // Final step of this ridiculously massive process - $get_pm_rules = Db::$db->query( + $get_pm_rules = $this->query( 'SELECT id_member, id_rule, actions FROM {db_prefix}pm_rules WHERE id_member IN ({array_int:member_list})', @@ -278,7 +279,7 @@ public function execute(): bool // Put this back into a string $actions = serialize($actions); - Db::$db->query( + $this->query( 'UPDATE {db_prefix}pm_rules SET actions = {string:actions} WHERE id_rule = {int:id_rule}', @@ -291,7 +292,7 @@ public function execute(): bool } // Remove processed pm labels, to avoid duplicated data if upgrader is restarted. - Db::$db->query( + $this->query( 'UPDATE {db_prefix}members SET message_labels = {string:blank} WHERE id_member IN ({array_int:member_list})', @@ -311,32 +312,10 @@ public function execute(): bool } $pm_recipients_table = new Schema\v2_1\PmRecipients(); - $existing_structure = $pm_recipients_table->getCurrentStructure(); - - foreach ($existing_structure['columns'] as $column) { - if ($column['name'] == 'labels') { - $col = new Column( - name: $column['name'], - type: 'varchar', - ); - - $pm_recipients_table->dropColumn($col); - } - } + $pm_recipients_table->dropColumn('labels'); $members_table = new Schema\v2_1\Members(); - $existing_structure = $members_table->getCurrentStructure(); - - foreach ($existing_structure['columns'] as $column) { - if ($column['name'] == 'message_labels') { - $col = new Column( - name: $column['name'], - type: 'varchar', - ); - - $members_table->dropColumn($col); - } - } + $members_table->dropColumn('message_labels'); return true; } diff --git a/Sources/Maintenance/Migration/v2_1/PostgreSqlFindInSet.php b/Sources/Maintenance/Migration/v2_1/PostgreSqlFindInSet.php index afc99bcfe84..34470046629 100644 --- a/Sources/Maintenance/Migration/v2_1/PostgreSqlFindInSet.php +++ b/Sources/Maintenance/Migration/v2_1/PostgreSqlFindInSet.php @@ -27,7 +27,7 @@ class PostgreSQLFindInSet extends MigrationBase /** * */ - public string $name = 'Add find_in_set function (PostgreSQL)'; + public string $name = 'Adding FIND_IN_SET function (PostgreSQL)'; /**************** * Public methods diff --git a/Sources/Maintenance/Migration/v2_1/PostgreSqlIPv6Helper.php b/Sources/Maintenance/Migration/v2_1/PostgreSqlIPv6Helper.php index b530f5a2e06..22a94f9887c 100644 --- a/Sources/Maintenance/Migration/v2_1/PostgreSqlIPv6Helper.php +++ b/Sources/Maintenance/Migration/v2_1/PostgreSqlIPv6Helper.php @@ -27,7 +27,7 @@ class PostgreSQLIPv6Helper extends MigrationBase /** * */ - public string $name = 'helper function for ip convert'; + public string $name = 'Adding helper function for IPv6 conversion'; /**************** * Public methods diff --git a/Sources/Maintenance/Migration/v2_1/PostgreSqlSchemaDiff.php b/Sources/Maintenance/Migration/v2_1/PostgreSqlSchemaDiff.php index 6273cc8e009..b1d91af1e41 100644 --- a/Sources/Maintenance/Migration/v2_1/PostgreSqlSchemaDiff.php +++ b/Sources/Maintenance/Migration/v2_1/PostgreSqlSchemaDiff.php @@ -35,8 +35,10 @@ class PostgreSqlSchemaDiff extends MigrationBase *********************/ /** - * Schmea fixes we will peform, these are not cross database safe as we intend to run this only on PostgreSQL. * @var array + * + * Schmea fixes we will peform, these are not cross database safe as we + * intend to run this only on PostgreSQL. */ private array $schema_fixes = [ ['log_subscribed', 'ALTER pending_details DROP DEFAULT'], @@ -141,6 +143,7 @@ public function execute(): bool $this->query( 'DROP INDEX IF EXISTS {db_prefix}log_actions_id_topic_id_log', ); + $this->query( 'CREATE INDEX {db_prefix}log_actions_id_topic_id_log ON {db_prefix}log_actions (id_topic, id_log)', ); diff --git a/Sources/Maintenance/Migration/v2_1/PostgreSqlSequences.php b/Sources/Maintenance/Migration/v2_1/PostgreSqlSequences.php index 357608b120e..72a6a29210e 100644 --- a/Sources/Maintenance/Migration/v2_1/PostgreSqlSequences.php +++ b/Sources/Maintenance/Migration/v2_1/PostgreSqlSequences.php @@ -238,7 +238,7 @@ public function isCandidate(): bool */ public function execute(): bool { - for ($i = Maintenance::getCurrentStart(); $i < \count($this->sequences); Maintenance::setCurrentStart()) { + for ($i = Maintenance::getCurrentStart(); $i < \count($this->sequences); $i++) { $this->handleTimeout(); $value = $this->sequences[$i]; @@ -248,9 +248,11 @@ public function execute(): bool [ 'key' => Config::$db_prefix . $value['key'], 'field' => $value['field'], - 'table' => $value['table'], + 'table' => Config::$db_prefix . $value['table'], ], ); + + Maintenance::setCurrentStart(); } return true; diff --git a/Sources/Maintenance/Migration/v2_1/Smileys.php b/Sources/Maintenance/Migration/v2_1/Smileys.php index 007e8c11c4b..c4536b8e373 100644 --- a/Sources/Maintenance/Migration/v2_1/Smileys.php +++ b/Sources/Maintenance/Migration/v2_1/Smileys.php @@ -48,12 +48,7 @@ public function execute(): bool // Adding the new `smiley_files` table if ($start <= 0) { $table = new Schema\v2_1\SmileyFiles(); - $existing_tables = Db::$db->list_tables(); - - if (!\in_array(Config::$db_prefix . $table->name, $existing_tables)) { - $table->create(); - } - + $table->create(); $this->handleTimeout(++$start); } diff --git a/Sources/Maintenance/Migration/v2_1/UserDrafts.php b/Sources/Maintenance/Migration/v2_1/UserDrafts.php index 7e32267a523..6abe26cccc8 100644 --- a/Sources/Maintenance/Migration/v2_1/UserDrafts.php +++ b/Sources/Maintenance/Migration/v2_1/UserDrafts.php @@ -41,9 +41,9 @@ class UserDrafts extends MigrationBase */ public function isCandidate(): bool { - $tables = Db::$db->list_tables(); + $table = new Schema\v2_1\UserDrafts(); - return !\in_array(Config::$db_prefix . 'user_drafts', $tables) || Maintenance::getCurrentStart() > 0; + return !$table->exists(); } /** @@ -53,14 +53,10 @@ public function execute(): bool { $start = Maintenance::getCurrentStart(); - $drafts_table = new Schema\v2_1\UserDrafts(); - - $tables = Db::$db->list_tables(); - // Creating draft table. - if ($start <= 0 && !\in_array(Config::$db_prefix . 'user_drafts', $tables)) { - $drafts_table->create(); - + if ($start <= 0) { + $table = new Schema\v2_1\UserDrafts(); + $table->create(); $this->handleTimeout(++$start); } @@ -74,8 +70,8 @@ public function execute(): bool ) ) { // Anyone who can currently post unapproved topics we assume can create drafts as well ... - $request = Db::$db->query( - 'SELECT id_group, id_board, add_deny, permission + $request = $this->query( + 'SELECT id_group, id_profile, add_deny, permission FROM {db_prefix}board_permissions WHERE permission = {literal:post_unapproved_topics}', [], @@ -86,7 +82,7 @@ public function execute(): bool while ($row = Db::$db->fetch_assoc($request)) { $inserts[] = [ (int) $row['id_group'], - (int) $row['id_board'], + (int) $row['id_profile'], 'post_draft', (int) $row['add_deny'], ]; @@ -99,7 +95,7 @@ public function execute(): bool '{db_prefix}board_permissions', [ 'id_group' => 'int', - 'id_board' => 'int', + 'id_profile' => 'int', 'permission' => 'string', 'add_deny' => 'int', ], diff --git a/Sources/Maintenance/Migration/v2_1/VerificationQuestions.php b/Sources/Maintenance/Migration/v2_1/VerificationQuestions.php index f0d44b5ee52..e9a500a81a1 100644 --- a/Sources/Maintenance/Migration/v2_1/VerificationQuestions.php +++ b/Sources/Maintenance/Migration/v2_1/VerificationQuestions.php @@ -15,7 +15,6 @@ namespace SMF\Maintenance\Migration\v2_1; -use SMF\Config; use SMF\Db\DatabaseApi as Db; use SMF\Db\Schema; use SMF\Maintenance\Maintenance; @@ -41,9 +40,9 @@ class VerificationQuestions extends MigrationBase */ public function isCandidate(): bool { - $tables = Db::$db->list_tables(); + $table = new Schema\v2_1\Qanda(); - return !\in_array(Config::$db_prefix . 'qanda', $tables); + return !$table->exists(); } /** @@ -53,14 +52,10 @@ public function execute(): bool { $start = Maintenance::getCurrentStart(); - $table = new Schema\v2_1\Qanda(); - - $tables = Db::$db->list_tables(); - - // Creating draft table. - if ($start <= 0 && !\in_array(Config::$db_prefix . 'qanda', $tables)) { + // Creating table. + if ($start <= 0) { + $table = new Schema\v2_1\Qanda(); $table->create(); - $this->handleTimeout(++$start); } diff --git a/Sources/Maintenance/Migration/v3_0/ConvertToInnoDb.php b/Sources/Maintenance/Migration/v3_0/ConvertToInnoDb.php index e3d0ffa935a..a0a82b4b076 100644 --- a/Sources/Maintenance/Migration/v3_0/ConvertToInnoDb.php +++ b/Sources/Maintenance/Migration/v3_0/ConvertToInnoDb.php @@ -54,7 +54,7 @@ public function execute(): bool $result = true; if ($structure['engine'] !== 'InnoDB') { - $result = Db::$db->query( + $result = $this->query( 'ALTER TABLE {identifier:table} ENGINE {literal:InnoDB} ROW_FORMAT=DYNAMIC', @@ -63,7 +63,7 @@ public function execute(): bool ], ); } elseif ($structure['row_format'] !== 'Dynamic') { - $result = Db::$db->query( + $result = $this->query( 'ALTER TABLE {identifier:table} ROW_FORMAT=DYNAMIC', [ @@ -80,7 +80,7 @@ public function execute(): bool // Try to ensure all future tables use dynamic row format. $can_set_global_default = false; - $request = Db::$db->query('SHOW GRANTS'); + $request = $this->query('SHOW GRANTS'); while ($row = Db::$db->fetch_row($request)) { if ( @@ -95,7 +95,7 @@ public function execute(): bool Db::$db->free_result($request); if ($can_set_global_default) { - $result = Db::$db->query( + $result = $this->query( 'SET GLOBAL innodb_default_row_format=DYNAMIC', [ 'db_error_skip' => true, diff --git a/Sources/Maintenance/Migration/v3_0/DropModPrefs.php b/Sources/Maintenance/Migration/v3_0/DropModPrefs.php new file mode 100644 index 00000000000..2182a4920b4 --- /dev/null +++ b/Sources/Maintenance/Migration/v3_0/DropModPrefs.php @@ -0,0 +1,57 @@ +getCurrentStructure(); + + return isset($existing_structure['columns']['mod_prefs']); + } + + /** + * + */ + public function execute(): bool + { + $table = new Schema\v3_0\Members(); + $table->dropColumn('mod_prefs'); + + return true; + } +} diff --git a/Sources/Maintenance/Migration/v3_0/EditHistory.php b/Sources/Maintenance/Migration/v3_0/EditHistory.php index 42e559964b7..28507c27929 100644 --- a/Sources/Maintenance/Migration/v3_0/EditHistory.php +++ b/Sources/Maintenance/Migration/v3_0/EditHistory.php @@ -50,7 +50,7 @@ public function execute(): bool } // Populate edit_history. - $request = Db::$db->query( + $request = $this->query( 'SELECT id_msg, body, modified_time, modified_name, modified_reason, edit_history FROM {db_prefix}messages WHERE id_msg > {int:start} @@ -77,7 +77,7 @@ public function execute(): bool $row['modified_reason'], ]]); - Db::$db->query( + $this->query( 'UPDATE {db_prefix}messages SET edit_history = {string:edit_history} WHERE id_msg = {int:id_msg}', diff --git a/Sources/Maintenance/Migration/v3_0/EventUids.php b/Sources/Maintenance/Migration/v3_0/EventUids.php index 446978eae04..bf1389e5f23 100644 --- a/Sources/Maintenance/Migration/v3_0/EventUids.php +++ b/Sources/Maintenance/Migration/v3_0/EventUids.php @@ -41,7 +41,7 @@ public function execute(): bool { $calendar_updates = []; - $request = Db::$db->query( + $request = $this->query( 'SELECT id_event, uid FROM {db_prefix}calendar', [], @@ -56,7 +56,7 @@ public function execute(): bool Db::$db->free_result($request); foreach ($calendar_updates as $calendar_update) { - Db::$db->query( + $this->query( 'UPDATE {db_prefix}calendar SET uid = {string:uid} WHERE id_event = {int:id_event}', diff --git a/Sources/Maintenance/Migration/v3_0/HolidaysToEvents.php b/Sources/Maintenance/Migration/v3_0/HolidaysToEvents.php index 199524a028d..e5697819e99 100644 --- a/Sources/Maintenance/Migration/v3_0/HolidaysToEvents.php +++ b/Sources/Maintenance/Migration/v3_0/HolidaysToEvents.php @@ -634,7 +634,7 @@ public function execute(): bool User::load(); } - $request = Db::$db->query( + $request = $this->query( 'SELECT title, GROUP_CONCAT(event_date) as rdates FROM {db_prefix}calendar_holidays GROUP BY title', diff --git a/Sources/Maintenance/Migration/v3_0/LanguageDirectory.php b/Sources/Maintenance/Migration/v3_0/LanguageDirectory.php index 57c527cd770..4a85c9fa1cb 100644 --- a/Sources/Maintenance/Migration/v3_0/LanguageDirectory.php +++ b/Sources/Maintenance/Migration/v3_0/LanguageDirectory.php @@ -72,7 +72,7 @@ public function execute(): bool $this->handleTimeout(); // Skip errors here so we don't croak if the columns don't exist... - $request = Db::$db->query( + $request = $this->query( 'SELECT id_member FROM {db_prefix}members WHERE lngfile IN ({array_string:possible_languages}) @@ -105,7 +105,7 @@ public function execute(): bool $args['search_members'] = $members; - Db::$db->query( + $this->query( 'UPDATE {db_prefix}members SET lngfile = CASE ' . implode(' ', $statements) . ' diff --git a/Sources/Maintenance/Migration/v3_0/MailType.php b/Sources/Maintenance/Migration/v3_0/MailType.php index c8e1a005d48..d60f295789f 100644 --- a/Sources/Maintenance/Migration/v3_0/MailType.php +++ b/Sources/Maintenance/Migration/v3_0/MailType.php @@ -15,7 +15,6 @@ namespace SMF\Maintenance\Migration\v3_0; -use SMF\Db\DatabaseApi as Db; use SMF\Maintenance\Migration\MigrationBase; class MailType extends MigrationBase @@ -38,7 +37,7 @@ class MailType extends MigrationBase */ public function execute(): bool { - Db::$db->query( + $this->query( 'UPDATE {db_prefix}settings SET value = CASE diff --git a/Sources/Maintenance/Migration/v3_0/PermissionChanges.php b/Sources/Maintenance/Migration/v3_0/PermissionChanges.php index 17061c1b744..75cd3dabb1f 100644 --- a/Sources/Maintenance/Migration/v3_0/PermissionChanges.php +++ b/Sources/Maintenance/Migration/v3_0/PermissionChanges.php @@ -15,7 +15,6 @@ namespace SMF\Maintenance\Migration\v3_0; -use SMF\Db\DatabaseApi as Db; use SMF\Maintenance\Migration\MigrationBase; class PermissionChanges extends MigrationBase @@ -38,7 +37,7 @@ class PermissionChanges extends MigrationBase */ public function execute(): bool { - Db::$db->query( + $this->query( 'DELETE FROM {db_prefix}permissions WHERE permission IN ({array_string:perms})', [ diff --git a/Sources/Maintenance/Migration/v3_0/PostgreSqlFunctions.php b/Sources/Maintenance/Migration/v3_0/PostgreSqlFunctions.php index 493a23bf267..bf3ace41f8f 100644 --- a/Sources/Maintenance/Migration/v3_0/PostgreSqlFunctions.php +++ b/Sources/Maintenance/Migration/v3_0/PostgreSqlFunctions.php @@ -49,7 +49,7 @@ public function execute(): bool { $schema_version = substr(__NAMESPACE__, strrpos(__NAMESPACE__, '\\', -1) + 1); - $queries = Table::getInitializers($schema_version, POSTGRE_TITLE); + $queries = Table::getInitializers($schema_version); foreach ($queries as $query) { // Use the upgrade query handler. diff --git a/Sources/Maintenance/Migration/v3_0/RecurringEvents.php b/Sources/Maintenance/Migration/v3_0/RecurringEvents.php index ce10d2a8e54..c3cc255fb63 100644 --- a/Sources/Maintenance/Migration/v3_0/RecurringEvents.php +++ b/Sources/Maintenance/Migration/v3_0/RecurringEvents.php @@ -51,13 +51,13 @@ public function execute(): bool } if (Db::$db->title === MYSQL_TITLE) { - Db::$db->query( + $this->query( 'ALTER TABLE {db_prefix}calendar MODIFY COLUMN start_date DATE AFTER id_member', [], ); - Db::$db->query( + $this->query( 'ALTER TABLE {db_prefix}calendar MODIFY COLUMN end_date DATE AFTER start_date', [], @@ -67,7 +67,7 @@ public function execute(): bool $updates = []; - $request = Db::$db->query( + $request = $this->query( 'SELECT id_event, start_date, end_date, start_time, end_time, timezone FROM {db_prefix}calendar', [], @@ -120,7 +120,7 @@ public function execute(): bool Db::$db->free_result($request); foreach ($updates as $id_event => $changes) { - Db::$db->query( + $this->query( 'UPDATE {db_prefix}calendar SET duration = {string:duration}, end_date = {date:end_date}, rrule = {string:rrule} WHERE id_event = {int:id_event}', diff --git a/Sources/Maintenance/Tools/Install.php b/Sources/Maintenance/Tools/Install.php index 29a50f32add..c4810ddd8c2 100644 --- a/Sources/Maintenance/Tools/Install.php +++ b/Sources/Maintenance/Tools/Install.php @@ -69,6 +69,13 @@ class Install extends ToolsBase implements ToolsInterface */ public string $script_file = 'install.php'; + /** + * @var string + * + * HTML element ID for the submission form in this tool's HTML templates. + */ + public string $form_id = 'install_form'; + /********************* * Internal properties *********************/ @@ -394,7 +401,7 @@ public function databaseSettings(): bool // If we have not found a one, set some defaults. if (!$foundOne) { Maintenance::$context['db'] = [ - 'server' => $db->getDefaultHost(), + 'server' => $db->getDefaultHost() === '' ? 'localhost' : $db->getDefaultHost(), 'user' => $db->getDefaultUser(), 'name' => $db->getDefaultName(), 'pass' => $db->getDefaultPassword(), @@ -550,13 +557,13 @@ public function databaseSettings(): bool ); // Okay, let's try the prefix if it didn't work... - if (!Db::$db->select(Db::$db->name, Db::$db->connection) && Db::$db->name != '') { + if (!Db::$db->select(Db::$db->name, Db::$db->connection)) { Db::$db->query( 'CREATE DATABASE IF NOT EXISTS {identifier:name}', [ 'security_override' => true, 'db_error_skip' => true, - 'name' => Db::$db->name, + 'name' => Db::$db->prefix . Db::$db->name, ], Db::$db->connection, ); @@ -742,7 +749,7 @@ public function databasePopulation(): bool // Some initialization may exist. Db::$db->disableQueryCheck = true; - foreach (Table::getInitializers($this->schema_version, Db::$db->title) as $query) { + foreach (Table::getInitializers($this->schema_version) as $query) { Db::$db->query($query, [ 'security_override' => true, ]); diff --git a/Sources/Maintenance/Tools/ToolsBase.php b/Sources/Maintenance/Tools/ToolsBase.php index abe6ee09fa6..7193b974371 100644 --- a/Sources/Maintenance/Tools/ToolsBase.php +++ b/Sources/Maintenance/Tools/ToolsBase.php @@ -42,6 +42,13 @@ abstract class ToolsBase */ public string $script_file; + /** + * @var string + * + * HTML element ID for the submission form in this tool's HTML templates. + */ + public string $form_id; + /** * @var bool * @@ -540,26 +547,34 @@ final public function detectLanguages(array $key_files = ['General']): array } /** - * This will check if we need to handle a timeout, if so, it sets up data for the next round. + * This will check if we need to handle a timeout, if so, it sets up data + * for the next round. * + * @param array $json_response_data Data to send in a JSON response if we + * have timed out. This data is passed to Maintenance::jsonResponse(). + * Only used when Maintenance::isJson() returns true. * @throws \ValueError * @throws \Exception */ - public function checkAndHandleTimeout(): void + public function checkAndHandleTimeout(array $json_response_data = []): void { if (!Maintenance::isOutOfTime()) { return; } + $this->logProgress(Lang::getTxt('log_paused_step', ['num' => $this->getStep()->getId()], file: 'Maintenance')); + // If this is not json, we need to do a few things. if (!Maintenance::isJson()) { // We're going to pause after this! Maintenance::$context['pause'] = true; Maintenance::setQueryString(); + } else { + Maintenance::jsonResponse($json_response_data); } - Maintenance::exit(); + Maintenance::exit(Maintenance::isJson()); throw new \Exception('Zombies!'); } @@ -585,6 +600,15 @@ public function updateSettingsFile(array $config_vars, ?bool $keep_quotes = null $this->logProgress(Lang::getTxt('log_settings_file_save', ['setting_names' => Lang::sentenceList(array_keys($config_vars))], file: 'Maintenance'), true); } + if ($rebuild) { + // Remove all the existing comments to make the rebuild nice and clean. + Config::safeFileWrite( + file: SMF_SETTINGS_FILE, + data: Config::stripPhpComments(file_get_contents(SMF_SETTINGS_FILE)), + mtime: time(), + ); + } + if (!Config::updateSettingsFile($config_vars, $keep_quotes, $rebuild)) { $this->logProgress(Lang::getTxt('log_failed_with_error', ['error' => Lang::getTxt('settings_error', file: 'Maintenance')], file: 'Maintenance')); @@ -641,6 +665,7 @@ public function updateModSettings(array $change_array, bool $update = false): bo protected function deleteOldSchemaAndMaintenanceFiles(?FtpConnection $ftp): void { if (!isset(Config::$modSettings['smf_version'])) { + Db::load(); Config::reloadModSettings(); } diff --git a/Sources/Maintenance/Tools/Upgrade.php b/Sources/Maintenance/Tools/Upgrade.php index 5af6b9bb821..ac4a00aa0e0 100644 --- a/Sources/Maintenance/Tools/Upgrade.php +++ b/Sources/Maintenance/Tools/Upgrade.php @@ -86,7 +86,6 @@ class Upgrade extends ToolsBase implements ToolsInterface Migration\v2_1\FixDates::class, Migration\v2_1\CreateMemberLogins::class, Migration\v2_1\CollapsedCategories::class, - Migration\v2_1\BoardDescriptions::class, Migration\v2_1\LegacyAttachments::class, Migration\v2_1\AttachmentSizes::class, Migration\v2_1\AttachmentDirectory::class, @@ -154,6 +153,7 @@ class Upgrade extends ToolsBase implements ToolsInterface Migration\v2_1\IdxLogComments::class, Migration\v2_1\MysqlLegacyData::class, Migration\v2_1\Smileys::class, + Migration\v2_1\BoardDescriptions::class, Migration\v2_1\LogErrorsBacktrace::class, Migration\v2_1\BoardPermissionsView::class, Migration\v2_1\PostgreSqlSchemaDiff::class, @@ -172,6 +172,7 @@ class Upgrade extends ToolsBase implements ToolsInterface Migration\v3_0\RecurringEvents::class, Migration\v3_0\HolidaysToEvents::class, Migration\v3_0\EventUids::class, + Migration\v3_0\DropModPrefs::class, Migration\v3_0\SpoofDetector::class, Migration\v3_0\SearchResultsPrimaryKey::class, Migration\v3_0\MailType::class, @@ -193,7 +194,6 @@ class Upgrade extends ToolsBase implements ToolsInterface // Cleanup steps for 2.1 -> 3.0 'v3_0' => [ Cleanup\v3_0\TasksDirCase::class, - Cleanup\v3_0\OldFiles::class, ], ]; @@ -228,6 +228,13 @@ class Upgrade extends ToolsBase implements ToolsInterface */ public string $script_file = 'upgrade.php'; + /** + * @var string + * + * HTML element ID for the submission form in this tool's HTML templates. + */ + public string $form_id = 'upgrade_form'; + /** * @var int * @@ -979,18 +986,15 @@ public function upgradeOptions(): bool // If they have a "host:port" setup for the host, split that into separate values // You should never have a : in the hostname if you're not on MySQL, but better safe than sorry if (strpos(Config::$db_server, ':') !== false) { - list(Config::$db_server, Config::$db_port) = explode(':', Config::$db_server); + list(Config::$db_server, $db_port) = explode(':', Config::$db_server); + Config::$db_port = (int) $db_port; $file_settings['db_server'] = Config::$db_server; - - // Only set this if we're not using the default port - if (Config::$db_port != Db::$db->getDefaultPort()) { - $file_settings['db_port'] = (int) Config::$db_port; - } + $file_settings['db_port'] = Config::$db_port; } // If db_port is set and is the same as the default, set it to 0. - if (!empty(Config::$db_port) && Config::$db_port != Db::$db->getDefaultPort()) { + if (!empty(Config::$db_port) && Config::$db_port == Db::$db->getDefaultPort()) { $file_settings['db_port'] = 0; } @@ -1223,10 +1227,11 @@ public function finalize(): bool // Log what we've done. if (!isset(User::$me)) { - User::load(); + User::load(dataset: 'minimal'); } if (empty(User::$me->id) && !empty($this->user['id'])) { + User::load($this->user['id'], dataset: 'minimal'); User::setMe($this->user['id']); } @@ -1611,6 +1616,7 @@ private function performSubsteps(array $substeps): bool // Load up the current user safely. if (!isset(User::$me)) { + User::load($this->user['id'], dataset: 'minimal'); User::setMe($this->user['id']); if ($this->user['id'] === 0 && $this->user['name'] === 'Database Admin') { diff --git a/Sources/Maintenance/Utf8ConverterStep.php b/Sources/Maintenance/Utf8ConverterStep.php index d99ac5bd097..e4309782ccd 100644 --- a/Sources/Maintenance/Utf8ConverterStep.php +++ b/Sources/Maintenance/Utf8ConverterStep.php @@ -743,7 +743,7 @@ public function convertDatabase(): bool if (Maintenance::isJson()) { Maintenance::jsonResponse([ 'name' => $substep->name, - 'next' => $substeps[Maintenance::getCurrentSubStep()]->name, + 'next' => isset($substeps[Maintenance::getCurrentSubStep()]) ? $substeps[Maintenance::getCurrentSubStep()]->name : '', 'completed' => true, 'substep' => Maintenance::getCurrentSubStep(), 'start' => Maintenance::getCurrentStart(), diff --git a/Sources/QueryString.php b/Sources/QueryString.php index c92a0a3ed52..554130c65cc 100644 --- a/Sources/QueryString.php +++ b/Sources/QueryString.php @@ -639,6 +639,7 @@ protected static function sslRedirect(): void && !Sapi::httpsOn() && str_starts_with($_SERVER['REQUEST_URL'] ?? '', 'http://') && SMF != 'SSI' + && !\defined('SMF_INSTALLING') ) { if (isset($_GET['sslRedirect'])) { ErrorHandler::fatalLang('login_ssl_required', false); @@ -654,7 +655,7 @@ protected static function sslRedirect(): void */ protected static function wwwRedirect(): void { - if (SMF == 'SSI') { + if (SMF == 'SSI' || \defined('SMF_INSTALLING')) { return; } @@ -678,7 +679,7 @@ protected static function wwwRedirect(): void */ protected static function fixUrl(): void { - if (SMF == 'SSI') { + if (SMF == 'SSI' || \defined('SMF_INSTALLING')) { return; } diff --git a/Sources/Tasks/GroupReq_Notify.php b/Sources/Tasks/GroupReq_Notify.php index 95a0d70cbab..37d76560529 100644 --- a/Sources/Tasks/GroupReq_Notify.php +++ b/Sources/Tasks/GroupReq_Notify.php @@ -105,7 +105,7 @@ public function execute(): bool Theme::loadEssential(); $request = Db::$db->query( - 'SELECT id_member, email_address, lngfile, member_name, mod_prefs + 'SELECT id_member, email_address, lngfile, member_name FROM {db_prefix}members WHERE id_member IN ({array_int:moderator_list}) ORDER BY lngfile', diff --git a/Sources/User.php b/Sources/User.php index 3af549bb48d..00bf23d8fad 100644 --- a/Sources/User.php +++ b/Sources/User.php @@ -575,14 +575,6 @@ class User implements \ArrayAccess */ public array $mod_cache = []; - /** - * @var string - * - * Moderator preferences. - * @todo This doesn't appear to be used anywhere. - */ - public string $mod_prefs = ''; - /** * @var bool * diff --git a/Themes/default/Admin.template.php b/Themes/default/Admin.template.php index 2be9b2150e3..bfc0c72d497 100644 --- a/Themes/default/Admin.template.php +++ b/Themes/default/Admin.template.php @@ -1557,7 +1557,7 @@ function template_repair_boards() if (!empty(Utils::$context['redirect_to_recount'])) { echo ' '; } } diff --git a/Themes/default/InstallTemplate.php b/Themes/default/InstallTemplate.php index 5387f37cc37..d2e4651c55b 100644 --- a/Themes/default/InstallTemplate.php +++ b/Themes/default/InstallTemplate.php @@ -36,7 +36,7 @@ public static function upper(): void { if (\count(Maintenance::$tool->getSteps()) - 1 !== (int) Maintenance::getCurrentStep()) { echo ' -