added new datepicker to disclosures gui
[openemr.git] / sql_upgrade.php
blobae6ce4199fb796f48211979683db44383789d87a
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 // Disable PHP timeout. This will not work in safe mode.
14 ini_set('max_execution_time', '0');
16 $ignoreAuth = true; // no login required
18 require_once('interface/globals.php');
19 require_once('library/sql_upgrade_fx.php');
21 $versionService = new \services\VersionService();
23 // Fetching current version because it was updated by the sql_upgrade_fx
24 // script and this script will further modify it.
25 $currentVersion = $versionService->fetch();
27 $desiredVersion = $currentVersion;
28 $desiredVersion->setDatabase($v_database);
29 $desiredVersion->setTag($v_tag);
30 $desiredVersion->setRealPatch($v_realpatch);
31 $desiredVersion->setPatch($v_patch);
32 $desiredVersion->setMinor($v_minor);
33 $desiredVersion->setMajor($v_major);
35 // Force logging off
36 $GLOBALS["enable_auditlog"]=0;
38 $versions = array();
39 $sqldir = "$webserver_root/sql";
40 $dh = opendir($sqldir);
41 if (! $dh) die("Cannot read $sqldir");
42 while (false !== ($sfname = readdir($dh))) {
43 if (substr($sfname, 0, 1) == '.') continue;
44 if (preg_match('/^(\d+)_(\d+)_(\d+)-to-\d+_\d+_\d+_upgrade.sql$/', $sfname, $matches)) {
45 $version = $matches[1] . '.' . $matches[2] . '.' . $matches[3];
46 $versions[$version] = $sfname;
49 closedir($dh);
50 ksort($versions);
52 <html>
53 <head>
54 <title>OpenEMR Database Upgrade</title>
55 <link rel='STYLESHEET' href='interface/themes/style_blue.css'>
56 <link rel="shortcut icon" href="public/images/favicon.ico" />
57 </head>
58 <body>
59 <center>
60 <span class='title'>OpenEMR Database Upgrade</span>
61 <br>
62 </center>
63 <?php
64 if (!empty($_POST['form_submit'])) {
65 $form_old_version = $_POST['form_old_version'];
67 foreach ($versions as $version => $filename) {
68 if (strcmp($version, $form_old_version) < 0) continue;
69 upgradeFromSqlFile($filename);
72 if (!empty($GLOBALS['ippf_specific'])) {
73 // Upgrade custom stuff for IPPF.
74 upgradeFromSqlFile('ippf_upgrade.sql');
77 if ( (!empty($v_realpatch)) && ($v_realpatch != "") && ($v_realpatch > 0) ) {
78 // This release contains a patch file, so process it.
79 upgradeFromSqlFile('patch.sql');
82 flush();
84 echo "<font color='green'>Updating global configuration defaults...</font><br />\n";
85 require_once("library/globals.inc.php");
86 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
87 foreach ($grparr as $fldid => $fldarr) {
88 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
89 if ( is_array($fldtype) || (substr($fldtype, 0, 2) !== 'm_') ) {
90 $row = sqlQuery("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
91 if (empty($row['count'])) {
92 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
93 "VALUES ( '$fldid', '0', '$flddef' )");
99 echo "<font color='green'>Updating Access Controls...</font><br />\n";
100 require("acl_upgrade.php");
101 echo "<br />\n";
103 $canRealPatchBeApplied = $versionService->canRealPatchBeApplied($desiredVersion);
104 $line = "Updating version indicators";
106 if ($canRealPatchBeApplied) {
107 $line = $line . ". Patch was also installed, updating version patch indicator";
110 echo "<font color='green'>" . $line . "...</font><br />\n";
111 $result = $versionService->update($desiredVersion);
113 if (!$result) {
114 echo "<font color='red'>Version could not be updated</font><br />\n";
115 exit();
118 echo "<p><font color='green'>Database and Access Control upgrade finished.</font></p>\n";
119 echo "</body></html>\n";
120 exit();
124 <center>
125 <form method='post' action='sql_upgrade.php'>
126 <p>Please select the prior release you are converting from:
127 <select name='form_old_version'>
128 <?php
129 foreach ($versions as $version => $filename) {
130 echo " <option value='$version'";
131 // Defaulting to most recent version, which is now 5.0.0.
132 if ($version === '5.0.0') echo " selected";
133 echo ">$version</option>\n";
136 </select>
137 </p>
138 <p>If you are unsure or were using a development version between two
139 releases, then choose the older of possible releases.</p>
140 <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>
141 <p><input type='submit' name='form_submit' value='Upgrade Database' /></p>
142 </form>
143 </center>
144 </body>
145 </html>