ensure always a unique installation id when need it (#4654)
[openemr.git] / sql_patch.php
blobb22a7eb4b725e604ac93b800884c6bd20eb2e5b1
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\Common\Uuid\UuidRegistry;
30 use OpenEMR\Services\VersionService;
32 // Force logging off
33 $GLOBALS["enable_auditlog"] = 0;
35 $EMRversion = trim(preg_replace('/\s*\([^)]*\)/', '', $GLOBALS['openemr_version']));
39 <html>
40 <head>
41 <title>OpenEMR <?php echo attr($EMRversion) ?> <?php echo xlt('Database Patch'); ?></title>
42 <link rel='STYLESHEET' href='interface/themes/style_blue.css'>
43 <link rel="shortcut icon" href="public/images/favicon.ico" />
44 </head>
45 <body style="color:green;">
47 <div style="box-shadow: 3px 3px 5px 6px #ccc; border-radius: 20px; padding: 10px 40px;background-color:#EFEFEF; width:500px; margin:40px auto">
49 <p style="font-weight:bold; font-size:1.8em; text-align:center">OpenEMR <?php echo text($EMRversion),' ',xlt('Database Patch'),' ',text($v_realpatch) ?></p>
50 <p style="font-weight:bold; text-align:center;"><?php echo xlt('Applying Patch to site'),' : ',text($_SESSION['site_id']) ?></p>
53 <?php
54 upgradeFromSqlFile('patch.sql');
55 flush();
57 echo "<br /><p class='text-success'>Updating UUIDs (this could take some time)<br />\n";
58 flush_echo();
59 $updateUuidLog = UuidRegistry::populateAllMissingUuids();
60 if (!empty($updateUuidLog)) {
61 echo "Updated UUIDs: " . text($updateUuidLog) . "</p>\n";
62 } else {
63 echo "Did not need to update or add any new UUIDs</p>\n";
65 flush_echo();
67 echo '<p style="font-weight:bold; text-align:left; color:green">',xlt('Updating global configuration defaults'),'...</p>';
68 $skipGlobalEvent = true; //use in globals.inc.php script to skip event stuff
69 require_once("library/globals.inc.php");
70 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
71 foreach ($grparr as $fldid => $fldarr) {
72 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
73 if (is_array($fldtype) || (substr($fldtype, 0, 2) !== 'm_')) {
74 $row = sqlQuery("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
75 if (empty($row['count'])) {
76 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
77 "VALUES ( '$fldid', '0', '$flddef' )");
83 $versionService = new VersionService();
84 $currentVersion = $versionService->fetch();
85 $desiredVersion = $currentVersion;
86 $desiredVersion['v_database'] = $v_database;
87 $desiredVersion['v_tag'] = $v_tag;
88 $desiredVersion['v_realpatch'] = $v_realpatch;
89 $desiredVersion['v_patch'] = $v_patch;
90 $desiredVersion['v_minor'] = $v_minor;
91 $desiredVersion['v_major'] = $v_major;
93 $canRealPatchBeApplied = $versionService->canRealPatchBeApplied($desiredVersion);
94 if ($canRealPatchBeApplied) {
95 echo '<p style="font-weight:bold; text-align:left;">',xlt('Updating version indicators'),'...</p>';
96 $versionService->update($desiredVersion);
99 echo '<p style="text-align:center; font-size:1.8em;">',xlt('Database Patch'),' ',text($desiredVersion['v_realpatch']),' ',xlt('finished'),'.</p>';
101 echo '<p style="text-align:center; font-size:1.8em;">OpenEMR ',xlt('Version'),' = ',text($EMRversion . '(' . $desiredVersion['v_realpatch'] . ')'),'.</p>';
103 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>';
105 if (isset($_SERVER['HTTP_REFERER'])) {
106 $split = preg_split('/\//', $_SERVER['HTTP_REFERER']);
107 if ($split[count($split) - 1] == 'admin.php') {
108 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>';
113 </div>
114 </body>
115 </html>