Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installer and upgrader rewrite #8093

Draft
wants to merge 84 commits into
base: release-3.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
6dc4234
Creates SMF\Db\Schema and descendents
Sesquipedalian Jan 25, 2024
b21fbb1
Adds database schema definition for SMF 2.1 to ./other/Schema
Sesquipedalian Feb 8, 2024
3c6a5b9
Initial replacement of installer logic
jdarwood007 Feb 9, 2024
682dfc6
Update Column.php
Sesquipedalian Feb 9, 2024
6b21c03
Worked on some phpdoc
jdarwood007 Feb 9, 2024
17e47ec
Add more phpdocs
jdarwood007 Feb 9, 2024
425cf52
Rename index to indices to avoid conflicts with index
jdarwood007 Feb 10, 2024
1e52320
DId not mean to send that up, testing for fixing the bug with that.
jdarwood007 Feb 10, 2024
a8ef0db
Reverse some changes that shouldn't have been changed.
jdarwood007 Feb 13, 2024
2fd2007
Reverts some more changes that shouldn't have happened
Sesquipedalian Feb 14, 2024
b1f3c00
Update Sources/Db/Schema/Column.php
Sesquipedalian Feb 14, 2024
452cfad
Some cleanup in install.php
Sesquipedalian Feb 14, 2024
5009f22
Improves code for finding the right dir in Maintenance::getBaseDir()
Sesquipedalian Feb 14, 2024
ebe7161
Started wireframe for upgrades
jdarwood007 Feb 14, 2024
b06abd5
Fixes some accidental reversions of Lang::getTxt() usage
Sesquipedalian Feb 14, 2024
4177e54
More cleanup
Sesquipedalian Feb 14, 2024
1bbace1
Removes unnecessary code duplication
Sesquipedalian Feb 14, 2024
a24873f
Continue on writing wireframe for upgrader
jdarwood007 Feb 15, 2024
db000e9
Work on welcome page
jdarwood007 Feb 20, 2024
fd65aff
Merge branch 'release-3.0' into db_schema
jdarwood007 Feb 20, 2024
e0da08c
Welcome page loads
jdarwood007 Feb 20, 2024
9ad7c21
Get login working, get upgrade options page loading
jdarwood007 Feb 21, 2024
f9c2208
Merge branch 'release-3.0' into db_schema
Sesquipedalian Feb 21, 2024
443e5c4
Updates to fix a few github action issues with the changes.
jdarwood007 Feb 21, 2024
895a7ff
Merge branch 'db_schema' of github.com:Sesquipedalian/SMF into db_schema
jdarwood007 Feb 21, 2024
f864853
Merge branch 'release-3.0' into db_schema
jdarwood007 Feb 25, 2024
f4573f9
Backups work
jdarwood007 Feb 26, 2024
01430b9
Merge branch 'release-3.0' into db_schema
jdarwood007 Feb 26, 2024
632f23c
Merge branch 'release-3.0' into db_schema
Sesquipedalian Feb 29, 2024
d1427d3
Minor fixes in SMF\Maintenance\Tools\Install
Sesquipedalian Feb 29, 2024
120445f
Tidying and documentation in Install and Upgrade tools
Sesquipedalian Feb 29, 2024
4e56499
Typo fix
Sesquipedalian Feb 29, 2024
75d1a8e
Rename Index.php to index.php, part 1
Sesquipedalian Mar 1, 2024
9c524f0
Rename Index.php to index.php, part 2
Sesquipedalian Mar 1, 2024
c8e2ca3
A bit of tidying in upgrade.php
Sesquipedalian Mar 1, 2024
59aad48
Fixes various issues in installer (it works now)
Sesquipedalian Mar 1, 2024
501b9b5
Defines constants before using in upgrade.php
Sesquipedalian Mar 2, 2024
7672349
Decodes JSON data in SMF\Maintenance\Tools\Upgrade::getUpgradeData()
Sesquipedalian Mar 2, 2024
2ad0a99
Replaces getRequiredVersionForPHP() with a simple constant
Sesquipedalian Mar 2, 2024
eadf558
Compares settings to defaults in SMF\Maintenance::isInstalled()
Sesquipedalian Mar 2, 2024
be34eb6
More tidying and documentation
Sesquipedalian Mar 2, 2024
d4391f0
Fixes version checking in Upgrade
Sesquipedalian Mar 2, 2024
d56a9aa
Respect and use $use_old_hashing in Maintenance::loginAdmin()
Sesquipedalian Mar 2, 2024
8d7d87d
Whitespace fixes in Install
Sesquipedalian Mar 2, 2024
a84a4e5
Removes unnecessary Windows check
Sesquipedalian Mar 2, 2024
fd97a09
Removes $initial_columns property in SMF\Db\Schema\Table
Sesquipedalian Mar 2, 2024
c6e4966
Add some migration logic
jdarwood007 Mar 2, 2024
2418284
Minor documentation fixes
Sesquipedalian Mar 2, 2024
61cb192
Add a few more migration steps
jdarwood007 Mar 3, 2024
5f27462
Forgot PHP CS
jdarwood007 Mar 3, 2024
76148b7
Merge branch 'db_schema' of github.com:Sesquipedalian/SMF into db_schema
jdarwood007 Mar 3, 2024
b69ef7b
Add some more migration steps
jdarwood007 Mar 13, 2024
e94d8f0
Compares settings to defaults in Maintenance::isInstalled() (take 2)
Sesquipedalian Mar 17, 2024
270962c
Improves naming and organization consistency in SMF\Maintenance\*
Sesquipedalian Mar 26, 2024
6a30532
Use named and explicitly ordered migration substeps
Sesquipedalian Mar 26, 2024
36bca51
Maintenance language file tweaks
Sesquipedalian Mar 26, 2024
0db28f8
Merge branch 'release-3.0' into db_schema
Sesquipedalian Mar 26, 2024
1156540
Adds use statements that should have been in 6a30532
Sesquipedalian Mar 26, 2024
d2441c4
Add support for renaming columns
jdarwood007 Apr 6, 2024
6cca222
Add some more migrations
jdarwood007 Apr 6, 2024
ec3bce5
Custom Fields logic
jdarwood007 May 5, 2024
a7064e4
Merge branch 'release-3.0' into db_schema
jdarwood007 May 5, 2024
28a61b6
Few more migration steps
jdarwood007 May 5, 2024
4985444
Found a few missing index files
jdarwood007 May 5, 2024
476f0c2
Merge branch 'release-3.0' into db_schema
jdarwood007 Jun 16, 2024
323dc60
More 2.1 migration steps
jdarwood007 Jun 16, 2024
0f1e7f9
PHP-CS-Fixer cleanup
Sesquipedalian Jun 27, 2024
d7dc026
Merge branch 'release-3.0' into 3.0/db_schema
Sesquipedalian Jun 27, 2024
37481cf
Moves methods to add, alter, and drop columns and indices to Table
Sesquipedalian Jun 27, 2024
6be83f1
Renames SMF\Db\Schema\Indices to SMF\Db\Schema\DbIndex
Sesquipedalian Jun 27, 2024
8556a6c
Updates method calls for adding columns, etc.
Sesquipedalian Jun 27, 2024
fb4f62a
Remove ICQ
Sesquipedalian Jun 27, 2024
04ddbaa
Revert "Remove ICQ"
Sesquipedalian Jun 27, 2024
b8c8f9a
Tidying
Sesquipedalian Jun 27, 2024
a71377c
Updates schema and adds migration step for message version column
Sesquipedalian Jun 27, 2024
e91c916
Updates schema and adds migration steps for for calendar table
Sesquipedalian Jun 27, 2024
ad0f3a9
Adds migration step for spoof detector support
Sesquipedalian Jun 27, 2024
dd547a4
Adds migration step for spoof detector support (part 2)
Sesquipedalian Jun 27, 2024
307f1de
Check keys, not values
Sesquipedalian Jun 27, 2024
38ae58a
Avoid false positives when looking for calendar_holidays table
Sesquipedalian Jun 27, 2024
d1bba97
Fixes logic for checking column name in SessionIDs migration step
Sesquipedalian Jun 27, 2024
b76c4fa
Uses Table::getStructure method
Sesquipedalian Jun 27, 2024
57ea9f0
For clarity, renames Table::getStructure to Table::getCurrentStructure
Sesquipedalian Jun 27, 2024
9ac173c
Merge branch 'release-3.0' into db_schema
Sesquipedalian Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
!/Languages/en_US/
/Languages/en_US/agreement.txt
Settings.php
!Sources/Db/Schema/*/Settings.php
Settings_bak.php
Settings_org.php
db_last_error.php
Expand Down
437 changes: 235 additions & 202 deletions Languages/en_US/Install.php → Languages/en_US/Maintenance.php

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Sources/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,10 @@ public static function setLoginCookie(int $cookie_length, int $id, string $passw
// Backup and remove the old session.
$oldSessionData = $_SESSION;
$_SESSION = [];
session_destroy();

if (session_status() === PHP_SESSION_ACTIVE) {
session_destroy();
}

// Recreate and restore the new session.
Session::load();
Expand Down
6 changes: 3 additions & 3 deletions Sources/Db/APIs/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ public function create_table(string $table_name, array $columns, array $indexes
$short_table_name = str_replace('{db_prefix}', $this->prefix, $table_name);

// First - no way do we touch SMF tables.
if (in_array(strtolower($short_table_name), $this->reservedTables)) {
if (!defined('SMF_INSTALLING') && in_array(strtolower($short_table_name), $this->reservedTables)) {
return false;
}

Expand Down Expand Up @@ -1748,7 +1748,7 @@ public function drop_table(string $table_name, array $parameters = [], string $e
$short_table_name = str_replace('{db_prefix}', $this->prefix, $table_name);

// God no - dropping one of these = bad.
if (in_array(strtolower($short_table_name), $this->reservedTables)) {
if (!defined('SMF_INSTALLING') && in_array(strtolower($short_table_name), $this->reservedTables)) {
return false;
}

Expand Down Expand Up @@ -2434,7 +2434,7 @@ protected function create_query_column(array $column): string

// Sort out the size... and stuff...
$column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;
list($type, $size) = $this->calculate_type($column['type'], (int) $column['size']);
list($type, $size) = $this->calculate_type($column['type'], $column['size'] === null ? null : (int) $column['size']);

// Allow unsigned integers (mysql only)
$unsigned = in_array($type, ['int', 'tinyint', 'smallint', 'mediumint', 'bigint']) && !empty($column['unsigned']) ? 'unsigned ' : '';
Expand Down
4 changes: 2 additions & 2 deletions Sources/Db/APIs/PostgreSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@ public function create_table(string $table_name, array $columns, array $indexes
$short_table_name = str_replace('{db_prefix}', $this->prefix, $table_name);

// First - no way do we touch SMF tables.
if (in_array(strtolower($short_table_name), $this->reservedTables)) {
if (!defined('SMF_INSTALLING') && in_array(strtolower($short_table_name), $this->reservedTables)) {
return false;
}

Expand Down Expand Up @@ -1853,7 +1853,7 @@ public function drop_table(string $table_name, array $parameters = [], string $e
$short_table_name = str_replace('{db_prefix}', $this->prefix, $table_name);

// God no - dropping one of these = bad.
if (in_array(strtolower($table_name), $this->reservedTables)) {
if (!defined('SMF_INSTALLING') && in_array(strtolower($table_name), $this->reservedTables)) {
return false;
}

Expand Down
6 changes: 6 additions & 0 deletions Sources/Db/DatabaseApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ protected function __construct()
*/
protected function prefixReservedTables(): void
{
if (defined('SMF_INSTALLING')) {
$this->reservedTables = [];

return;
}

// Reset $reservedTables to default.
$class_vars = get_class_vars(__CLASS__);
$this->reservedTables = $class_vars['reservedTables'];
Expand Down
203 changes: 203 additions & 0 deletions Sources/Db/Schema/Column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<?php

/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2023 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 3.0 Alpha 1
*/

declare(strict_types=1);

namespace SMF\Db\Schema;

use SMF\Db\DatabaseApi as Db;

/**
* Represents a column in a database table.
*/
class Column
{
/*******************
* Public properties
*******************/

/**
* @var string
*
* Name of the column.
*/
public string $name;

/**
* @var string
*
* Data type of the column.
*/
public string $type;

/**
* @var ?int
*
* Size of the column.
* Only applicable to some data types.
*/
public ?int $size;

/**
* @var ?bool
*
* Whether the column uses unsigned numerical values.
* Only applicable in MySQL.
*/
public ?bool $unsigned;

/**
* @var ?bool
*
* Whether the column disallows null values.
*/
public ?bool $not_null;

/**
* @var string|float|int|bool|null
*
* Default value of the column.
*/
public string|float|int|bool|null $default;

/**
* @var ?bool
*
* Whether this is an automatically incrementing column.
* Only applicable to integer columns.
*/
public ?bool $auto;

/**
* @var ?string
*
* The character set for string data.
* Only applicable to string types.
*/
public ?string $charset;

/**
* @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;

/****************
* Public methods
****************/

/**
* Constructor.
*
* @param string $name Name of the column.
* @param string $type Data type of the column.
* @param ?int $size Size of the column.
* Only applicable to some data types.
* @param ?bool $unsigned Whether the column uses unsigned numerical values.
* Only used by MySQL.
* @param ?bool $not_null Whether the column disallows null values.
* @param mixed $default Default value of the column. If null, no default
* will be set. To set an explicit null default, use the string 'NULL'.
* @param ?bool $auto Whether this is an automatically incrementing 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.
*/
public function __construct(
string $name,
string $type,
?int $size = null,
?bool $unsigned = null,
?bool $not_null = null,
string|float|int|bool|null $default = null,
?bool $auto = null,
?string $charset = null,
) {
$this->name = strtolower($name);
$this->type = strtolower($type);

if (isset($default)) {
$this->default = $default === 'NULL' ? null : $default;
}

foreach (['auto', 'size', 'unsigned', 'not_null'] as $var) {
if (isset($var)) {
$this->{$var} = ${$var};
}
}

if (isset($charset)) {
$this->charset = strtolower($charset);
}
}

/**
* Adds this column to the specified table.
*
* @see SMF\Db\DatabaseApi::add_column
*
* @param string $table_name The name of the table to add the column to.
* @param string $if_exists What to do if the column exists.
* If 'update', column is updated.
* @return bool Whether or not the operation was successful.
*/
public function add(string $table_name, string $if_exists = 'update'): bool
Sesquipedalian marked this conversation as resolved.
Show resolved Hide resolved
{
return Db::$db->add_column(
$table_name,
get_object_vars($this),
[],
$if_exists,
);
}

/**
* Updates the column in the database to match the definition given by this
* object's properties.
*
* @see SMF\Db\DatabaseApi::change_column
*
* @param string $table_name Name of the table that contains this column.
* @param ?string $old_name If passed, uses this as the old column name.
* @return bool Whether or not the operation was successful.
*/
public function alter(string $table_name, ?string $old_name = null): bool
{
return Db::$db->change_column(
$table_name,
$old_name ?? $this->name,
get_object_vars($this),
);
}

/**
* Drops this column from the specified table.
*
* @see SMF\Db\DatabaseApi::remove_column
*
* @param string $table_name The name of the table to drop the column from.
* @return bool Whether or not the operation was successful.
*/
public function drop(string $table_name): bool
{
return Db::$db->remove_column(
$table_name,
$this->name,
);
}
}

?>
Loading