php - How can I get mediawiki to email me on every db error? -


i'm looking hook or way send out emails every time database error on mediawiki. realize might have add functionality database class i'm not sure @ moment if should doing that.

i not want solution includes daemons, crons, or else that'll read , send out emails based on sql query log.

the practical way of doing registering custom exception handler. there check if exception database error , send e-mail accordingly.

i’ve come simple code:

$wghooks['setupaftercache'][] = 'onsetupaftercache'; function onsetupaftercache() {     set_exception_handler( 'customexceptionhandler' );      return true; } 

first have set hook register our exception handler. if registered in localsettings.php overriden wfinstallexceptionhandler().

function customexceptionhandler( $e ) {     if( $e instanceof dberror ) {         $from = new mailaddress( 'dberror@example.com' );         $to = new mailaddress( 'personal.mail@example.com' );         $body = 'a database error occured on wiki. details follow:' . "\n\n" .             $e->gettext();          usermailer::send( $to, $from, 'database error on wiki', $body );     } 

here check if exception caused database , send e-mail. should customize $from, $to , $body variables. more info usermailer , mailaddress classes see documentation.

    wfexceptionhandler( $e ); } 

in end pass exception mediawiki’s handler, we’ve overriden earlier. takes care of outputting error user , other important stuff.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -