Skip to content

Commit 9caea1c

Browse files
Rewrites upgrader
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
1 parent 5727046 commit 9caea1c

File tree

122 files changed

+16685
-5976
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+16685
-5976
lines changed

Languages/en_US/Maintenance.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
$txt['upgrade_step_migration'] = 'Migrations';
9292
$txt['upgrade_step_convertutf'] = 'Convert to UTF-8';
9393
$txt['upgrade_step_cleanup'] = 'Cleanup';
94-
$txt['upgrade_step_delete'] = 'Finalize Upgrade';
94+
$txt['upgrade_step_finalize'] = 'Finalize Upgrade';
9595

9696
// Installer - Welcome.
9797
$txt['install_welcome'] = 'Welcome';
@@ -295,14 +295,21 @@
295295
// Upgrade - steps and substeps
296296
$txt['upgrade_steps'] = 'Steps';
297297
$txt['upgrade_substeps'] = 'Substeps';
298-
$txt['upgrade_db_changes'] = 'Executing database changes';
299-
$txt['upgrade_db_patient'] = 'Please be patient - this may take some time on large forums. The time elapsed increments from the server to show progress is being made.';
298+
$txt['upgrade_executing_substeps'] = 'Executing {type, select,
299+
migration {database changes}
300+
cleanup {cleanup steps}
301+
other {substeps}
302+
}';
303+
$txt['upgrade_please_be_patient'] = 'Please be patient - this may take some time on large forums. The time elapsed increments from the server to show progress is being made.';
300304
$txt['upgrade_current_step'] = 'Current Step:';
301-
$txt['upgrade_current_substep'] = 'Current Migration:';
302-
$txt['upgrade_completed'] = 'Completed';
303-
$txt['upgrade_outof'] = 'out of';
304-
$txt['upgrade_db_complete'] = 'Database update complete! Click Continue to proceed.';
305-
$txt['upgrade_completed_migration'] = ' Completed Migration:';
305+
$txt['upgrade_current_substep'] = 'Current Substep: {substep}';
306+
$txt['upgrade_substep_progress'] = 'Completed {substep_done} out of {total_substeps} {type, select,
307+
migration {database changes}
308+
cleanup {cleanup steps}
309+
other {substeps}
310+
}.';
311+
$txt['upgrade_completed_substep'] = ' Completed Substep:';
312+
$txt['upgrade_step_complete'] = 'The "{step}" step is complete! Click Continue to proceed.';
306313

307314

308315

@@ -414,9 +421,10 @@
414421
$txt['upgrade_continue_step'] = 'Continue from step reached during last execution of upgrade script.';
415422
$txt['upgrade_bypass'] = '<strong>Note:</strong> If necessary, the above security check can be bypassed for users who may administrate a server, but may not have admin rights on the forum. In order to bypass the above check, simply open &quot;upgrade.php&quot; in a text editor and replace &quot;$disable_security = false;&quot; with &quot;$disable_security = true;&quot; and refresh this page.';
416423
$txt['upgrade_areyouready'] = 'Before the upgrade gets underway, please review the options below and press &quot;Continue&quot; when you are ready to begin.';
417-
$txt['upgrade_backup_table'] = 'Perform a tables backup in your database with the prefix';
424+
$txt['upgrade_backup_table'] = 'Backup SMF tables in your database using the prefix <span class="bbc_tt">{0}</span>';
418425
$txt['upgrade_backup_complete'] = 'Backup Complete! Click Continue to Proceed.';
419-
$txt['upgrade_recommended'] = 'recommended!';
426+
$txt['upgrade_recommended'] = 'Strongly recommended!';
427+
$txt['upgrade_backup_already_exists'] = 'Backup already exists. If you enable this option, the existing backup will be replaced with a new one.';
420428
$txt['upgrade_maintenance'] = 'Put the forum into maintenance mode during upgrade.';
421429
$txt['upgrade_maintenance_title'] = 'Maintenance Title:';
422430
$txt['upgrade_maintenance_message'] = 'Maintenance Message:';
@@ -474,7 +482,7 @@
474482
$txt['upgrade_incorrect_settings'] = 'If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
475483

