Update X12_5010_837P.php (#2599)
[openemr.git] / sql_upgrade.php
blob386a3bb81e0b64f7311b69980b0b035061f27274
1 <?php
2 // Copyright (C) 2008-2010 Rod Roark <rod@sunsetsystems.com>
3 //
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.
8 //
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);
44 // Force logging off
45 $GLOBALS["enable_auditlog"]=0;
47 $versions = array();
48 $sqldir = "$webserver_root/sql";
49 $dh = opendir($sqldir);
50 if (! $dh) {
51 die("Cannot read $sqldir");
54 while (false !== ($sfname = readdir($dh))) {
55 if (substr($sfname, 0, 1) == '.') {
56 continue;
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;
65 closedir($dh);
66 ksort($versions);
68 <html>
69 <head>
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" />
73 </head>
74 <body>
75 <center>
76 <span class='title'>OpenEMR Database Upgrade</span>
77 <br>
78 </center>
79 <?php
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) {
85 continue;
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');
101 flush();
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");
121 echo "<br />\n";
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);
133 if (!$result) {
134 echo "<font color='red'>Version could not be updated</font><br />\n";
135 exit();
138 echo "<p><font color='green'>Database and Access Control upgrade finished.</font></p>\n";
139 echo "</body></html>\n";
140 exit();
144 <center>
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'>
148 <?php
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') {
153 echo " selected";
156 echo ">$version</option>\n";
159 </select>
160 </p>
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>
165 </form>
166 </center>
167 </body>
168 </html>