3 // Copyright (C) 2008-2010 Rod Roark <rod@sunsetsystems.com>
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This may be run after an upgraded OpenEMR has been installed.
11 // Its purpose is to upgrade the MySQL OpenEMR database as needed
12 // for the new release.
14 // Checks if the server's PHP version is compatible with OpenEMR:
15 require_once(dirname(__FILE__
) . "/src/Common/Compatibility/Checker.php");
16 $response = OpenEMR\Common\Compatibility\Checker
::checkPhpVersion();
17 if ($response !== true) {
18 die(htmlspecialchars($response));
21 // Disable PHP timeout. This will not work in safe mode.
22 ini_set('max_execution_time', '0');
24 $ignoreAuth = true; // no login required
26 require_once('interface/globals.php');
27 require_once('library/sql_upgrade_fx.php');
30 use OpenEMR\Core\Header
;
31 use OpenEMR\Services\VersionService
;
33 $versionService = new VersionService();
35 // Fetching current version because it was updated by the sql_upgrade_fx
36 // script and this script will further modify it.
37 $currentVersion = $versionService->fetch();
39 $desiredVersion = $currentVersion;
40 $desiredVersion->setDatabase($v_database);
41 $desiredVersion->setTag($v_tag);
42 $desiredVersion->setRealPatch($v_realpatch);
43 $desiredVersion->setPatch($v_patch);
44 $desiredVersion->setMinor($v_minor);
45 $desiredVersion->setMajor($v_major);
48 $GLOBALS["enable_auditlog"] = 0;
51 $sqldir = "$webserver_root/sql";
52 $dh = opendir($sqldir);
54 die("Cannot read $sqldir");
57 while (false !== ($sfname = readdir($dh))) {
58 if (substr($sfname, 0, 1) == '.') {
62 if (preg_match('/^(\d+)_(\d+)_(\d+)-to-\d+_\d+_\d+_upgrade.sql$/', $sfname, $matches)) {
63 $version = $matches[1] . '.' . $matches[2] . '.' . $matches[3];
64 $versions[$version] = $sfname;
73 <title
>OpenEMR Database Upgrade
</title
>
74 <?php Header
::setupHeader(); ?
>
75 <link rel
="shortcut icon" href
="public/images/favicon.ico" />
78 <div
class="container mt-3">
81 <h2
>OpenEMR Database Upgrade
</h2
>
84 <div
class="jumbotron p-4">
85 <form
class="form-inline" method
='post' action
='sql_upgrade.php'>
86 <div
class="form-group mb-3">
87 <label
>Please select the prior release you are converting from
:</label
>
88 <select
class='ml-3 form-control' name
='form_old_version'>
90 foreach ($versions as $version => $filename) {
91 echo " <option value='$version'";
92 // Defaulting to most recent version, which is now 5.0.2.
93 if ($version === '5.0.2') {
96 echo ">$version</option>\n";
101 <p
>If you are unsure
or were using a development version between two
102 releases
, then choose the older of possible releases
.</p
>
103 <p
class="text-danger">If you are upgrading from a version below
5.0.0 to version
5.0.0 or greater
, do note that this upgrade can take anywhere from several minutes to several
hours (you will only see a whitescreen until it is complete
; do not stop the script before it is complete
or you risk corrupting your data
).</p
>
104 <button type
='submit' class='btn btn-primary btn-transmit' name
='form_submit' value
='Upgrade Database'>Upgrade Database
</button
>
109 if (!empty($_POST['form_submit'])) {
110 echo '<div class="jumbotron p-4">';
111 $form_old_version = $_POST['form_old_version'];
113 foreach ($versions as $version => $filename) {
114 if (strcmp($version, $form_old_version) < 0) {
118 upgradeFromSqlFile($filename);
121 if (!empty($GLOBALS['ippf_specific'])) {
122 // Upgrade custom stuff for IPPF.
123 upgradeFromSqlFile('ippf_upgrade.sql');
126 if ((!empty($v_realpatch)) && ($v_realpatch != "") && ($v_realpatch > 0)) {
127 // This release contains a patch file, so process it.
128 upgradeFromSqlFile('patch.sql');
133 echo "<p class='text-success'>Updating global configuration defaults...</p><br />\n";
134 $skipGlobalEvent = true; //use in globals.inc.php script to skip event stuff
135 require_once("library/globals.inc.php");
136 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
137 foreach ($grparr as $fldid => $fldarr) {
138 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
139 if (is_array($fldtype) ||
(substr($fldtype, 0, 2) !== 'm_')) {
140 $row = sqlQuery("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
141 if (empty($row['count'])) {
142 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
143 "VALUES ( '$fldid', '0', '$flddef' )");
149 echo "<p class='text-success'>Updating Access Controls...</p><br />\n";
150 require("acl_upgrade.php");
153 $canRealPatchBeApplied = $versionService->canRealPatchBeApplied($desiredVersion);
154 $line = "Updating version indicators";
156 if ($canRealPatchBeApplied) {
157 $line = $line . ". Patch was also installed, updating version patch indicator";
160 echo "<p class='text-success'>" . $line . "...</p><br />\n";
161 $result = $versionService->update($desiredVersion);
164 echo "<p class='text-danger'>Version could not be updated</p><br />\n";
168 echo "<p><p class='text-success'>Database and Access Control upgrade finished.</p></p>\n";
169 echo "</div></body></html>\n";