Commit 30676ef2 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1950199: Reset mahara timezone after saml cron breaks it



There is a part of the SAML core code that sets the timezone to UTC
when creating the metadata refresh file.

This causes all cron jobs after it in the same run to use the
incorrect timezone

Change-Id: Id6c741b439ef42c50edc844878969f90e24a29b6
Signed-off-by: default avatarRobert Lyon <robertl@catalyst.net.nz>
(cherry picked from commit 5a239852)
parent 608a1656
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -568,6 +568,9 @@ class PluginAuthSaml extends PluginAuth {
                                           AND aic.field = 'metarefresh_metadata_url'
                                           AND (aic.value IS NOT NULL and aic.value != '')", array())) {
            Metarefresh::metadata_refresh_hook();
            // Reset timezone back to what it should be
            $timezone = get_mahara_timezone();
            date_default_timezone_set($timezone);
        }
    }

+1 −19
Original line number Diff line number Diff line
@@ -1761,25 +1761,7 @@ function configure_dbconnection() {
    // Bug 1771362: Set timezone for PHP and the DB to a user selected timezone or the country
    // selected in site settings (if no timezone selected) to avoid innaccurate times being shown.
    try {
        $timezoners = $db->_Execute("SELECT value FROM " . db_table_name('config') . " WHERE field = 'timezone' LIMIT 1");
        if (!$timezoners->fields || $timezoners->fields['value'] == "") {
            $countryrs = $db->_Execute("SELECT value FROM " . db_table_name('config') . " WHERE field = 'country' LIMIT 1");
            if ($countryrs->fields && $countryrs->fields['value'] != "") {
                // Get the two letter country identifier.
                $country = $countryrs->fields['value'];
                // Country ID has to be uppercase or this won't work.
                $timezone = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, strtoupper($country))[0];
                if (!$timezoners->fields) {
                    $db->_Execute("INSERT INTO " . db_table_name('config') . " (field, value) VALUES ('timezone', '" . $timezone . "')");
                }
                else {
                    $db->_Execute("UPDATE " . db_table_name('config') . " SET value = '" . $timezone . "' WHERE field = 'timezone'");
                }
            }
        }
        else {
            $timezone = $timezoners->fields['value'];
        }
        $timezone = get_mahara_timezone();

        if (!empty($timezone)) {
            date_default_timezone_set($timezone); // For PHP.
+30 −0
Original line number Diff line number Diff line
@@ -6247,3 +6247,33 @@ function clean_str_replace($str, $replace='', $exclude=array()) {
    }
    return $str;
}

/**
 * Get the timezone for the mahara site
 *
 * @return string timezone
 */
function get_mahara_timezone() {
    db_ignore_sql_exceptions(true);
    try {
        $timezone = get_field_sql("SELECT value FROM {config} WHERE field = ? LIMIT 1", array('timezone'));
        if (empty($timezone)) {
            // Get the two letter country identifier.
            $country = get_field_sql("SELECT value FROM {config} WHERE field = ? LIMIT 1", array('country'));
            if ($country) {
                // Country ID has to be uppercase or this won't work.
                $timezone = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, strtoupper($country))[0];
            }
            else {
                // No timezone available
                $timezone = 'UTC';
            }
        }
        return $timezone;
    }
    catch (SQLException $e) {
        // Site probably not installed yet
        return 'UTC';
    }
    db_ignore_sql_exceptions(false);
}
 No newline at end of file