[REF] Switch CRM_Utils_Error::fatal calls for CRM_Core_Exception in Grant. utils...
authorSeamus Lee <seamuslee001@gmail.com>
Sat, 14 Dec 2019 21:40:07 +0000 (08:40 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Sat, 14 Dec 2019 21:59:23 +0000 (08:59 +1100)
12 files changed:
CRM/Grant/BAO/Grant.php
CRM/Utils/Hook.php
CRM/Utils/HttpClient.php
CRM/Utils/Mail.php
CRM/Utils/Mail/EmailProcessor.php
CRM/Utils/Migrate/Export.php
CRM/Utils/Migrate/Import.php
CRM/Utils/System.php
CRM/Utils/Type.php
CRM/Utils/Weight.php
Civi/Angular/Page/Modules.php
bin/ContributionProcessor.php

index 12147c190ef6a658d602dc9ce371d295a190d9b7..baf098c4fc047ff1950b8768fff4ea9dbf5bd673 100644 (file)
@@ -71,6 +71,8 @@ class CRM_Grant_BAO_Grant extends CRM_Grant_DAO_Grant {
    *
    * @return array
    *   Array of event summary values
+   *
+   * @throws CRM_Core_Exception
    */
   public static function getGrantStatusOptGroup() {
 
@@ -81,7 +83,7 @@ class CRM_Grant_BAO_Grant extends CRM_Grant_DAO_Grant {
 
     $og = CRM_Core_BAO_OptionGroup::retrieve($params, $defaults);
     if (!$og) {
-      CRM_Core_Error::fatal('No option group for grant statuses - database discrepancy! Make sure you loaded civicrm_data.mysql');
+      throw new CRM_Core_Exception('No option group for grant statuses - database discrepancy! Make sure you loaded civicrm_data.mysql');
     }
 
     return $og;
index 89dd2be19d6911ee0b971e1c7e422af4d49776dd..b84ec7ac87139bc43129b02204c2059567acfc67 100644 (file)
@@ -57,7 +57,7 @@ abstract class CRM_Utils_Hook {
   private $commonIncluded = FALSE;
 
   /**
-   * @var array(string)
+   * @var array|string
    */
   private $commonCiviModules = [];
 
@@ -249,7 +249,7 @@ abstract class CRM_Utils_Hook {
    * @param mixed $arg6
    *
    * @return array|bool
-   * @throws \Exception
+   * @throws \CRM_Core_Exception
    */
   public function runHooks(
     $civiModules, $fnSuffix, $numParams,
@@ -307,8 +307,7 @@ abstract class CRM_Utils_Hook {
           break;
 
         default:
-          CRM_Core_Error::fatal(ts('Invalid hook invocation'));
-          break;
+          throw new CRM_Core_Exception(ts('Invalid hook invocation'));
       }
 
       if (!empty($fResult) &&
index 4bab3001ea565638be82887c02c136c0a83d97ab..c7989ec626842d935c381ed23a99e1107a0fee46 100644 (file)
@@ -62,16 +62,18 @@ class CRM_Utils_HttpClient {
    * @param string $localFile
    *   Path at which to store the .zip file.
    * @return STATUS_OK|STATUS_WRITE_ERROR|STATUS_DL_ERROR
+   *
+   * @throws CRM_Core_Exception
    */
   public function fetch($remoteFile, $localFile) {
     // Download extension zip file ...
     if (!function_exists('curl_init')) {
-      CRM_Core_Error::fatal('Cannot install this extension - curl is not installed!');
+      throw new CRM_Core_Exception('Cannot install this extension - curl is not installed!');
     }
 
     list($ch, $caConfig) = $this->createCurl($remoteFile);
     if (preg_match('/^https:/', $remoteFile) && !$caConfig->isEnableSSL()) {
-      CRM_Core_Error::fatal('Cannot install this extension - does not support SSL');
+      throw new CRM_Core_Exception('Cannot install this extension - does not support SSL');
     }
 
     $fp = @fopen($localFile, "w");
index 6e7cc0c6cca89b4d6719d48b13e7826e97e61cf8..b9aa6ef617e2662fd423a5872899e63d73cecffd 100644 (file)
@@ -25,6 +25,8 @@ class CRM_Utils_Mail {
    * to the mailer through the container.
    *
    * @return Mail
+   *
+   * @throws CRM_Core_Exception
    */
   public static function createMailer() {
     $mailingInfo = Civi::settings()->get('mailing_backend');
@@ -37,7 +39,7 @@ class CRM_Utils_Mail {
     elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SMTP) {
       if ($mailingInfo['smtpServer'] == '' || !$mailingInfo['smtpServer']) {
         CRM_Core_Error::debug_log_message(ts('There is no valid smtp server setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the SMTP Server.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
-        CRM_Core_Error::fatal(ts('There is no valid smtp server setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the SMTP Server.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
+        throw new CRM_Core_Exception(ts('There is no valid smtp server setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the SMTP Server.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
       }
 
       $params['host'] = $mailingInfo['smtpServer'] ? $mailingInfo['smtpServer'] : 'localhost';
@@ -81,7 +83,7 @@ class CRM_Utils_Mail {
         !$mailingInfo['sendmail_path']
       ) {
         CRM_Core_Error::debug_log_message(ts('There is no valid sendmail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the sendmail server.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
-        CRM_Core_Error::fatal(ts('There is no valid sendmail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the sendmail server.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
+        throw new CRM_Core_Exception(ts('There is no valid sendmail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the sendmail server.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
       }
       $params['sendmail_path'] = $mailingInfo['sendmail_path'];
       $params['sendmail_args'] = $mailingInfo['sendmail_args'];
index 90b65cdc04ef7ed3f06b41225788f5f7baca3e6f..9d68310b9dfef8fd455bc1e9ac62984ef1df050e 100644 (file)
@@ -75,6 +75,10 @@ class CRM_Utils_Mail_EmailProcessor {
 
   /**
    * Process the mailboxes that aren't default (ie. that aren't used by civiMail for the bounce).
+   *
+   * @return bool
+   *
+   * @throws CRM_Core_Exception.
    */
   public static function processActivities() {
     $dao = new CRM_Core_DAO_MailSettings();
@@ -87,7 +91,7 @@ class CRM_Utils_Mail_EmailProcessor {
       self::_process(FALSE, $dao, TRUE);
     }
     if (!$found) {
-      CRM_Core_Error::fatal(ts('No mailboxes have been configured for Email to Activity Processing'));
+      throw new CRM_Core_Exception(ts('No mailboxes have been configured for Email to Activity Processing'));
     }
     return $found;
   }
@@ -114,6 +118,7 @@ class CRM_Utils_Mail_EmailProcessor {
    *   Create activities.
    *
    * @throws Exception
+   * @throws CRM_Core_Exception
    */
   public static function _process($civiMail, $dao, $is_create_activities) {
     // 0 = activities; 1 = bounce;
@@ -125,7 +130,7 @@ class CRM_Utils_Mail_EmailProcessor {
       : CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Inbound Email');
 
     if (!$emailActivityTypeId) {
-      CRM_Core_Error::fatal(ts('Could not find a valid Activity Type ID for Inbound Email'));
+      throw new CRM_Core_Exception(ts('Could not find a valid Activity Type ID for Inbound Email'));
     }
 
     $config = CRM_Core_Config::singleton();
@@ -156,7 +161,7 @@ class CRM_Utils_Mail_EmailProcessor {
       $message = ts('Could not connect to MailStore for ') . $dao->username . '@' . $dao->server . '<p>';
       $message .= ts('Error message: ');
       $message .= '<pre>' . $e->getMessage() . '</pre><p>';
-      CRM_Core_Error::fatal($message);
+      throw new CRM_Core_Exception($message);
     }
 
     // process fifty at a time, CRM-4002
index e8f5c00951baae267c4985d68ba02c27ab4fd4e7..73469e553f59210f9e6ea8ad390bc2a66f8b1860 100644 (file)
@@ -19,7 +19,8 @@ class CRM_Utils_Migrate_Export {
   const XML_VALUE_SEPARATOR = ":;:;:;";
 
   /**
-   * @var array description of export field mapping
+   * @var array
+   * Description of export field mapping
    *
    * @code
    * 'exampleEntityMappingName' => array(
@@ -343,6 +344,7 @@ class CRM_Utils_Migrate_Export {
    *
    * @return string
    *   XML
+   * @throws CRM_Core_Exception
    */
   public function toXML() {
     $buffer = '<?xml version="1.0" encoding="iso-8859-1" ?>';
@@ -356,7 +358,7 @@ class CRM_Utils_Migrate_Export {
         $buffer .= "  </{$this->_xml[$key]['scope']}>\n";
       }
       elseif ($this->_xml[$key]['required']) {
-        CRM_Core_Error::fatal("No records in DB for $key");
+        throw new CRM_Core_Exception("No records in DB for $key");
       }
     }
     $buffer .= "</CustomData>\n";
index 0f5d0443a865a50f4a6362a6d24ec36d95ddef9e..420198d7917b374458c323f1d057aad2d0a66a51 100644 (file)
@@ -398,7 +398,7 @@ AND        v.name = %1
    * @param $xml
    * @param $idMap
    *
-   * @throws Exception
+   * @throws CRM_Core_Exception
    */
   public function profileFields(&$xml, &$idMap) {
     foreach ($xml->ProfileFields as $profileFieldsXML) {
@@ -423,7 +423,7 @@ AND        f.column_name = %2
           ];
           $cfID = CRM_Core_DAO::singleValueQuery($sql, $params);
           if (!$cfID) {
-            CRM_Core_Error::fatal(ts("Could not find custom field for %1, %2, %3",
+            throw new CRM_Core_Exception(ts("Could not find custom field for %1, %2, %3",
                 [
                   1 => $profileField->field_name,
                   2 => $tableName,
index 28f9e9ba9e135b57b8b003e30ea9d7627d24e999..21cfda96a144c38658cb276bbe3c2f6371b87b0b 100644 (file)
@@ -980,6 +980,8 @@ class CRM_Utils_System {
    *   Returns TRUE if the requirement is met, FALSE if the requirement is not
    *   met and we're not aborting due to the failed requirement. If $abort is
    *   TRUE and the requirement fails, this function does not return.
+   *
+   * @throws CRM_Core_Exception
    */
   public static function checkPHPVersion($ver = 5, $abort = TRUE) {
     $phpVersion = substr(PHP_VERSION, 0, 1);
@@ -988,7 +990,7 @@ class CRM_Utils_System {
     }
 
     if ($abort) {
-      CRM_Core_Error::fatal(ts('This feature requires PHP Version %1 or greater',
+      throw new CRM_Core_Exception(ts('This feature requires PHP Version %1 or greater',
         [1 => $ver]
       ));
     }
@@ -1059,6 +1061,8 @@ class CRM_Utils_System {
    *
    * @return string
    *   civicrm version
+   *
+   * @throws CRM_Core_Exception
    */
   public static function version() {
     static $version;
@@ -1075,7 +1079,7 @@ class CRM_Utils_System {
 
       // pattern check
       if (!CRM_Utils_System::isVersionFormatValid($version)) {
-        CRM_Core_Error::fatal('Unknown codebase version.');
+        throw new CRM_Core_Exception('Unknown codebase version.');
       }
     }
 
@@ -1161,7 +1165,7 @@ class CRM_Utils_System {
    *
    * @param bool|FALSE $abort
    *
-   * @throws \Exception
+   * @throws \CRM_Core_Exception
    */
   public static function redirectToSSL($abort = FALSE) {
     $config = CRM_Core_Config::singleton();
@@ -1177,7 +1181,7 @@ class CRM_Utils_System {
       Civi::log()->warning('CiviCRM thinks site is not SSL, redirecting to {url}', ['url' => $url]);
       if (!self::checkURL($url, TRUE)) {
         if ($abort) {
-          CRM_Core_Error::fatal('HTTPS is not set up on this machine');
+          throw new CRM_Core_Exception('HTTPS is not set up on this machine');
         }
         else {
           CRM_Core_Session::setStatus(ts('HTTPS is not set up on this machine'), ts('Warning'), 'alert');
index b57ea91540dd41a52eae6b4a5883da15f255967e..54abc84763e947b62494af3c8f3b718c43526f90 100644 (file)
@@ -213,7 +213,7 @@ class CRM_Utils_Type {
    * @param string $type
    *   The type to verify against.
    * @param bool $abort
-   *   If TRUE, the operation will CRM_Core_Error::fatal() on invalid data.
+   *   If TRUE, the operation will throw an CRM_Core_Exception on invalid data.
    *
    * @return mixed
    *   The data, escaped if necessary.
@@ -326,17 +326,16 @@ class CRM_Utils_Type {
         break;
 
       default:
-        CRM_Core_Error::fatal(
+        throw new CRM_Core_Exception(
           $type . " is not a recognised (camel cased) data type."
         );
-        break;
     }
 
     // @todo Use exceptions instead of CRM_Core_Error::fatal().
     if ($abort) {
       $data = htmlentities($data);
 
-      CRM_Core_Error::fatal("$data is not of the type $type");
+      throw new CRM_Core_Exception("$data is not of the type $type");
     }
     return NULL;
   }
index 6df6d5bddd40467b025262fdffffa1a64d95313d..47154d1f4d03fade0b25e3dbb0bbf3f4fd332397 100644 (file)
  */
 class CRM_Utils_Weight {
   /**
-   * @var array, list of GET fields which must be validated
+   * List of GET fields which must be validated
    *
    * To reduce the size of this patch, we only sign the exploitable fields
    * which make up "$baseURL" in addOrder() (eg 'filter' or 'dao').
    * Less-exploitable fields (eg 'dir') are left unsigned.
    * 'id','src','dst','dir'
+   * @var array
    */
   public static $SIGNABLE_FIELDS = ['reset', 'dao', 'idName', 'url', 'filter'];
 
@@ -418,13 +419,17 @@ class CRM_Utils_Weight {
     }
   }
 
+  /**
+   *
+   * @throws CRM_Core_Exception
+   */
   public static function fixOrder() {
     $signature = CRM_Utils_Request::retrieve('_sgn', 'String');
     $signer = new CRM_Utils_Signer(CRM_Core_Key::privateKey(), self::$SIGNABLE_FIELDS);
 
     // Validate $_GET values b/c subsequent code reads $_GET (via CRM_Utils_Request::retrieve)
     if (!$signer->validate($signature, $_GET)) {
-      CRM_Core_Error::fatal('Request signature is invalid');
+      throw new CRM_Core_Exception('Request signature is invalid');
     }
 
     // Note: Ensure this list matches self::$SIGNABLE_FIELDS
index 3b6b5a75ba5440b59ca1d1167b1bf9a2fecb1bb7..aa3655b8c7ab2e96f675e88b4e9e66d3c2db1652 100644 (file)
@@ -24,6 +24,8 @@ class Modules extends \CRM_Core_Page {
    * "civicrm/ajax/anulgar-modules" route).
    *
    * @deprecated
+   *
+   * @throws \CRM_Core_Exception
    */
   public function run() {
     /**
@@ -56,7 +58,7 @@ class Modules extends \CRM_Core_Page {
         break;
 
       default:
-        \CRM_Core_Error::fatal("Unrecognized format");
+        throw new \CRM_Core_Exception("Unrecognized format");
     }
 
     \CRM_Utils_System::civiExit();
index 3434316ac58dbf115d03fab9c88f5e143d326583..cf3323b5c10dcc63ba4db8ba7c8152996510a5b1 100644 (file)
@@ -204,7 +204,7 @@ class CiviContributeProcessor {
 
     $handle = fopen($csvFile, "r");
     if (!$handle) {
-      CRM_Core_Error::fatal("Can't locate csv file.");
+      throw new CRM_Core_Exception("Can't locate csv file.");
     }
 
     require_once "CRM/Contribute/BAO/Contribution/Utils.php";
@@ -231,7 +231,7 @@ class CiviContributeProcessor {
         CRM_Core_Error::debug_log_message("Considering first row ( line $row ) as HEADER ..<p>", TRUE);
 
         if (empty($header)) {
-          CRM_Core_Error::fatal("Header is empty.");
+          throw new CRM_Core_Exception("Header is empty.");
         }
       }
       $row++;
@@ -254,7 +254,7 @@ class CiviContributeProcessor {
           CRM_Core_DAO::$_nullObject, FALSE, 0, 'REQUEST'
         );
         if ($start < $end) {
-          CRM_Core_Error::fatal("Start offset can't be less than End offset.");
+          throw new CRM_Core_Exception("Start offset can't be less than End offset.");
         }
 
         $start = date('Y-m-d', time() - $start * 24 * 60 * 60) . 'T00:00:00.00Z';