/**
 * Adds log entry into upgrade_log table
 *
 * @param int $type UPGRADE_LOG_NORMAL, UPGRADE_LOG_NOTICE or UPGRADE_LOG_ERROR
 * @param string $plugin plugin or null if main
 * @param string $info short description text of log entry
 * @param string $details long problem description
 * @param string $backtrace string used for errors only
 * @return void
 */
function upgrade_log($type, $plugin, $info, $details = null, $backtrace = null)
{
    global $DB, $USER, $CFG;
    $plugin = $plugin === 'moodle' ? null : $plugin;
    $backtrace = print_backtrace($backtrace, true);
    $version = null;
    //first try to find out current version number
    if (empty($plugin) or $plugin === 'moodle') {
        //main
        $version = $CFG->version;
    } else {
        if ($plugin === 'local') {
            //customisation
            $version = $CFG->local_version;
        } else {
            if (strpos($plugin, 'mod/') === 0) {
                try {
                    $modname = substr($plugin, strlen('mod/'));
                    $version = $DB->get_field('modules', 'version', array('name' => $modname));
                    $version = $version === false ? null : $version;
                } catch (Exception $ignored) {
                }
            } else {
                if (strpos($plugin, 'block/') === 0) {
                    try {
                        $blockname = substr($plugin, strlen('block/'));
                        if ($block = $DB->get_record('block', array('name' => $blockname))) {
                            $version = $block->version;
                        }
                    } catch (Exception $ignored) {
                    }
                } else {
                    $pluginversion = get_config(str_replace('/', '_', $plugin), 'version');
                    if (!empty($pluginversion)) {
                        $version = $pluginversion;
                    }
                }
            }
        }
    }
    $log = new object();
    $log->type = $type;
    $log->plugin = $plugin;
    $log->version = $version;
    $log->info = $info;
    $log->details = $details;
    $log->backtrace = $backtrace;
    $log->userid = $USER->id;
    $log->timemodified = time();
    try {
        $DB->insert_record('upgrade_log', $log);
    } catch (Exception $ignored) {
        // possible during install or 2.0 upgrade
    }
}
Exemple #2
0
/**
 * Returns true if the current site debugging settings are equal or above specified level.
 * If passed a parameter it will emit a debugging notice similar to trigger_error(). The
 * routing of notices is controlled by $CFG->debugdisplay
 * eg use like this:
 *
 * 1)  debugging('a normal debug notice');
 * 2)  debugging('something really picky', DEBUG_ALL);
 * 3)  debugging('annoying debug message only for develpers', DEBUG_DEVELOPER);
 * 4)  if (debugging()) { perform extra debugging operations (do not use print or echo) }
 *
 * In code blocks controlled by debugging() (such as example 4)
 * any output should be routed via debugging() itself, or the lower-level
 * trigger_error() or error_log(). Using echo or print will break XHTML
 * JS and HTTP headers.
 *
 *
 * @param string $message a message to print
 * @param int $level the level at which this debugging statement should show
 * @param array $backtrace use different backtrace
 * @return bool
 */
function debugging($message = '', $level = DEBUG_NORMAL, $backtrace = null)
{
    global $CFG;
    if (empty($CFG->debug)) {
        return false;
    }
    if ($CFG->debug >= $level) {
        if ($message) {
            if (!$backtrace) {
                $backtrace = debug_backtrace();
            }
            $from = print_backtrace($backtrace, true);
            if (!isset($CFG->debugdisplay)) {
                $CFG->debugdisplay = ini_get_bool('display_errors');
            }
            if ($CFG->debugdisplay) {
                if (!defined('DEBUGGING_PRINTED')) {
                    define('DEBUGGING_PRINTED', 1);
                    // indicates we have printed something
                }
                notify($message . $from, 'notifytiny');
            } else {
                trigger_error($message . $from, E_USER_NOTICE);
            }
        }
        return true;
    }
    return false;
}
Exemple #3
0
 /**
  * When rolling back, reset our transaction depth
  *
  */
 public function rollback()
 {
     // If we're at depth == 0, don't need to do a rollback
     if ($this->transactionDepth > 0) {
         $this->proxied->rollBack();
     }
     $this->log->debug("ROLLBACK");
     print_backtrace(debug_backtrace());
     $this->transactionDepth = 0;
 }