Example #1
0
/**
 * Enables CLI maintenance mode by creating new dataroot/climaintenance.html file.
 */
function enable_cli_maintenance_mode()
{
    global $CFG;
    if (file_exists("{$CFG->dataroot}/climaintenance.html")) {
        unlink("{$CFG->dataroot}/climaintenance.html");
    }
    if (isset($CFG->maintenance_message) and !html_is_blank($CFG->maintenance_message)) {
        $data = $CFG->maintenance_message;
        $data = bootstrap_renderer::early_error_content($data, null, null, null);
        $data = bootstrap_renderer::plain_page(get_string('sitemaintenance', 'admin'), $data);
    } else {
        if (file_exists("{$CFG->dataroot}/climaintenance.template.html")) {
            $data = file_get_contents("{$CFG->dataroot}/climaintenance.template.html");
        } else {
            $data = get_string('sitemaintenance', 'admin');
            $data = bootstrap_renderer::early_error_content($data, null, null, null);
            $data = bootstrap_renderer::plain_page(get_string('sitemaintenance', 'admin'), $data);
        }
    }
    file_put_contents("{$CFG->dataroot}/climaintenance.html", $data);
    chmod("{$CFG->dataroot}/climaintenance.html", $CFG->filepermissions);
}
Example #2
0
/**
 * Default exception handler, uncaught exceptions are equivalent to error() in 1.9 and earlier
 *
 * @param Exception $ex
 * @return void -does not return. Terminates execution!
 */
function default_exception_handler($ex)
{
    global $CFG, $DB, $OUTPUT, $USER, $FULLME, $SESSION, $PAGE;
    // detect active db transactions, rollback and log as error
    abort_all_db_transactions();
    if ($ex instanceof required_capability_exception && !CLI_SCRIPT && !AJAX_SCRIPT && !empty($CFG->autologinguests) && !empty($USER->autologinguest)) {
        $SESSION->wantsurl = qualified_me();
        redirect(get_login_url());
    }
    $info = get_exception_info($ex);
    if (debugging('', DEBUG_MINIMAL)) {
        $logerrmsg = "Default exception handler: " . $info->message . ' Debug: ' . $info->debuginfo . "\n" . format_backtrace($info->backtrace, true);
        error_log($logerrmsg);
    }
    if (is_early_init($info->backtrace)) {
        echo bootstrap_renderer::early_error($info->message, $info->moreinfourl, $info->link, $info->backtrace, $info->debuginfo, $info->errorcode);
    } else {
        try {
            if ($DB) {
                // If you enable db debugging and exception is thrown, the print footer prints a lot of rubbish
                $DB->set_debug(0);
            }
            echo $OUTPUT->fatal_error($info->message, $info->moreinfourl, $info->link, $info->backtrace, $info->debuginfo);
        } catch (Exception $out_ex) {
            // default exception handler MUST not throw any exceptions!!
            // the problem here is we do not know if page already started or not, we only know that somebody messed up in outputlib or theme
            // so we just print at least something instead of "Exception thrown without a stack frame in Unknown on line 0":-(
            if (CLI_SCRIPT or AJAX_SCRIPT) {
                // just ignore the error and send something back using the safest method
                echo bootstrap_renderer::early_error($info->message, $info->moreinfourl, $info->link, $info->backtrace, $info->debuginfo, $info->errorcode);
            } else {
                echo bootstrap_renderer::early_error_content($info->message, $info->moreinfourl, $info->link, $info->backtrace, $info->debuginfo);
                $outinfo = get_exception_info($out_ex);
                echo bootstrap_renderer::early_error_content($outinfo->message, $outinfo->moreinfourl, $outinfo->link, $outinfo->backtrace, $outinfo->debuginfo);
            }
        }
    }
    exit(1);
    // General error code
}
Example #3
0
/**
 * Create CLI maintenance file to prevent all access.
 */
function tool_dbtransfer_create_maintenance_file()
{
    global $CFG;
    register_shutdown_function('tool_dbtransfer_maintenance_callback');
    $options = new stdClass();
    $options->trusted = false;
    $options->noclean = false;
    $options->smiley = false;
    $options->filter = false;
    $options->para = true;
    $options->newlines = false;
    $message = format_text(get_string('climigrationnotice', 'tool_dbtransfer'), FORMAT_MARKDOWN, $options);
    $message = bootstrap_renderer::early_error_content($message, '', '', array());
    $html = <<<OET
<!DOCTYPE html>
<html>
<header><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><header/>
<body>{$message}</body>
</html>
OET;
    file_put_contents("{$CFG->dataroot}/climaintenance.html", $html);
    @chmod("{$CFG->dataroot}/climaintenance.html", $CFG->filepermissions);
}