minor change to prior commit
[openemr.git] / sql_patch.php
blobaec2163381e428443b4c47688d3f22ab104d175f
1 <?php
3 // Copyright (C) 2008-2010 Rod Roark <rod@sunsetsystems.com>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This may be run after an upgraded OpenEMR has been installed.
11 // Its purpose is to upgrade the MySQL OpenEMR database as needed
12 // for the new release.
14 // Checks if the server's PHP version is compatible with OpenEMR:
15 require_once(dirname(__FILE__) . "/src/Common/Compatibility/Checker.php");
16 $response = OpenEMR\Common\Compatibility\Checker::checkPhpVersion();
17 if ($response !== true) {
18 die(htmlspecialchars($response));
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 use OpenEMR\Services\VersionService;
31 $versionService = new VersionService();
33 // Fetching current version because it was updated by the sql_upgrade_fx
34 // script and this script will further modify it.
35 $currentVersion = $versionService->fetch();
37 $desiredVersion = $currentVersion;
38 $desiredVersion->setDatabase($v_database);
39 $desiredVersion->setTag($v_tag);
40 $desiredVersion->setRealPatch($v_realpatch);
41 $desiredVersion->setPatch($v_patch);
42 $desiredVersion->setMinor($v_minor);
43 $desiredVersion->setMajor($v_major);
45 // Force logging off
46 $GLOBALS["enable_auditlog"] = 0;
48 $EMRversion = trim(preg_replace('/\s*\([^)]*\)/', '', $GLOBALS['openemr_version']));
52 <html>
53 <head>
54 <title>OpenEMR <?php echo attr($EMRversion) ?> <?php echo xlt('Database Patch'); ?></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 style="color:green;">
60 <div style="box-shadow: 3px 3px 5px 6px #ccc; border-radius: 20px; padding: 10px 40px;background-color:#EFEFEF; width:500px; margin:40px auto">
62 <p style="font-weight:bold; font-size:1.8em; text-align:center">OpenEMR <?php echo text($EMRversion),' ',xlt('Database Patch'),' ',text($desiredVersion->getRealPatch()) ?></p>
63 <p style="font-weight:bold; text-align:center;"><?php echo xlt('Applying Patch to site'),' : ',text($_SESSION['site_id']) ?></p>
66 <?php
67 upgradeFromSqlFile('patch.sql');
68 flush();
70 echo '<p style="font-weight:bold; text-align:left; color:green">',xlt('Updating global configuration defaults'),'...</p>';
71 $skipGlobalEvent = true; //use in globals.inc.php script to skip event stuff
72 require_once("library/globals.inc.php");
73 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
74 foreach ($grparr as $fldid => $fldarr) {
75 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
76 if (is_array($fldtype) || (substr($fldtype, 0, 2) !== 'm_')) {
77 $row = sqlQuery("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
78 if (empty($row['count'])) {
79 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
80 "VALUES ( '$fldid', '0', '$flddef' )");
86 $canRealPatchBeApplied = $versionService->canRealPatchBeApplied($desiredVersion);
87 if ($canRealPatchBeApplied) {
88 echo '<p style="font-weight:bold; text-align:left;">',xlt('Updating version indicators'),'...</p>';
89 $result = $versionService->update($desiredVersion);
91 if (!$result) {
92 echo '<p style="font-weight:bold; text-align:left; color:red">',xlt('Unable insert version information into database'),'...</p>';
96 echo '<p style="text-align:center; font-size:1.8em;">',xlt('Database Patch'),' ',text($desiredVersion->getRealPatch()),' ',xlt('finished'),'.</p>';
98 echo '<p style="text-align:center; font-size:1.8em;">OpenEMR ',xlt('Version'),' = ',text($EMRversion . '(' . $desiredVersion->getRealPatch() . ')'),'.</p>';
100 echo '<p><a style="border-radius: 10px; padding:5px; width:200px; margin:0 auto; background-color:green; color:white; font-weight:bold; display:block; text-align:center;" href="index.php?site=',attr($_SESSION['site_id']) . '">',xlt('Log in'),'</a></p>';
102 if (isset($_SERVER['HTTP_REFERER'])) {
103 $split = preg_split('/\//', $_SERVER['HTTP_REFERER']);
104 if ($split[count($split) - 1] == 'admin.php') {
105 echo '<p><a style="border-radius: 10px; padding:5px; width:200px; margin:0 auto; background-color:green; color:white; font-weight:bold; display:block; text-align:center;" href="admin.php">',xlt('Back to Admin Page'),'</a></p>';
110 </div>
111 </body>
112 </html>