| 1 |
<?php |
<?php |
| 2 |
|
|
| 3 |
// $Id: civicrm_error.module,v 1.1.2.3 2007/07/23 22:03:20 dalin Exp $ |
// $Id: civicrm_error.module,v 1.1.2.3.2.1 2009/06/30 13:47:06 dalin Exp $ |
| 4 |
|
|
| 5 |
/** |
/** |
| 6 |
* @file |
* @file |
| 13 |
* to use this function. |
* to use this function. |
| 14 |
*/ |
*/ |
| 15 |
function civicrm_error_handler($civicrm_error) { |
function civicrm_error_handler($civicrm_error) { |
| 16 |
|
global $user; |
| 17 |
|
|
| 18 |
$site = variable_get('site_name', 'drupal'); |
$site = variable_get('site_name', 'drupal'); |
| 19 |
|
|
| 20 |
// Generate output. |
// Generate output. |
| 21 |
$output .= 'There was a CiviCRM error at '. check_plain($site) .".\n"; |
$output .= $subject = t('CiviCRM error at @site', array('@site' => $site)); |
| 22 |
|
|
| 23 |
// CiviCRM error details. |
// CiviCRM error details. |
| 24 |
if ($civicrm_error) { |
if ($civicrm_error) { |
| 33 |
} |
} |
| 34 |
|
|
| 35 |
// User info. |
// User info. |
|
global $user; |
|
| 36 |
$output .= "\n\n\n\n\n============================ USER ============================\n"; |
$output .= "\n\n\n\n\n============================ USER ============================\n"; |
| 37 |
$output .= _civicrm_error_parse_array($user); |
$output .= _civicrm_error_parse_array($user); |
| 38 |
|
|
| 44 |
$output .= "\n\n\n\n\n============================ SESSION ============================\n"; |
$output .= "\n\n\n\n\n============================ SESSION ============================\n"; |
| 45 |
$output .= _civicrm_error_parse_array($_SESSION); |
$output .= _civicrm_error_parse_array($_SESSION); |
| 46 |
|
|
|
// $_SESSION |
|
|
$output .= "\n\n\n\n\n***SESSION***\n"; |
|
|
$output .= _civicrm_error_parse_array($_SESSION); |
|
|
|
|
| 47 |
// $_REQUEST |
// $_REQUEST |
| 48 |
$output .= "\n\n\n\n\n============================ REQUEST ============================\n"; |
$output .= "\n\n\n\n\n============================ REQUEST ============================\n"; |
| 49 |
$output .= _civicrm_error_parse_array($_REQUEST); |
$output .= _civicrm_error_parse_array($_REQUEST); |
| 50 |
|
|
| 51 |
// backtrace |
// Backtrace. |
| 52 |
$backtrace = debug_backtrace(); |
$backtrace = debug_backtrace(); |
| 53 |
$output .= "\n\n\n\n\n============================ BACKTRACE ============================\n"; |
$output .= "\n\n\n\n\n============================ BACKTRACE ============================\n"; |
| 54 |
foreach ($backtrace as $call) { |
foreach ($backtrace as $call) { |
| 57 |
} |
} |
| 58 |
|
|
| 59 |
// Log / send error. |
// Log / send error. |
|
$subject = 'CiviCRM error at '. $site; |
|
|
$to = variable_get('civicrm_error_to', variable_get("site_mail", ini_get("sendmail_from"))); |
|
| 60 |
$errors_via = variable_get('civicrm_error_via', 'both'); |
$errors_via = variable_get('civicrm_error_via', 'both'); |
| 61 |
if ($errors_via == 'both' || $errors_via == 'watchdog') { |
if ($errors_via == 'both' || $errors_via == 'watchdog') { |
| 62 |
watchdog('civicrm_error', t('CiviCRM Error: <pre>!output</pre>', array('!output' => $output)), |
watchdog('civicrm_error', 'CiviCRM Error: <pre>!output</pre>', array('!output' => $output), |
| 63 |
WATCHDOG_ERROR); |
WATCHDOG_ERROR); |
| 64 |
} |
} |
| 65 |
if ($errors_via == 'both' || $errors_via == 'email') { |
if ($errors_via == 'both' || $errors_via == 'email') { |
| 66 |
drupal_mail('civicrm_error', $to, $subject, $output); |
$to = variable_get('civicrm_error_to', variable_get("site_mail", ini_get("sendmail_from"))); |
| 67 |
|
$language = language_default(); |
| 68 |
|
$params = array( |
| 69 |
|
'subject' => $subject, |
| 70 |
|
'body' => $output, |
| 71 |
|
); |
| 72 |
|
drupal_mail('civicrm_error', 'civicrm_error_email', $to, $language, $params); |
| 73 |
} |
} |
| 74 |
|
|
| 75 |
} |
} |
| 76 |
|
|
| 77 |
/** |
/** |
| 78 |
|
* Implementation of hook_mail(). |
| 79 |
|
*/ |
| 80 |
|
function civicrm_error_mail($key, &$message, $params) { |
| 81 |
|
if ($key == 'civicrm_error_email') { |
| 82 |
|
$message['subject'] = $params['subject']; |
| 83 |
|
$message['body'][] = drupal_html_to_text($params['body']); |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
/** |
| 88 |
* Helper function to return a pretty print of the given array. |
* Helper function to return a pretty print of the given array. |
| 89 |
* |
* |
| 90 |
* @param array $array |
* @param array $array |
| 133 |
/** |
/** |
| 134 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 135 |
*/ |
*/ |
| 136 |
function civicrm_error_menu($may_cache) { |
function civicrm_error_menu() { |
| 137 |
$items = array(); |
$items['admin/reports/civicrm_error'] = array( |
| 138 |
if ($may_cache) { |
'title' => 'CiviCRM Error Handler', |
| 139 |
$items[] = array( |
'description' => 'Configure reporting for CiviCRM errors.', |
| 140 |
'path' => 'admin/logs/civicrm_error', |
'page callback' => 'drupal_get_form', |
| 141 |
'title' => t('CiviCRM Error Handler'), |
'page arguments' => array('civicrm_error_settings'), |
| 142 |
'description' => t('Email critical CiviCRM errors.'), |
'access arguments' => array('administer site configuration'), |
| 143 |
'callback' => 'drupal_get_form', |
'type' => MENU_NORMAL_ITEM, |
| 144 |
'callback arguments' => 'civicrm_error_settings', |
); |
|
'access' => user_access('administer site configuration'), |
|
|
'type' => MENU_NORMAL_ITEM, |
|
|
); |
|
|
} |
|
| 145 |
return $items; |
return $items; |
| 146 |
} |
} |
| 147 |
|
|
|
|
|
| 148 |
/** |
/** |
| 149 |
* Settings page. |
* Settings page. |
| 150 |
* |
* |