Skip to content

Commit e44dfdf

Browse files
authored
fix(upgrade): skip stale patch directories and fix System module update URL (#17)
* fix(upgrade): skip stale patch directories and fix System module update URL Wrap patch file includes in buildUpgradeQueue() with try/catch so that stale directories from previous beta versions (e.g. upd_2.5.11-to-2.5.12 from the pre-rename cycle) are logged and skipped instead of crashing the upgrade with a fatal "Class not found" error. Also fix double-encoding of the System module update URL at the end of the upgrade wizard — & in the PHP string was re-encoded by htmlspecialchars() in oneButtonContinueForm(), producing & which broke the query parameters. * fix(upgrade): emit visible warnings for skipped patches and guard Db_manager loads Replace the undeclared $this->logs[] write in UpgradeControl::buildUpgradeQueue() with trigger_error(E_USER_WARNING) so that skipped patches produce a visible warning in the PHP error output instead of writing to a property that does not exist on the class. Also wrap the two method-level require_once calls for dbmanager.php inside upd-2.4.x-to-2.5.0 with class_exists('Db_manager', false) guards, matching the top-level guard, to prevent a fatal class redeclaration when the class was already loaded by an earlier patch in the upgrade queue.
1 parent 69422cc commit e44dfdf

4 files changed

Lines changed: 37 additions & 12 deletions

File tree

upgrade/class/Xoops/Upgrade/UpgradeControl.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,24 @@ public function buildUpgradeQueue(): bool
228228

229229
foreach ($dirs as $dir) {
230230
if (str_contains($dir, '-to-')) {
231-
$className = include $upgradeRoot . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . 'index.php';
231+
$patchFile = $upgradeRoot . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . 'index.php';
232+
if (!file_exists($patchFile)) {
233+
continue;
234+
}
235+
try {
236+
$className = include $patchFile;
237+
} catch (\Throwable $e) {
238+
// Stale directories from a previous version (e.g.
239+
// upd_2.5.11-to-2.5.12 from the pre-rename beta cycle) can
240+
// fail to load because they reference classes that no longer
241+
// exist. Emit a visible warning and skip — crashing the
242+
// entire upgrade is worse than skipping one broken patch.
243+
trigger_error(
244+
sprintf('Upgrade patch %s could not be loaded: %s', $dir, $e->getMessage()),
245+
E_USER_WARNING
246+
);
247+
continue;
248+
}
232249
if (is_string($className) && class_exists($className)) {
233250
$upg = $this->createPatch($className);
234251
$results[$dir] = $upg->isApplied();

upgrade/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
}
125125
if (0 === $upgradeControl->countUpgradeQueue()) {
126126
echo $upgradeControl->oneButtonContinueForm(
127-
XOOPS_URL . '/modules/system/admin.php?fct=modulesadmin&op=update&module=system',
127+
XOOPS_URL . '/modules/system/admin.php?fct=modulesadmin&op=update&module=system',
128128
[],
129129
);
130130
} else {

upgrade/upd-2.4.x-to-2.5.0/index.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
use Xoops\Upgrade\XoopsUpgrade;
1313
use Xoops\Upgrade\UpgradeControl;
1414

15-
require_once __DIR__ . '/dbmanager.php';
15+
if (!class_exists('Db_manager', false)) {
16+
require_once __DIR__ . '/dbmanager.php';
17+
}
1618

1719
/**
1820
* Upgrade from 2.4.x to 2.5.0
@@ -79,11 +81,13 @@ public function check_templates(): bool
7981
*/
8082
public function apply_config(): bool
8183
{
82-
if (!file_exists($this->dbmanagerFile)) {
83-
$this->logs[] = 'Database manager file not found: ' . $this->dbmanagerFile;
84-
return false;
84+
if (!class_exists('Db_manager', false)) {
85+
if (!file_exists($this->dbmanagerFile)) {
86+
$this->logs[] = 'Database manager file not found: ' . $this->dbmanagerFile;
87+
return false;
88+
}
89+
require_once $this->dbmanagerFile;
8590
}
86-
require_once $this->dbmanagerFile;
8791
$dbm = new Db_manager();
8892

8993
$sql = 'SELECT conf_id FROM `' . $this->db->prefix('config') . "` WHERE `conf_name` IN ('cpanel')";
@@ -197,11 +201,13 @@ public function apply_templates(): bool
197201
return false;
198202
}
199203

200-
if (!file_exists($this->dbmanagerFile)) {
201-
$this->logs[] = 'Database manager file not found: ' . $this->dbmanagerFile;
202-
return false;
204+
if (!class_exists('Db_manager', false)) {
205+
if (!file_exists($this->dbmanagerFile)) {
206+
$this->logs[] = 'Database manager file not found: ' . $this->dbmanagerFile;
207+
return false;
208+
}
209+
require_once $this->dbmanagerFile;
203210
}
204-
require_once $this->dbmanagerFile;
205211
$dbm = new Db_manager();
206212
$time = time();
207213
foreach ($modversion['templates'] as $tplfile) {

upgrade/upd_2.5.10-to-2.5.11/index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010
*/
1111

12-
require_once XOOPS_ROOT_PATH . '/install/class/dbmanager.php';
12+
if (!class_exists('Db_manager', false)) {
13+
require_once XOOPS_ROOT_PATH . '/install/class/dbmanager.php';
14+
}
1315

1416
use Xmf\Database\Tables;
1517
use Xoops\Upgrade\XoopsUpgrade;

0 commit comments

Comments
 (0)