Annual copyright bump (#6101)
[openemr.git] / sql_patch.php
blob81ea8761df3859f16e547a731366dfea6b7be580
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\Utils\SQLUpgradeService;
31 use OpenEMR\Services\VersionService;
33 // Force logging off
34 $GLOBALS["enable_auditlog"] = 0;
36 $EMRversion = trim(preg_replace('/\s*\([^)]*\)/', '', (new VersionService())->asString()));
38 $sqlUpgradeService = new SQLUpgradeService();
42 <html>
43 <head>
44 <title>OpenEMR <?php echo attr($EMRversion) ?> <?php echo xlt('Database Patch'); ?></title>
45 <link rel="shortcut icon" href="public/images/favicon.ico" />
46 </head>
47 <body style="color:green;">
49 <div style="box-shadow: 3px 3px 5px 6px #ccc; border-radius: 20px; padding: 10px 40px;background-color:#EFEFEF; width:500px; margin:40px auto">
51 <p style="font-weight:bold; font-size:1.8em; text-align:center">OpenEMR <?php echo text($EMRversion),' ',xlt('Database Patch'),' ',text($v_realpatch) ?></p>
52 <p style="font-weight:bold; text-align:center;"><?php echo xlt('Applying Patch to site'),' : ',text($_SESSION['site_id']) ?></p>
55 <?php
56 upgradeFromSqlFile('patch.sql');
57 flush();
59 echo "<br /><p class='text-success'>Updating UUIDs (this could take some time)<br />\n";
60 $sqlUpgradeService->flush_echo();
61 $updateUuidLog = UuidRegistry::populateAllMissingUuids();
62 if (!empty($updateUuidLog)) {
63 echo "Updated UUIDs: " . text($updateUuidLog) . "</p>\n";
64 } else {
65 echo "Did not need to update or add any new UUIDs</p>\n";
67 $sqlUpgradeService->flush_echo();
69 echo '<p style="font-weight:bold; text-align:left; color:green">',xlt('Updating global configuration defaults'),'...</p>';
70 $skipGlobalEvent = true; //use in globals.inc.php script to skip event stuff
71 require_once("library/globals.inc.php");
72 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
73 foreach ($grparr as $fldid => $fldarr) {
74 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
75 if (is_array($fldtype) || (substr($fldtype, 0, 2) !== 'm_')) {
76 $row = sqlQuery("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'");
77 if (empty($row['count'])) {
78 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
79 "VALUES ( '$fldid', '0', '$flddef' )");
85 $versionService = new VersionService();
86 $currentVersion = $versionService->fetch();
87 $desiredVersion = $currentVersion;
88 $desiredVersion['v_database'] = $v_database;
89 $desiredVersion['v_tag'] = $v_tag;
90 $desiredVersion['v_realpatch'] = $v_realpatch;
91 $desiredVersion['v_patch'] = $v_patch;
92 $desiredVersion['v_minor'] = $v_minor;
93 $desiredVersion['v_major'] = $v_major;
95 $canRealPatchBeApplied = $versionService->canRealPatchBeApplied($desiredVersion);
96 if ($canRealPatchBeApplied) {
97 echo '<p style="font-weight:bold; text-align:left;">',xlt('Updating version indicators'),'...</p>';
98 $versionService->update($desiredVersion);
101 echo '<p style="text-align:center; font-size:1.8em;">',xlt('Database Patch'),' ',text($desiredVersion['v_realpatch']),' ',xlt('finished'),'.</p>';
103 echo '<p style="text-align:center; font-size:1.8em;">OpenEMR ',xlt('Version'),' = ',text($EMRversion . '(' . $desiredVersion['v_realpatch'] . ')'),'.</p>';
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="index.php?site=',attr($_SESSION['site_id']) . '">',xlt('Log in'),'</a></p>';
107 if (isset($_SERVER['HTTP_REFERER'])) {
108 $split = preg_split('/\//', $_SERVER['HTTP_REFERER']);
109 if ($split[count($split) - 1] == 'admin.php') {
110 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>';
115 </div>
116 </body>
117 </html>