* @author Brady Miller * @copyright Copyright (c) 2008-2010 Rod Roark * @copyright Copyright (c) 2011-2021 Brady Miller * @link https://github.com/openemr/openemr/tree/master * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 */ /* @TODO add language selection. needs RTL testing */ $GLOBALS['ongoing_sql_upgrade'] = true; if (php_sapi_name() === 'cli') { // setting for when running as command line script // need this for output to be readable when running as command line $GLOBALS['force_simple_sql_upgrade'] = true; } // Checks if the server's PHP version is compatible with OpenEMR: require_once(__DIR__ . "/src/Common/Compatibility/Checker.php"); $response = OpenEMR\Common\Compatibility\Checker::checkPhpVersion(); if ($response !== true) { die(htmlspecialchars($response)); } @ini_set('zlib.output_compression', 0); @ini_set('implicit_flush', 1); @ob_end_clean(); // Disable PHP timeout. This will not work in safe mode. @ini_set('max_execution_time', '0'); if (ob_get_level() === 0) { ob_start(); } $ignoreAuth = true; // no login required $sessionAllowWrite = true; $GLOBALS['connection_pooling_off'] = true; // force off database connection pooling require_once('interface/globals.php'); require_once('library/sql_upgrade_fx.php'); use OpenEMR\Common\Csrf\CsrfUtils; use OpenEMR\Common\Uuid\UuidRegistry; use OpenEMR\Core\Header; use OpenEMR\Services\Utils\SQLUpgradeService; use OpenEMR\Services\VersionService; // Force logging off $GLOBALS["enable_auditlog"] = 0; $versions = array(); $sqldir = "$webserver_root/sql"; $dh = opendir($sqldir); if (!$dh) { die("Cannot read $sqldir"); } while (false !== ($sfname = readdir($dh))) { if ($sfname[0] === '.') { continue; } if (preg_match('/^(\d+)_(\d+)_(\d+)-to-\d+_\d+_\d+_upgrade.sql$/', $sfname, $matches)) { $version = $matches[1] . '.' . $matches[2] . '.' . $matches[3]; $versions[$version] = $sfname; } } closedir($dh); ksort($versions); $res2 = sqlStatement("select * from lang_languages where lang_description = ?", array($GLOBALS['language_default'])); for ($iter = 0; $row = sqlFetchArray($res2); $iter++) { $result2[$iter] = $row; } if (count($result2) == 1) { $defaultLangID = $result2[0]["lang_id"]; $defaultLangName = $result2[0]["lang_description"]; $direction = (int)$result2[0]["lang_is_rtl"] === 1 ? 'rtl' : 'ltr'; } else { //default to english if any problems $defaultLangID = 1; $defaultLangName = "English"; } $_SESSION['language_choice'] = $defaultLangID; $_SESSION['language_direction'] = $direction; CsrfUtils::setupCsrfKey(); session_write_close(); $sqlUpgradeService = new SQLUpgradeService(); header('Content-type: text/html; charset=utf-8'); ?> OpenEMR Database Upgrade

.
    $filename) { if (strcmp($version, $form_old_version) < 0) { continue; } // set polling version and start $sqlUpgradeService->flush_echo(""); $sqlUpgradeService->upgradeFromSqlFile($filename); // end polling sleep(2); // fixes odd bug, where if the sql upgrade goes to fast, then the polling does not stop $sqlUpgradeService->flush_echo(""); } if (!empty($GLOBALS['ippf_specific'])) { // Upgrade custom stuff for IPPF. $sqlUpgradeService->upgradeFromSqlFile('ippf_upgrade.sql'); } if ((!empty($v_realpatch)) && ($v_realpatch != "") && ($v_realpatch > 0)) { // This release contains a patch file, so process it. echo ""; $sqlUpgradeService->upgradeFromSqlFile('patch.sql'); } flush(); echo "

    Updating UUIDs (this could take some time)
    \n"; $sqlUpgradeService->flush_echo(""); $updateUuidLog = UuidRegistry::populateAllMissingUuids(); if (!empty($updateUuidLog)) { echo "Updated UUIDs: " . text($updateUuidLog) . "


    \n"; } else { echo "Did not need to update or add any new UUIDs


    \n"; } sleep(2); // fixes odd bug, where if process goes to fast, then the polling does not stop $sqlUpgradeService->flush_echo(""); echo "

    " . xlt("Updating global configuration defaults") . "..." . "


    \n"; $skipGlobalEvent = true; //use in globals.inc.php script to skip event stuff require_once("library/globals.inc.php"); foreach ($GLOBALS_METADATA as $grpname => $grparr) { foreach ($grparr as $fldid => $fldarr) { list($fldname, $fldtype, $flddef, $flddesc) = $fldarr; if (is_array($fldtype) || (substr($fldtype, 0, 2) !== 'm_')) { $row = sqlQuery("SELECT count(*) AS count FROM globals WHERE gl_name = '$fldid'"); if (empty($row['count'])) { sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " . "VALUES ( '$fldid', '0', '$flddef' )"); } } } } echo "

    " . xlt("Updating Access Controls") . "..." . "


    \n"; require("acl_upgrade.php"); echo "
    \n"; $versionService = new VersionService(); $currentVersion = $versionService->fetch(); $desiredVersion = $currentVersion; $desiredVersion['v_database'] = $v_database; $desiredVersion['v_tag'] = $v_tag; $desiredVersion['v_realpatch'] = $v_realpatch; $desiredVersion['v_patch'] = $v_patch; $desiredVersion['v_minor'] = $v_minor; $desiredVersion['v_major'] = $v_major; $canRealPatchBeApplied = $versionService->canRealPatchBeApplied($desiredVersion); $line = "Updating version indicators"; if ($canRealPatchBeApplied) { $line = $line . ". " . xlt("Patch was also installed, updating version patch indicator"); } echo "

    " . $line . "...


    \n"; $versionService->update($desiredVersion); echo "

    " . xlt("Database and Access Control upgrade finished.") . "

    \n"; echo "
    \n"; exit(); } ?>