? 324445-civicrm_error-formatting+watchdog+codestandards.11.patch ? 324445-civicrm_error-formatting+watchdog.4.patch ? 324445-civicrm_error-formatting+watchdog.9.patch Index: civicrm_error.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/civicrm_error/civicrm_error.install,v retrieving revision 1.1 diff -u -r1.1 civicrm_error.install --- civicrm_error.install 20 Jul 2007 15:44:34 -0000 1.1 +++ civicrm_error.install 29 Jun 2009 11:22:56 -0000 @@ -3,10 +3,16 @@ // $Id: civicrm_error.install,v 1.1 2007/07/20 15:44:34 dalin Exp $ /** + * @file + * Install file for civicrm_error module + */ + + +/** * Implementation of hook_install(). */ function civicrm_error_install() { - civicrm_error_config(true); + civicrm_error_config(TRUE); } /** @@ -17,7 +23,7 @@ civicrm_error_config(false); } -function civicrm_error_config($setup = true) { +function civicrm_error_config($setup = TRUE) { global $db_url; if (is_array($db_url) && isset($db_url['civicrm'])) { db_set_active('civicrm'); @@ -25,22 +31,22 @@ if ($domains = 1) { $config = unserialize(db_result(db_query('SELECT config_backend FROM civicrm_domain WHERE id = 1'))); if (array_key_exists('fatalErrorHandler', $config)) { - $config['fatalErrorHandler'] = ($setup ? 'civicrm_error_handler' : null); + $config['fatalErrorHandler'] = ($setup ? 'civicrm_error_handler' : NULL); /** TODO: this royal screws things up. Need to fix **/ // db_query('UPDATE civicrm_domain SET config_backend = "$s" WHERE id = 1', serialize($config)); - $fail = true; + $fail = TRUE; } else { - $fail = true; + $fail = TRUE; } } else { - $fail = true; + $fail = TRUE; } db_set_active(); } else { - $fail = true; + $fail = TRUE; } if ($fail) { $not = !$setup ? 'not ' : ''; Index: civicrm_error.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/civicrm_error/civicrm_error.module,v retrieving revision 1.1.2.5 diff -u -r1.1.2.5 civicrm_error.module --- civicrm_error.module 19 Sep 2007 22:40:03 -0000 1.1.2.5 +++ civicrm_error.module 29 Jun 2009 11:22:56 -0000 @@ -3,6 +3,11 @@ // $Id: civicrm_error.module,v 1.1.2.5 2007/09/19 22:40:03 dalin Exp $ /** + * @file + * Module to capture errors from CiviCRM + */ + +/** * Custom error function * Set CiviCRM » Administer CiviCRM » Global Settings » Debugging » Fatal Error Handler * To use this function @@ -16,11 +21,11 @@ // civicrm error details if ($civicrm_error) { - $output .= "\n\n\n\n***CIVICRM ERROR***\n"; + $output .= "\n\n============================ CIVICRM ERROR ============================\n"; $output .= _civicrm_error_parse_array($civicrm_error); } - $output .= "\n\n\n\n\n***PHP ERROR***\n"; + $output .= "\n\n\n\n\n============================ PHP ERROR ============================\n"; // php error details if (function_exists('error_get_last')) { $output .= _civicrm_error_parse_array(error_get_last()); @@ -31,34 +36,46 @@ // user info global $user; - $output .= "\n\n\n\n\n***USER***\n"; + $output .= "\n\n\n\n\n============================ USER ============================\n"; $output .= _civicrm_error_parse_array($user); // $_SERVER - $output .= "\n\n\n\n\n***SERVER***\n"; + $output .= "\n\n\n\n\n============================ SERVER ============================\n"; $output .= _civicrm_error_parse_array($_SERVER); // $_SESSION - $output .= "\n\n\n\n\n***SESSION***\n"; + $output .= "\n\n\n\n\n============================ SESSION ============================\n"; $output .= _civicrm_error_parse_array($_SESSION); // $_REQUEST - $output .= "\n\n\n\n\n***REQUEST***\n"; + $output .= "\n\n\n\n\n============================ REQUEST ============================\n"; $output .= _civicrm_error_parse_array($_REQUEST); // backtrace $backtrace = debug_backtrace(); - $output .= "\n\n\n\n\n***BACKTRACE***\n"; + $output .= "\n\n\n\n\n============================ BACKTRACE ============================\n"; foreach ($backtrace as $call) { - $output .= "\n\n**next call**\n"; + $output .= "\n\n ------------------------------- next call ------------------------------- \n"; $output .= _civicrm_error_parse_array($call); } // send email + // log error $subject = 'CiviCRM error at '. $site; $to = variable_get('civicrm_error_to', variable_get("site_mail", ini_get("sendmail_from"))); - drupal_mail('civicrm_error', $to, $subject, $output); + $errors_via = variable_get('civicrm_error_via', 'both') ; + switch ( $errors_via ) { + case "watchdog": + watchdog('civicrm_error', 'CiviCRM Error:
'. $output .'') ; + break ; + case "both": + watchdog('civicrm_error', 'CiviCRM Error:
'. $output .'') ; + // continue to "email" case here + case "email": + drupal_mail('civicrm_error', $to, $subject, $output); + break ; + } } /** @@ -68,9 +85,9 @@ // remove cc numbers $pattern = '/[0-9]{12}/'; $replace = 'xxxxxxxxxxxx'; - foreach((array)$array as $key => $value) { + foreach ((array)$array as $key => $value) { if (is_array($value) || is_object($value)) { - $value = print_r($value, true); + $value = print_r($value, TRUE); } $key = str_pad($key .':', 20, ' '); $line = $key . (string)_civicrm_error_check_length($value) ." \n"; @@ -123,5 +140,16 @@ '#description' => t("Select an email address to send all CiviCRM errors to."), '#required' => TRUE, ); + $form['civicrm_error_via'] = array( + '#type' => 'select', + '#title' => t('Errors via'), + '#options' => array( + 'both' => 'Email and Watchdog', + 'watchdog' => 'Watchdog only', + 'email' => 'Email only' + ), + '#default_value' => variable_get('civicrm_error_via', 'both'), + '#description' => t("Method for error delivery."), + ); return system_settings_form($form); }