476484
$txt['upgrade_fulltext_error'] = 'Your fulltext search index was dropped to facilitate the conversion. You will need to recreate it.';
477-
$txt['upgrade_writable_files'] = 'The following files need to be writable to continue the upgrade. Please ensure the Windows permissions are correctly set to allow this:';
485+
$txt['upgrade_writable_files'] = 'The following files need to be writable to continue the upgrade. Please ensure the file permissions are correctly set to allow this:';
478486
$txt['upgrade_time_user'] = '&quot;{name}&quot; is running the upgrade script.';
479487

480488
$txt['upgrade_completed_time_hms'] = 'Upgrade completed in {h, plural,
@@ -547,3 +555,5 @@
547555
$txt['upgrade_complete'] = 'Upgrade Complete';
548556
$txt['converting_utf8'] = 'Converting to UTF-8';
549557
$txt['converting_json'] = 'Converting to JSON';
558+
559+
$txt['converting_table_to_utf8mb4'] = 'Converting table {0} to utf8mb4';
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/**
4+
* Simple Machines Forum (SMF)
5+
*
6+
* @package SMF
7+
* @author Simple Machines https://www.simplemachines.org
8+
* @copyright 2024 Simple Machines and individual contributors
9+
* @license https://www.simplemachines.org/about/smf/license.php BSD
10+
*
11+
* @version 3.0 Alpha 3
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace SMF\Maintenance\Cleanup;
17+
18+
use SMF\Maintenance\SubStepInterface;
19+
20+
/**
21+
* Base class for cleanup tasks.
22+
*/
23+
abstract class CleanupBase implements SubStepInterface
24+
{
25+
/*******************
26+
* Public properties
27+
*******************/
28+
29+
/**
30+
* @var string
31+
*
32+
* Name of the cleanup task.
33+
*/
34+
public string $name;
35+
36+
/****************
37+
* Public methods
38+
****************/
39+
40+
/**
41+
* Check if the task should be performed or not.
42+
*
43+
* @return bool True if this task needs to be run, false otherwise.
44+
*/
45+
public function isCandidate(): bool
46+
{
47+
return true;
48+
}
49+
50+
/**
51+
*
52+
*/
53+
public function execute(): bool
54+
{
55+
return true;
56+
}
57+
}

