Merge pull request #4822 from kurund/indentation-fixes
[civicrm-core.git] / CRM / Core / Error.php
index 688299a140dc494896c7b54a8afa9be467a65bd2..e6b543fac9b7b6426449ade8972164310bb51cbf 100644 (file)
@@ -2,7 +2,7 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -76,10 +76,10 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * Status code of various types of errors
    * @var const
    */
-  CONST FATAL_ERROR = 2;
-  CONST DUPLICATE_CONTACT = 8001;
-  CONST DUPLICATE_CONTRIBUTION = 8002;
-  CONST DUPLICATE_PARTICIPANT = 8003;
+  const FATAL_ERROR = 2;
+  const DUPLICATE_CONTACT = 8001;
+  const DUPLICATE_CONTRIBUTION = 8002;
+  const DUPLICATE_PARTICIPANT = 8003;
 
   /**
    * We only need one instance of this object. So we use the singleton
@@ -114,7 +114,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @return object
    * @static
    */
-   static function &singleton($package = NULL, $msgCallback = FALSE, $contextCallback = FALSE, $throwPEAR_Error = FALSE, $stackClass = 'PEAR_ErrorStack') {
+   public static function &singleton($package = NULL, $msgCallback = FALSE, $contextCallback = FALSE, $throwPEAR_Error = FALSE, $stackClass = 'PEAR_ErrorStack') {
     if (self::$_singleton === NULL) {
       self::$_singleton = new CRM_Core_Error('CiviCRM');
     }
@@ -124,7 +124,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
   /**
    * Constructor
    */
-  function __construct() {
+  public function __construct() {
     parent::__construct('CiviCRM');
 
     $log = CRM_Core_Config::getLog();
@@ -158,7 +158,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @param $error
    * @param string $separator
    */
-  static function displaySessionError(&$error, $separator = '<br />') {
+  public static function displaySessionError(&$error, $separator = '<br />') {
     $message = self::getMessages($error, $separator);
     if ($message) {
       $status = ts("Payment Processor Error message") . "{$separator} $message";
@@ -176,7 +176,6 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @param object PEAR_Error
    *
    * @return void
-   * @access public
    */
   public static function handle($pearError) {
 
@@ -308,9 +307,8 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    *
    * @return void
    * @static
-   * @access public
    */
-  static function fatal($message = NULL, $code = NULL, $email = NULL) {
+  public static function fatal($message = NULL, $code = NULL, $email = NULL) {
     $vars = array(
       'message' => $message,
       'code' => $code,
@@ -396,9 +394,14 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    *
    * @return void
    * @static
-   * @access public
    */
-  static function handleUnhandledException($exception) {
+  public static function handleUnhandledException($exception) {
+    try {
+      CRM_Utils_Hook::unhandledException($exception);
+    } catch (Exception $other) {
+      // if the exception-handler generates an exception, then that sucks! oh, well. carry on.
+      CRM_Core_Error::debug_var('handleUnhandledException_nestedException', self::formatTextException($other));
+    }
     $config = CRM_Core_Config::singleton();
     $vars = array(
       'message' => $exception->getMessage(),
@@ -471,10 +474,9 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    *                subsystem is not initialized - CRM-13765
    *
    * @return string the generated output
-   * @access public
    * @static
    */
-  static function debug($name, $variable = NULL, $log = TRUE, $html = TRUE, $checkPermission = TRUE) {
+  public static function debug($name, $variable = NULL, $log = TRUE, $html = TRUE, $checkPermission = TRUE) {
     $error = self::singleton();
 
     if ($variable === NULL) {
@@ -519,7 +521,6 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    *
    * @return string the generated output
    *
-   * @access public
    *
    * @static
    *
@@ -566,11 +567,10 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @param string $comp message to be output
    * @return string format of the backtrace
    *
-   * @access public
    *
    * @static
    */
-  static function debug_log_message($message, $out = FALSE, $comp = '') {
+  public static function debug_log_message($message, $out = FALSE, $comp = '') {
     $config = CRM_Core_Config::singleton();
 
     $file_log = self::createDebugLogger($comp);
@@ -594,7 +594,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
   /**
    * Append to the query log (if enabled)
    */
-  static function debug_query($string) {
+  public static function debug_query($string) {
     if ( defined( 'CIVICRM_DEBUG_LOG_QUERY' ) ) {
       if ( CIVICRM_DEBUG_LOG_QUERY == 'backtrace' ) {
         CRM_Core_Error::backtrace( $string, true );
@@ -604,6 +604,20 @@ class CRM_Core_Error extends PEAR_ErrorStack {
     }
   }
 
+  /**
+   * Execute a query and log the results.
+   *
+   * @param string $query
+   */
+  public static function debug_query_result($query) {
+    $dao = CRM_Core_DAO::executeQuery($query);
+    $results = array();
+    while ($dao->fetch()) {
+      $results[] = (array)$dao;
+    }
+    CRM_Core_Error::debug_var('dao result', array('query' => $query, 'results' => $results));
+  }
+
   /**
    * Obtain a reference to the error log
    *
@@ -611,7 +625,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    *
    * @return Log
    */
-  static function createDebugLogger($comp = '') {
+  public static function createDebugLogger($comp = '') {
     $config = CRM_Core_Config::singleton();
 
     if ($comp) {
@@ -643,7 +657,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @param string $msg
    * @param bool $log
    */
-  static function backtrace($msg = 'backTrace', $log = FALSE) {
+  public static function backtrace($msg = 'backTrace', $log = FALSE) {
     $backTrace = debug_backtrace();
     $message = self::formatBacktrace($backTrace);
     if (!$log) {
@@ -662,7 +676,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @param int $maxArgLen maximum number of characters to show from each argument string
    * @return string printable plain-text
    */
-  static function formatBacktrace($backTrace, $showArgs = TRUE, $maxArgLen = 80) {
+  public static function formatBacktrace($backTrace, $showArgs = TRUE, $maxArgLen = 80) {
     $message = '';
     foreach (self::parseBacktrace($backTrace, $showArgs, $maxArgLen) as $idx => $trace) {
       $message .= sprintf("#%s %s\n", $idx, $trace);
@@ -681,7 +695,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @see debug_backtrace
    * @see Exception::getTrace()
    */
-  static function parseBacktrace($backTrace, $showArgs = TRUE, $maxArgLen = 80) {
+  public static function parseBacktrace($backTrace, $showArgs = TRUE, $maxArgLen = 80) {
     $ret = array();
     foreach ($backTrace as $trace) {
       $args = array();
@@ -745,7 +759,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @param Exception $e
    * @return string printable HTML text
    */
-  static function formatHtmlException(Exception $e) {
+  public static function formatHtmlException(Exception $e) {
     $msg = '';
 
     // Exception metadata
@@ -779,7 +793,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @param Exception $e
    * @return string printable plain text
    */
-  static function formatTextException(Exception $e) {
+  public static function formatTextException(Exception $e) {
     $msg = get_class($e) . ": \"" . $e->getMessage() . "\"\n";
 
     $ei = $e;
@@ -803,7 +817,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    *
    * @return object
    */
-  static function createError($message, $code = 8000, $level = 'Fatal', $params = NULL) {
+  public static function createError($message, $code = 8000, $level = 'Fatal', $params = NULL) {
     $error = CRM_Core_Error::singleton();
     $error->push($code, $level, array($params), $message);
     return $error;
@@ -817,7 +831,6 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @param null $redirect
    * @param string $title
    * @return void
-   * @access public
    * @static
    */
   public static function statusBounce($status, $redirect = NULL, $title = NULL) {
@@ -838,7 +851,6 @@ class CRM_Core_Error extends PEAR_ErrorStack {
   /**
    * Reset the error stack
    *
-   * @access public
    * @static
    */
   public static function reset() {
@@ -863,7 +875,6 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    *
    * @param object $obj       The PEAR_ERROR object
    * @return object $obj
-   * @access public
    * @static
    */
   public static function nullHandler($obj) {