Creating upgrade manager for Openemr

Hi,

I think it is long overdue for Openemr to create upgrade manager for Openemr so it is user friendly and easier for everyone to upgrade or update Openemr from old version to new version. At present, we have to copy the files on sites and default.php and then remove old version and then copy new version into it which is very tedious and easy to make mistake.

Here is the code suggestions created by Chatgpt for upgrade manager:

:warning: Important Notes (Read First)

  • OpenEMR upgrades affect database schema, files, and configuration

  • Always backup database & files before upgrading

  • This example:

    • Checks current version

    • Fetches available versions

    • Downloads upgrade package

    • Runs pre-checks

    • Executes upgrade scripts

  • You should restrict access to admins only

:file_folder: Directory Structure

openemr/
└── interface/
└── upgrade_manager/
├── index.php
├── api.php
├── upgrade.php
├── styles.css
├── script.js
└── upgrades/
└── 7.0.2.sql

:one: index.php (UI Entry Point)

<?php require_once("../../globals.php"); if (!isset($_SESSION['authUser']) || $_SESSION['authUser'] != 'admin') { die("Access denied"); } ?> OpenEMR Upgrade Manager

OpenEMR Upgrade Manager

<div class="status">
    <p>Current Version: <span id="currentVersion">Loading...</span></p>
    <p>Latest Version: <span id="latestVersion">Checking...</span></p>
</div>

<button id="checkBtn">Check for Updates</button>
<button id="upgradeBtn" disabled>Upgrade</button>

<pre id="log"></pre>

:two: styles.css

body {
font-family: Arial, sans-serif;
background: #f4f6f8;
}

.container {
max-width: 600px;
margin: 50px auto;
background: #fff;
padding: 20px;
border-radius: 6px;
}

button {
padding: 10px 15px;
margin-right: 10px;
}

.status p {
font-weight: bold;
}

#log {
background: #111;
color: #0f0;
padding: 10px;
height: 200px;
overflow-y: auto;
}

:three: script.js

const log = msg => {
const el = document.getElementById(“log”);
el.textContent += msg + “\n”;
el.scrollTop = el.scrollHeight;
};

document.getElementById(“checkBtn”).onclick = async () => {
log(“Checking versions…”);
const res = await fetch(“api.php?action=check”);
const data = await res.json();

document.getElementById("currentVersion").textContent = data.current;
document.getElementById("latestVersion").textContent = data.latest;

if (data.current !== data.latest) {
    document.getElementById("upgradeBtn").disabled = false;
    log("Upgrade available");
} else {
    log("System is up to date");
}

};

document.getElementById(“upgradeBtn”).onclick = async () => {
if (!confirm(“Backup database and files before proceeding. Continue?”)) return;

log("Starting upgrade...");
const res = await fetch("upgrade.php");
const text = await res.text();
log(text);

};

:four: api.php (Version Check API)

<?php require_once("../../globals.php"); if ($_GET['action'] === 'check') { $current = $GLOBALS['v_realpatch']; // OpenEMR version // Normally fetched from OpenEMR GitHub / API $latest = "7.0.2"; echo json_encode([ "current" => $current, "latest" => $latest ]); } 5️⃣ `upgrade.php` (Upgrade Execution) <?php require_once("../../globals.php"); require_once("$srcdir/sql.inc.php"); echo "Running pre-checks...\n"; // Example: DB connection check if (!$GLOBALS['dbh']) { die("Database connection failed\n"); } echo "Applying database upgrades...\n"; // Example SQL upgrade $sqlFile = __DIR__ . "/upgrades/7.0.2.sql"; if (file_exists($sqlFile)) { $sql = file_get_contents($sqlFile); sqlStatement($sql); echo "Database updated\n"; } else { echo "No DB changes\n"; } echo "Updating version number...\n"; sqlStatement("UPDATE version SET v_realpatch='7.0.2'"); echo "Upgrade completed successfully\n"; 6️⃣ Sample SQL Upgrade (`upgrades/7.0.2.sql`) ALTER TABLE users ADD COLUMN last_upgrade DATETIME; # 🔒 Security Recommendations ✔ Restrict to admin users ✔ CSRF protection ✔ File permissions check ✔ Mandatory backup confirmation ✔ Log all upgrade actions

It is not wise to use ChatGPT or any AI tool to create something this complex. Upgrading is not as straight forward as it seems. If there are any modifications to the original code. An automated upgrade is off the table altogether.

The sqlupgrade.php is only for the database. The code is replaced entirely when doing an upgrade with no changes to the code. But there is a consideration of the key in the database and the file keys having to match. So, the sites folder from the previous version needs to be managed in order to bring in all of the patients’ files.

You have not presented a clear outline of how all of this can be accounted for and automated.