Sources/Maintenance/Cleanup/index.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
// Try to handle it with the upper level index.php. (it should know what to do.)
4+
if (file_exists(dirname(__DIR__) . '/index.php')) {
5+
include dirname(__DIR__) . '/index.php';
6+
} else {
7+
exit;
8+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/**
4+
* Simple Machines Forum (SMF)
5+
*
6+
* @package SMF
7+
* @author Simple Machines https://www.simplemachines.org
8+
* @copyright 2024 Simple Machines and individual contributors
9+
* @license https://www.simplemachines.org/about/smf/license.php BSD
10+
*
11+
* @version 3.0 Alpha 3
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace SMF\Maintenance\Cleanup\v2_1;
17+
18+
use SMF\Maintenance\Cleanup\v3_0\OldFiles as OldFilesBase;
19+
20+
/**
21+
* Just like the v3_0 version of OldFiles, but with a different list of files.
22+
*/
23+
class OldFiles extends OldFilesBase
24+
{
25+
/*********************
26+
* Internal properties
27+
*********************/
28+
29+
/**
30+
* @var array
31+
*
32+
* List of files removed in SMF 2.1 (and earlier).
33+
*/
34+
protected array $removed = [
35+
// Files in the Themes directory.
36+
'themedir' => [
37+
// Removed in 2.1.
38+
'core',
39+
// Removed in 1.1.
40+
'default/Combat.template.php',
41+
'default/Modlog.template.php',
42+
'default/fader.js',
43+
'default/script.js',
44+
'default/spellcheck.js',
45+
'default/xml_board.js',
46+
'default/xml_topic.js',
47+
],
48+
// Files in the Sources directory.
49+
'sourcedir' => [
50+
// Removed in 2.1.
51+
'DumpDatabase.php',
52+
'LockTopic.php',
53+
// Removed in 2.0.
54+
'ModSettings.php',
55+
],
56+
// Files in the Smileys directory.
57+
'smileysdir' => [],
58+
// Files in the avatars directory.
59+
'avatardir' => [],
60+
// Files in the forum's root directory.
61+
'boarddir' => [],
62+
];
63+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
// Try to handle it with the upper level index.php. (it should know what to do.)
4+
if (file_exists(dirname(__DIR__) . '/index.php')) {
5+
include dirname(__DIR__) . '/index.php';
6+
} else {
7+
exit;
8+
}
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<?php
2+
3+
/**
4+
* Simple Machines Forum (SMF)
5+
*
6+
* @package SMF
7+
* @author Simple Machines https://www.simplemachines.org
8+
* @copyright 2024 Simple Machines and individual contributors
9+
* @license https://www.simplemachines.org/about/smf/license.php BSD
10+
*
11+
* @version 3.0 Alpha 3
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace SMF\Maintenance\Cleanup\v3_0;
17+
18+
use SMF\Config;
19+
use SMF\Maintenance\Cleanup\CleanupBase;
20+
use SMF\Utils;
21+
22+
class OldFiles extends CleanupBase
23+
{
24+
/*******************
25+
* Public properties
26+
*******************/
27+
28+
/**
29+
*
30+
*/
31+
public string $name = 'Cleanup old files';
32+
33+
/*********************
34+
* Internal properties
35+
*********************/
36+
37+
/**
38+
* @var array
39+
*
40+
* List of files removed in SMF 3.0.
41+
*/
42+
protected array $removed = [
43+
// Files in the Themes directory.
44+
'themedir' => [],
45+
// Files in the Sources directory.
46+
'sourcedir' => [],
47+
// Files in the Smileys directory.
48+
'smileysdir' => [],
49+
// Files in the avatars directory.
50+
'avatardir' => [],
51+
// Files in the forum's root directory.
52+
'boarddir' => [],
53+
];
54+
55+
/****************
56+
* Public methods
57+
****************/
58+
59+
/**
60+
* Check if the task should be performed or not.
61+
*
62+
* @return bool True if this task needs to be run, false otherwise.
63+
*/
64+
public function isCandidate(): bool
65+
{
66+
foreach ($this->removed as $dir => $files) {
67+
foreach ($files as $file) {
68+
if (is_file($this->getDirPath($dir) . '/' . $file)) {
69+
return true;
70+
}
71+
}
72+
}
73+
74+
return false;
75+
}
76+
77+
/**
78+
*
79+
*/
80+
public function execute(): bool
81+
{
82+
$success = true;
83+
84+
foreach ($this->removed as $dir => $files) {
85+
foreach ($files as $file) {
86+
if (!is_file($this->getDirPath($dir) . '/' . $file)) {
87+
continue;
88+
}
89+
90+
if (!$this->deletePath($this->getDirPath($dir) . '/' . $file)) {
91+
$success = false;
92+
}
93+
}
94+
}
95+
96+
return $success;
97+
}
98+
99+
/******************
100+
* Internal methods
101+
******************/
102+
103+
/**
104+
* Gets the correct directory path for a key in $this->removed.
105+
*
106+
* @param string $dir A key from $this->removed.
107+
* @throws \Exception if $dir is unrecognized.
108+
* @return string A directory path.
109+
*/
110+
protected function getDirPath(string $dir): string
111+
{
112+
switch ($dir) {
113+
case 'sourcedir':
114+
return Config::$sourcedir;
115+
116+
case 'themedir':
117+
return Config::$boarddir . '/Themes';
118+
119+
case 'smileysdir':
120+
return Config::$boarddir . '/Smileys';
121+
122+
case 'avatardir':
123+
return Config::$boarddir . '/avatars';
124+
125+
case 'boarddir':
126+
return Config::$boarddir;
127+
128+
default:
129+
throw new \Exception();
130+
}
131+
}
132+
133+
/**
134+
* Deletes a file or directory.
135+
*
136+
* Checks permissions first, just in case.
137+
*
138+
* @param string Path to a file or directory
139+
*/
140+
protected function deletePath(string $path): bool
141+
{
142+
if (!file_exists($path)) {
143+
return true;
144+
}
145+
146+
if (!Utils::makeWritable($path)) {
147+
return false;
148+
}
149+
150+
if (!is_dir($path)) {
151+
@unlink($pathname);
152+
} else {
153+
$dir = new \DirectoryIterator($path);
154+
155+
$to_delete = [];
156+
157+
foreach ($dir as $fileinfo) {
158+
if (!$fileinfo->isDot()) {
159+
$this->deletePath($fileinfo->getPathname());
160+
}
161+
}
162+
163+
@rmdir($path);
164+
}
165+
166+
return !file_exists($file);
167+
}
168+
}

0 commit comments

Comments
 (0)