Skip to content

Commit

Permalink
introduce INFO_DEPRECATION_LOG event
Browse files Browse the repository at this point in the history
This adds an event to dbg_deprecated(). This allows plugins to handle
deprecation warnings. One example would be @cosmocode/dokuwiki-plugin-sentry

One thing I don't like, but don't know how to avaoid is that this
function used to abort super early when $conf['allowdebug'] wasn't set.

However for the sentry plugin you probably would want logs, but still do
not show any debugging to end users (which allow debug would do).

So now the backtrace is always built, the event triggered and then
everything is sent to dbglog() which may simply throw everything away.

Suggestions on how to improve this welcome.
  • Loading branch information
splitbrain committed Jun 1, 2018
1 parent 2cceef4 commit 4445501
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions inc/infoutils.php
Expand Up @@ -443,24 +443,30 @@ function dbglog($msg,$header=''){
* @param string $alternative The function or method that should be used instead
*/
function dbg_deprecated($alternative = '') {
global $conf;
if(!$conf['allowdebug']) return;

$backtrace = debug_backtrace();
array_shift($backtrace);
$self = array_shift($backtrace);
$call = array_shift($backtrace);

$called = trim($self['class'].'::'.$self['function'].'()', ':');
$caller = trim($call['class'].'::'.$call['function'].'()', ':');

$msg = $called.' is deprecated. It was called from ';
$msg .= $caller.' in '.$call['file'].':'.$call['line'];
if($alternative) {
$msg .= ' '.$alternative.' should be used instead!';
$self = $backtrace[0];
$call = $backtrace[1];

$data = [
'trace' => $backtrace,
'alternative' => $alternative,
'called' => trim($self['class'] . '::' . $self['function'] . '()', ':'),
'caller' => trim($call['class'] . '::' . $call['function'] . '()', ':'),
'file' => $call['file'],
'line' => $call['line'],
];

$event = new Doku_Event('INFO_DEPRECATION_LOG', $data);
if($event->advise_before()) {
$msg = $event->data['called'] . ' is deprecated. It was called from ';
$msg .= $event->data['caller'] . ' in ' . $event->data['file'] . ':' . $event->data['line'];
if($event->data['alternative']) {
$msg .= ' ' . $event->data['alternative'] . ' should be used instead!';
}
dbglog($msg);
}

dbglog($msg);
$event->advise_after();
}

/**
Expand Down

0 comments on commit 4445501

Please sign in to comment.