-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6e4966
commit 61cb192
Showing
9 changed files
with
848 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?php | ||
|
||
/** | ||
* Simple Machines Forum (SMF) | ||
* | ||
* @package SMF | ||
* @author Simple Machines https://www.simplemachines.org | ||
* @copyright 2024 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\Maintenance\Migration\v2_1; | ||
|
||
use SMF\Config; | ||
use SMF\Db\DatabaseApi as Db; | ||
use SMF\Db\Schema\v3_0\MemberLogins; | ||
use SMF\Maintenance; | ||
use SMF\Maintenance\Migration; | ||
use SMF\Db\Schema\v3_0; | ||
use SMF\Security; | ||
|
||
class Migration0001 extends Migration | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public string $name = 'Adding new settings'; | ||
|
||
protected array $newSettings = [ | ||
'topic_move_any' => 1, | ||
'enable_ajax_alerts' => 1, | ||
'alerts_auto_purge' => 30, | ||
'minimize_files' => 1, | ||
'additional_options_collapsable' => 1, | ||
'defaultMaxListItems' => 15, | ||
'loginHistoryDays' => 30, | ||
'securityDisable_moderate' => 1, | ||
'httponlyCookies' => 1, | ||
'samesiteCookies' => 'lax', | ||
'export_expiry' => 7, | ||
'export_min_diskspace_pct' => 5, | ||
'export_rate' => 250, | ||
'mark_read_beyond' => 90, | ||
'mark_read_delete_beyond' => 365, | ||
'mark_read_max_users' => 500, | ||
]; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function isCandidate(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function execute(): bool | ||
{ | ||
$newSettings = []; | ||
|
||
// Copying the current package backup setting. | ||
if (!isset(Config::$modSettings['package_make_full_backups']) && isset(Config::$modSettings['package_make_backups'])) { | ||
$newSettings['package_make_full_backups'] = Config::$modSettings['package_make_backups']; | ||
} | ||
|
||
// Copying the current "allow users to disable word censor" setting. | ||
if (!isset(Config::$modSettings['allow_no_censored'])) { | ||
$request = $this->query('', ' | ||
SELECT value | ||
FROM {db_prefix}themes | ||
WHERE variable={string:allow_no_censored} | ||
AND id_theme = 1 OR id_theme = {int:default_theme}', | ||
[ | ||
'allow_no_censored' => 'allow_no_censored', | ||
'default_theme' => Config::$modSettings['theme_default'] | ||
]); | ||
|
||
// Is it set for either "default" or the one they've set as default? | ||
while ($row = Db::$db->fetch_assoc($request)) | ||
{ | ||
if ($row['value'] == 1) | ||
{ | ||
$newSettings['allow_no_censored'] = 1; | ||
|
||
// Don't do this twice... | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// Add all any settings to the settings table. | ||
foreach ($newSettings as $key => $default) { | ||
if (!isset(Config::$modSettings[$key])) { | ||
$newSettings[$key] = $default; | ||
} | ||
} | ||
|
||
// Enable some settings we ripped from Theme settings. | ||
$ripped_settings = array('show_modify', 'show_user_images', 'show_blurb', 'show_profile_buttons', 'subject_toggle', 'hide_post_group'); | ||
|
||
$request = Db::$db->query('', ' | ||
SELECT variable, value | ||
FROM {db_prefix}themes | ||
WHERE variable IN({array_string:ripped_settings}) | ||
AND id_member = 0 | ||
AND id_theme = 1', | ||
array( | ||
'ripped_settings' => $ripped_settings, | ||
) | ||
); | ||
|
||
$inserts = array(); | ||
while ($row = Db::$db->fetch_assoc($request)) { | ||
if (!isset(Config::$modSettings[$row['variable']])) { | ||
$newSettings[$row['variable']] = $row['value']; | ||
} | ||
} | ||
Db::$db->free_result($request); | ||
|
||
// Calculate appropriate hash cost. | ||
if (!isset(Config::$modSettings['bcrypt_hash_cost'])) { | ||
$newSettings['bcrypt_hash_cost'] = Security::hashBenchmark(); | ||
} | ||
|
||
// Adding new profile data export settings. | ||
if (!isset(Config::$modSettings['export_dir'])) { | ||
$newSettings['export_dir'] = Config::$boarddir . '/exports'; | ||
} | ||
|
||
Config::updateModSettings($newSettings); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/** | ||
* Simple Machines Forum (SMF) | ||
* | ||
* @package SMF | ||
* @author Simple Machines https://www.simplemachines.org | ||
* @copyright 2024 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\Maintenance\Migration\v2_1; | ||
|
||
use SMF\Config; | ||
use SMF\Db\DatabaseApi as Db; | ||
use SMF\Db\Schema\v3_0\MemberLogins; | ||
use SMF\Maintenance; | ||
use SMF\Maintenance\Migration; | ||
use SMF\Db\Schema\v3_0; | ||
|
||
class Migration0001 extends Migration | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public string $name = 'Creating login history table'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function isCandidate(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function execute(): bool | ||
{ | ||
$tables = Db::$db->list_tables(); | ||
|
||
if (!in_array(Config::$db_prefix . 'member_logins', $tables)) { | ||
$member_logins = new MemberLogins(); | ||
$member_logins->create(); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/** | ||
* Simple Machines Forum (SMF) | ||
* | ||
* @package SMF | ||
* @author Simple Machines https://www.simplemachines.org | ||
* @copyright 2024 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\Maintenance\Migration\v2_1; | ||
|
||
use SMF\Config; | ||
use SMF\Db\DatabaseApi as Db; | ||
use SMF\Db\Schema\v3_0\MemberLogins; | ||
use SMF\Maintenance; | ||
use SMF\Maintenance\Migration; | ||
use SMF\Db\Schema\v3_0; | ||
|
||
class Migration0001 extends Migration | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public string $name = 'Converting collapsed categories'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function isCandidate(): bool | ||
{ | ||
$tables = Db::$db->list_tables(); | ||
|
||
return in_array(Config::$db_prefix . 'collapsed_categories', $tables); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function execute(): bool | ||
{ | ||
$request = Db::$db->query('', ' | ||
SELECT id_member, id_cat | ||
FROM {db_prefix}collapsed_categories'); | ||
|
||
$inserts = array(); | ||
while ($row = Db::$db->fetch_assoc($request)) | ||
$inserts[] = array($row['id_member'], 1, 'collapse_category_' . $row['id_cat'], $row['id_cat']); | ||
Db::$db->free_result($request); | ||
|
||
$result = false; | ||
|
||
if (!empty($inserts)) { | ||
$result = Db::$db->insert('replace', | ||
'{db_prefix}themes', | ||
array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string', 'value' => 'string'), | ||
$inserts, | ||
array('id_theme', 'id_member', 'variable') | ||
); | ||
} | ||
|
||
if ($result !== false) { | ||
Db::$db->drop_table('{db_prefix}collapsed_categories'); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/** | ||
* Simple Machines Forum (SMF) | ||
* | ||
* @package SMF | ||
* @author Simple Machines https://www.simplemachines.org | ||
* @copyright 2024 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\Maintenance\Migration\v2_1; | ||
|
||
use SMF\BBCodeParser; | ||
use SMF\Config; | ||
use SMF\Db\DatabaseApi as Db; | ||
use SMF\Db\Schema\v3_0\MemberLogins; | ||
use SMF\Maintenance; | ||
use SMF\Maintenance\Migration; | ||
use SMF\Db\Schema\v3_0; | ||
use SMF\Utils; | ||
|
||
class Migration0001 extends Migration | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public string $name = 'Parsing board descriptions and names'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function isCandidate(): bool | ||
{ | ||
return empty(Config::$modSettings['smfVersion']) || version_compare(trim(strtolower(Config::$modSettings['smfVersion'])), '2.1.foo', '<'); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function execute(): bool | ||
{ | ||
|
||
$request = Db::$db->query('', ' | ||
SELECT name, description, id_board | ||
FROM {db_prefix}boards | ||
WHERE id_board > {int:start}', | ||
[ | ||
'start' => Maintenance::getCurrentStart() | ||
] | ||
); | ||
|
||
while ($row = Db::$db->fetch_assoc($request)) | ||
{ | ||
Db::$db->query('', ' | ||
UPDATE {db_prefix}boards | ||
SET name = {string:name}, description = {string:description} | ||
WHERE id = {int:id}', | ||
[ | ||
'id' => $row['id'], | ||
'name' => Utils::htmlspecialchars(strip_tags(BBCodeParser::load()->unparse($row['name']))), | ||
'description' => Utils::htmlspecialchars(strip_tags(BBCodeParser::load()->unparse($row['description']))), | ||
]); | ||
|
||
Maintenance::setCurrentStart(); | ||
$this->handleTimeout(); | ||
} | ||
Db::$db->free_result($request); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
?> |
Oops, something went wrong.