Commit 151d08a
committed
fix(flex): use sql_upgrade.php CLI mode in upgradeOpenEMR
The previous implementation rewrote sql_upgrade.php with sed to inject the
source version. After openemr/openemr#11906 added native CLI support, the
target sed pattern (`$form_old_version = $_POST['form_old_version'];`) no
longer exists in sql_upgrade.php — the assignment is now
`$form_old_version = $cliFromVersion ?? ($_POST['form_old_version'] ?? '')`.
The sed becomes a silent no-op, leaving `$form_old_version = ''`. The loop
guard `strcmp($version, '') < 0` is then false for every upgrade file, so
sql_upgrade.php starts processing from `2_6_0-to-2_6_1_upgrade.sql` instead
of the requested 5.0.0. That file contains an unguarded
`INSERT INTO categories_seq VALUES (0)` which adds a second row alongside
the demo dump's `(26)`. Several files later,
`5_0_0-to-5_0_1_upgrade.sql:407` runs
`UPDATE categories_seq SET id = (SELECT MAX(id) FROM categories)` without a
WHERE clause; with two rows being set to the same id, the second hits a
PRIMARY KEY violation and the upgrade aborts. The database is left at
v5.0.0 with only the earliest upgrade scripts partially applied — visible
to users as broken login CSS, missing columns
(`lists_medication.reporting_source_record_id`), and erroring background
services after `openemr-cmd drid`.
Switch to the supported `--from=VERSION` CLI argument, which is honored by
the loop guard at `sql_upgrade.php:379`
(`!empty($_POST['form_submit']) || $cliFromVersion !== null`) and removes
the need to mutate the script source.
Validated end-to-end: `openemr-cmd drid` now leaves the database at
v8.1.1-dev / v_database=538, with `categories_seq` containing the expected
single row and `lists_medication.reporting_source_record_id` present.
Assisted-by: Claude Code1 parent 28e8caf commit 151d08a
1 file changed
Lines changed: 2 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
211 | | - | |
| 210 | + | |
212 | 211 | | |
213 | 212 | | |
214 | 213 | | |
215 | 214 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | 215 | | |
224 | 216 | | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
| 217 | + | |
230 | 218 | | |
231 | 219 | | |
232 | 220 | | |
| |||
0 commit comments