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__
) . "/common/compatibility/Checker.php");
16 $response = OpenEMR\Checker
::checkPhpVersion();
17 if ($response !== true) {
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');
29 $versionService = new \services\
VersionService();
31 // Fetching current version because it was updated by the sql_upgrade_fx
32 // script and this script will further modify it.
33 $currentVersion = $versionService->fetch();
35 $desiredVersion = $currentVersion;
36 $desiredVersion->setDatabase($v_database);
37 $desiredVersion->setTag($v_tag);
38 $desiredVersion->setRealPatch($v_realpatch);
39 $desiredVersion->setPatch($v_patch);
40 $desiredVersion->setMinor($v_minor);
41 $desiredVersion->setMajor($v_major);
44 $GLOBALS["enable_auditlog"]=0;
47 $sqldir = "$webserver_root/sql";
48 $dh = opendir($sqldir);
50 die("Cannot read $sqldir");
53 while (false !== ($sfname = readdir($dh))) {
54 if (substr($sfname, 0, 1) == '.') {
58 if (preg_match('/^(\d+)_(\d+)_(\d+)-to-\d+_\d+_\d+_upgrade.sql$/', $sfname, $matches)) {
59 $version = $matches[1] . '.' . $matches[2] . '.' . $matches[3];
60 $versions[$version] = $sfname;
69 <title
>OpenEMR Database Upgrade
</title
>
70 <link rel
='STYLESHEET' href
='interface/themes/style_blue.css'>
71 <link rel
="shortcut icon" href
="public/images/favicon.ico" />
75 <span
class='title'>OpenEMR Database Upgrade
</span
>
79 if (!empty($_POST['form_submit'])) {
80 $form_old_version = $_POST['form_old_version'];
82 foreach ($versions as $version => $filename) {
83 if (strcmp($version, $form_old_version) < 0) {
87 upgradeFromSqlFile($filename);
90 if (!empty($GLOBALS['ippf_specific'])) {
91 // Upgrade custom stuff for IPPF.
92 upgradeFromSqlFile('ippf_upgrade.sql');
95 if ((!empty($v_realpatch)) && ($v_realpatch != "") && ($v_realpatch > 0)) {
96 // This release contains a patch file, so process it.
97 upgradeFromSqlFile('patch.sql');
102 echo "<font color='green'>Updating global configuration defaults...</font><br />\n";
103 require_once("library/globals.inc.php");
104 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
105 foreach ($grparr as $fldid => $fldarr) {
106 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
107 if (is_array($fldtype) ||
(substr($fldtype, 0, 2) !== 'm_')) {
108 $row = sqlQuery("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
109 if (empty($row['count'])) {
110 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
111 "VALUES ( '$fldid', '0', '$flddef' )");
117 echo "<font color='green'>Updating Access Controls...</font><br />\n";
118 require("acl_upgrade.php");
121 $canRealPatchBeApplied = $versionService->canRealPatchBeApplied($desiredVersion);
122 $line = "Updating version indicators";
124 if ($canRealPatchBeApplied) {
125 $line = $line . ". Patch was also installed, updating version patch indicator";
128 echo "<font color='green'>" . $line . "...</font><br />\n";
129 $result = $versionService->update($desiredVersion);
132 echo "<font color='red'>Version could not be updated</font><br />\n";
136 echo "<p><font color='green'>Database and Access Control upgrade finished.</font></p>\n";
137 echo "</body></html>\n";
143 <form method
='post' action
='sql_upgrade.php'>
144 <p
>Please select the prior release you are converting from
:
145 <select name
='form_old_version'>
147 foreach ($versions as $version => $filename) {
148 echo " <option value='$version'";
149 // Defaulting to most recent version, which is now 5.0.0.
150 if ($version === '5.0.0') {
154 echo ">$version</option>\n";
159 <p
>If you are unsure
or were using a development version between two
160 releases
, then choose the older of possible releases
.</p
>
161 <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
>
162 <p
><input type
='submit' name
='form_submit' value
='Upgrade Database' /></p
>