From d9139c427f30bdb00be4d823a33f7b0f0dc6f85e Mon Sep 17 00:00:00 2001 From: Leonard Jonathan Oh Date: Mon, 30 Oct 2023 16:39:01 +0000 Subject: [PATCH] Enhancement (admin): Add DB Updater tool in Admin Panel to upgrade DB This tools checks `./web/updater` for a `.php` file with a higher version than the DB's version. If such a file is present, it offers an upgrade. Benefits: - One click to upgrade the DB - No need to remove the `./updater` tool after upgrading (compatible with docker immutability) --- web/pages/admin.php | 19 +++++++++++++++++++ web/pages/updater.php | 7 +++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/web/pages/admin.php b/web/pages/admin.php index 00e79ed8..1a771b85 100644 --- a/web/pages/admin.php +++ b/web/pages/admin.php @@ -1012,6 +1012,24 @@ function message($icon, $msg) + Current Version: {$g_options['version']}
+ Current DB version: {$g_options['dbversion']}
"; +if (file_exists('./updater') && $mode != 'updater') { + if (file_exists("./updater/" . ($g_options['dbversion'] + 1) . ".php")) { + $updateDbHtml .= " +
+
+ \"Warning\" Warning: Your database needs an upgrade. To perform a Database Update, please go to the Updater page. +
HLX:CE Database Updater
+ +
"; + } else { + $updateDbHtml .= "Great. Your database is the latest version."; + } +} +$updateDbHtml .= "
"; + // General Settings $admintasks['options'] = new AdminTask('HLstatsX:CE Settings', 80); $admintasks['adminusers'] = new AdminTask('Admin Users', 100); @@ -1036,6 +1054,7 @@ function message($icon, $msg) $admintasks['ribbons'] = new AdminTask('Ribbons (triggered by Awards)', 80, 'game'); // Tools +$admintasks['tools_updater'] = new AdminTask('DB Updater', 100, 'tool', $updateDbHtml); $admintasks['tools_perlcontrol'] = new AdminTask('HLstatsX: CE Daemon Control', 80, 'tool', 'Reload or stop your HLX: CE Daemons'); $admintasks['tools_editdetails'] = new AdminTask('Edit Player or Clan Details', 80, 'tool', 'Edit a player or clan\'s profile information.'); $admintasks['tools_adminevents'] = new AdminTask('Admin-Event History', 80, 'tool', 'View event history of logged Rcon commands and Admin Mod messages.'); diff --git a/web/pages/updater.php b/web/pages/updater.php index af965cec..1f381d9b 100644 --- a/web/pages/updater.php +++ b/web/pages/updater.php @@ -55,5 +55,8 @@ } } - echo "

\"Warning\" You must delete the \"updater\" folder from your web site before your site will be operational.\n\n"; -?> \ No newline at end of file + // In docker, the updater folder will always be present, to allow + // DB upgrades to be done using this updater. Hence, this code is + // commented out to allow things to work correctly after the DB upgrade in docker. + // echo "

\"Warning\" You must delete the \"updater\" folder from your web site before your site will be operational.\n\n"; +?>