2 // Copyright (C) 2008-2010 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This may be run after an upgraded OpenEMR has been installed.
10 // Its purpose is to upgrade the MySQL OpenEMR database as needed
11 // for the new release.
13 // Checks if the server's PHP version is compatible with OpenEMR:
14 require_once(dirname(__FILE__
) . "/src/Common/Compatibility/Checker.php");
15 $response = OpenEMR\Common\Compatibility\Checker
::checkPhpVersion();
16 if ($response !== true) {
17 die(htmlspecialchars($response));
20 // Disable PHP timeout. This will not work in safe mode.
21 ini_set('max_execution_time', '0');
23 $ignoreAuth = true; // no login required
25 require_once('interface/globals.php');
26 require_once('library/sql_upgrade_fx.php');
28 use OpenEMR\Services\VersionService
;
30 $versionService = new VersionService();
32 // Fetching current version because it was updated by the sql_upgrade_fx
33 // script and this script will further modify it.
34 $currentVersion = $versionService->fetch();
36 $desiredVersion = $currentVersion;
37 $desiredVersion->setDatabase($v_database);
38 $desiredVersion->setTag($v_tag);
39 $desiredVersion->setRealPatch($v_realpatch);
40 $desiredVersion->setPatch($v_patch);
41 $desiredVersion->setMinor($v_minor);
42 $desiredVersion->setMajor($v_major);
45 $GLOBALS["enable_auditlog"]=0;
48 $sqldir = "$webserver_root/sql";
49 $dh = opendir($sqldir);
51 die("Cannot read $sqldir");
54 while (false !== ($sfname = readdir($dh))) {
55 if (substr($sfname, 0, 1) == '.') {
59 if (preg_match('/^(\d+)_(\d+)_(\d+)-to-\d+_\d+_\d+_upgrade.sql$/', $sfname, $matches)) {
60 $version = $matches[1] . '.' . $matches[2] . '.' . $matches[3];
61 $versions[$version] = $sfname;
70 <title
>OpenEMR Database Upgrade
</title
>
71 <link rel
='STYLESHEET' href
='interface/themes/style_blue.css'>
72 <link rel
="shortcut icon" href
="public/images/favicon.ico" />
76 <span
class='title'>OpenEMR Database Upgrade
</span
>
80 if (!empty($_POST['form_submit'])) {
81 $form_old_version = $_POST['form_old_version'];
83 foreach ($versions as $version => $filename) {
84 if (strcmp($version, $form_old_version) < 0) {
88 upgradeFromSqlFile($filename);
91 if (!empty($GLOBALS['ippf_specific'])) {
92 // Upgrade custom stuff for IPPF.
93 upgradeFromSqlFile('ippf_upgrade.sql');
96 if ((!empty($v_realpatch)) && ($v_realpatch != "") && ($v_realpatch > 0)) {
97 // This release contains a patch file, so process it.
98 upgradeFromSqlFile('patch.sql');
103 echo "<font color='green'>Updating global configuration defaults...</font><br />\n";
104 $skipGlobalEvent = true; //use in globals.inc.php script to skip event stuff
105 require_once("library/globals.inc.php");
106 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
107 foreach ($grparr as $fldid => $fldarr) {
108 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
109 if (is_array($fldtype) ||
(substr($fldtype, 0, 2) !== 'm_')) {
110 $row = sqlQuery("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
111 if (empty($row['count'])) {
112 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
113 "VALUES ( '$fldid', '0', '$flddef' )");
119 echo "<font color='green'>Updating Access Controls...</font><br />\n";
120 require("acl_upgrade.php");
123 $canRealPatchBeApplied = $versionService->canRealPatchBeApplied($desiredVersion);
124 $line = "Updating version indicators";
126 if ($canRealPatchBeApplied) {
127 $line = $line . ". Patch was also installed, updating version patch indicator";
130 echo "<font color='green'>" . $line . "...</font><br />\n";
131 $result = $versionService->update($desiredVersion);
134 echo "<font color='red'>Version could not be updated</font><br />\n";
138 echo "<p><font color='green'>Database and Access Control upgrade finished.</font></p>\n";
139 echo "</body></html>\n";
145 <form method
='post' action
='sql_upgrade.php'>
146 <p
>Please select the prior release you are converting from
:
147 <select name
='form_old_version'>
149 foreach ($versions as $version => $filename) {
150 echo " <option value='$version'";
151 // Defaulting to most recent version, which is now 5.0.2.
152 if ($version === '5.0.2') {
156 echo ">$version</option>\n";
161 <p
>If you are unsure
or were using a development version between two
162 releases
, then choose the older of possible releases
.</p
>
163 <p style
="color:red">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
>
164 <p
><input type
='submit' name
='form_submit' value
='Upgrade Database' /></p
>