remove unused packages and parts of packages
[openemr.git] / sql_upgrade.php
blob62d4037c17fcf38134583ad136bb4f854118e274
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__) . "/common/compatibility/Checker.php");
16 use OpenEMR\Common\Checker;
18 $response = Checker::checkPhpVersion();
19 if ($response !== true) {
20 die($response);
23 // Disable PHP timeout. This will not work in safe mode.
24 ini_set('max_execution_time', '0');
26 $ignoreAuth = true; // no login required
28 require_once('interface/globals.php');
29 require_once('library/sql_upgrade_fx.php');
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);
47 // Force logging off
48 $GLOBALS["enable_auditlog"]=0;
50 $versions = array();
51 $sqldir = "$webserver_root/sql";
52 $dh = opendir($sqldir);
53 if (! $dh) {
54 die("Cannot read $sqldir");
57 while (false !== ($sfname = readdir($dh))) {
58 if (substr($sfname, 0, 1) == '.') {
59 continue;
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;
68 closedir($dh);
69 ksort($versions);
71 <html>
72 <head>
73 <title>OpenEMR Database Upgrade</title>
74 <link rel='STYLESHEET' href='interface/themes/style_blue.css'>
75 <link rel="shortcut icon" href="public/images/favicon.ico" />
76 </head>
77 <body>
78 <center>
79 <span class='title'>OpenEMR Database Upgrade</span>
80 <br>
81 </center>
82 <?php
83 if (!empty($_POST['form_submit'])) {
84 $form_old_version = $_POST['form_old_version'];
86 foreach ($versions as $version => $filename) {
87 if (strcmp($version, $form_old_version) < 0) {
88 continue;
91 upgradeFromSqlFile($filename);
94 if (!empty($GLOBALS['ippf_specific'])) {
95 // Upgrade custom stuff for IPPF.
96 upgradeFromSqlFile('ippf_upgrade.sql');
99 if ((!empty($v_realpatch)) && ($v_realpatch != "") && ($v_realpatch > 0)) {
100 // This release contains a patch file, so process it.
101 upgradeFromSqlFile('patch.sql');
104 flush();
106 echo "<font color='green'>Updating global configuration defaults...</font><br />\n";
107 require_once("library/globals.inc.php");
108 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
109 foreach ($grparr as $fldid => $fldarr) {
110 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
111 if (is_array($fldtype) || (substr($fldtype, 0, 2) !== 'm_')) {
112 $row = sqlQuery("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
113 if (empty($row['count'])) {
114 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
115 "VALUES ( '$fldid', '0', '$flddef' )");
121 echo "<font color='green'>Updating Access Controls...</font><br />\n";
122 require("acl_upgrade.php");
123 echo "<br />\n";
125 $canRealPatchBeApplied = $versionService->canRealPatchBeApplied($desiredVersion);
126 $line = "Updating version indicators";
128 if ($canRealPatchBeApplied) {
129 $line = $line . ". Patch was also installed, updating version patch indicator";
132 echo "<font color='green'>" . $line . "...</font><br />\n";
133 $result = $versionService->update($desiredVersion);
135 if (!$result) {
136 echo "<font color='red'>Version could not be updated</font><br />\n";
137 exit();
140 echo "<p><font color='green'>Database and Access Control upgrade finished.</font></p>\n";
141 echo "</body></html>\n";
142 exit();
146 <center>
147 <form method='post' action='sql_upgrade.php'>
148 <p>Please select the prior release you are converting from:
149 <select name='form_old_version'>
150 <?php
151 foreach ($versions as $version => $filename) {
152 echo " <option value='$version'";
153 // Defaulting to most recent version, which is now 5.0.1.
154 if ($version === '5.0.1') {
155 echo " selected";
158 echo ">$version</option>\n";
161 </select>
162 </p>
163 <p>If you are unsure or were using a development version between two
164 releases, then choose the older of possible releases.</p>
165 <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>
166 <p><input type='submit' name='form_submit' value='Upgrade Database' /></p>
167 </form>
168 </center>
169 </body>
170 </html>