CRM-12427 Fixes and patch
authorDeepak Srivastava <deepak.srivastava@webaccess.co.in>
Fri, 26 Apr 2013 10:23:06 +0000 (15:53 +0530)
committerDeepak Srivastava <deepak.srivastava@webaccess.co.in>
Fri, 26 Apr 2013 10:23:06 +0000 (15:53 +0530)
CRM/Activity/BAO/Activity.php
CRM/Contact/Form/Task/SMSCommon.php
CRM/Mailing/BAO/Job.php
tools/extensions/org.civicrm.sms.clickatell.zip
tools/extensions/org.civicrm.sms.clickatell/org_civicrm_sms_clickatell.php
tools/extensions/org.civicrm.sms.twilio.zip
tools/extensions/org.civicrm.sms.twilio/org_civicrm_sms_twilio.php

index 941e55c19ec54d4e71a9d0a70f69928afde6e19c..d28b76373d90a12db2816591c238ad305c27d7a0 100644 (file)
@@ -1499,7 +1499,8 @@ LEFT JOIN   civicrm_case_activity ON ( civicrm_case_activity.activity_id = tbl.a
     }
 
     $success = 0;
-    $escapeSmarty = $sent = FALSE;
+    $escapeSmarty = FALSE;
+    $errMsgs = array();
     foreach ($contactDetails as $values) {
       $contactId = $values['contact_id'];
 
@@ -1525,19 +1526,33 @@ LEFT JOIN   civicrm_case_activity ON ( civicrm_case_activity.activity_id = tbl.a
         $smsParams['To'] = '';
       }
 
-      if (self::sendSMSMessage(
-          $contactId,
-          $tokenText,
-          $tokenHtml,
-          $smsParams,
-          $activityID
-        )) {
-        // even a single successful delivery should set this falg to true
-        $sent = TRUE;
+      $sendResult = self::sendSMSMessage(
+        $contactId,
+        $tokenText,
+        $tokenHtml,
+        $smsParams,
+        $activityID
+      );
+
+      if (PEAR::isError($sendResult)) {
+        // Collect all of the PEAR_Error objects
+        $errMsgs[] = $sendResult;
+      } else {
         $success++;
       }
     }
 
+    // If at least one message was sent and no errors
+    // were generated then return a boolean value of TRUE.
+    // Otherwise, return FALSE (no messages sent) or
+    // and array of 1 or more PEAR_Error objects.
+    $sent = FALSE;
+    if ($success > 0 && count($errMsgs) == 0) {
+      $sent = TRUE;
+    } elseif (count($errMsgs) > 0) {
+      $sent = $errMsgs;
+    }
+
     return array($sent, $activity->id, $success);
   }
 
@@ -1548,7 +1563,7 @@ LEFT JOIN   civicrm_case_activity ON ( civicrm_case_activity.activity_id = tbl.a
    * @param int    $activityID        the activity ID that tracks the message
    * @param array  $smsParams         the params used for sending sms
    *
-   * @return boolean                  true if successfull else false.
+   * @return mixed                    true on success or PEAR_Error object
    * @access public
    * @static
    */
@@ -1579,7 +1594,11 @@ LEFT JOIN   civicrm_case_activity ON ( civicrm_case_activity.activity_id = tbl.a
     // make sure both phone are valid
     // and that the recipient wants to receive sms
     if (empty($toPhoneNumber) or $toDoNotSms) {
-      return FALSE;
+      return PEAR::raiseError(
+        'Recipient phone number is invalid or recipient does not want to receive SMS',
+        null,
+        PEAR_ERROR_RETURN
+      );
     }
 
     $message = $tokenHtml ? $tokenHtml : $tokenText;
@@ -1588,8 +1607,9 @@ LEFT JOIN   civicrm_case_activity ON ( civicrm_case_activity.activity_id = tbl.a
     $smsParams['parent_activity_id'] = $activityID;
 
     $providerObj = CRM_SMS_Provider::singleton(array('provider_id' => $smsParams['provider_id']));
-    if (!$providerObj->send($recipient, $smsParams, $message, NULL)) {
-      return FALSE;
+    $sendResult = $providerObj->send($recipient, $smsParams, $message, NULL);
+    if (PEAR::isError($sendResult)) {
+      return $sendResult;
     }
 
     // add activity target record for every sms that is send
index 79cbfd1aeae66f2d95518c577bec40e4559708d6..611e52a33bb031fb71b7850e573a8e2b29a40151 100644 (file)
@@ -402,29 +402,39 @@ class CRM_Contact_Form_Task_SMSCommon {
       $contactIds
     );
 
-    if ($sent) {
+    if ($countSuccess > 0) {
       CRM_Core_Session::setStatus(ts('One message was sent successfully.', array('plural' => '%count messages were sent successfully.', 'count' => $countSuccess)), ts('Message Sent', array('plural' => 'Messages Sent', 'count' => $countSuccess)), 'success');
     }
 
-    //Display the name and number of contacts for those sms is not sent.
-    $smsNotSent = array_diff_assoc($allContactIds, $contactIds);
-
-    if (!empty($smsNotSent)) {
-      $not_sent = array();
-      foreach ($smsNotSent as $index => $contactId) {
-        $displayName    = $form->_allContactDetails[$contactId]['display_name'];
-        $phone          = $form->_allContactDetails[$contactId]['phone'];
-        $contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=$contactId");
-        $not_sent[] = "<a href='$contactViewUrl' title='$phone'>$displayName</a>";
+    if (is_array($sent)) {
+      // At least one PEAR_Error object was generated.
+      // Display the error messages to the user.
+      $status = '<ul>';
+      foreach ($sent as $errMsg) {
+        $status .= '<li>' . $errMsg . '</li>';
       }
-      $status = '(' . ts('because no phone number on file or communication preferences specify DO NOT SMS or Contact is deceased');
-      if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Form_Task_SMS') {
-        $status .= ' ' . ts("or the contact is not part of the activity '%1'", array(1 => self::RECIEVED_SMS_ACTIVITY_SUBJECT));
+      $status .= '</ul>';
+      CRM_Core_Session::setStatus($status, ts('One Message Not Sent', array('count' => count($sent), 'plural' => '%count Messages Not Sent')), 'info');
+    } else {
+      //Display the name and number of contacts for those sms is not sent.
+      $smsNotSent = array_diff_assoc($allContactIds, $contactIds);
+
+      if (!empty($smsNotSent)) {
+        $not_sent = array();
+        foreach ($smsNotSent as $index => $contactId) {
+          $displayName    = $form->_allContactDetails[$contactId]['display_name'];
+          $phone          = $form->_allContactDetails[$contactId]['phone'];
+          $contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=$contactId");
+          $not_sent[] = "<a href='$contactViewUrl' title='$phone'>$displayName</a>";
+        }
+        $status = '(' . ts('because no phone number on file or communication preferences specify DO NOT SMS or Contact is deceased');
+        if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Form_Task_SMS') {
+          $status .= ' ' . ts("or the contact is not part of the activity '%1'", array(1 => self::RECIEVED_SMS_ACTIVITY_SUBJECT));
+        }
+        $status .= ')<ul><li>' . implode('</li><li>', $not_sent) . '</li></ul>';
+        CRM_Core_Session::setStatus($status, ts('One Message Not Sent', array('count' => count($smsNotSent), 'plural' => '%count Messages Not Sent')), 'info');
       }
-      $status .= ')<ul><li>' . implode('</li><li>', $not_sent) . '</li></ul>';
-      CRM_Core_Session::setStatus($status, ts('One Message Not Sent', array('count' => count($smsNotSent), 'plural' => '%count Messages Not Sent')), 'info');
     }
-
   }
 }
 
index 8c81602584ef9ae60c2ca6cf63d00e06aae954d4..46fa34c5bcf087c321495bc0e62e617f90b03bdc 100644 (file)
@@ -653,7 +653,8 @@ VALUES (%1, %2, %3, %4, %5, %6, %7)
         CRM_Core_Error::setCallback();
       }
 
-      if (is_a($result, 'PEAR_Error')) {
+      // FIXME: for now we skipping bounce handling for sms
+      if (is_a($result, 'PEAR_Error') && !$mailing->sms_provider_id) {
         // CRM-9191
         $message = $result->getMessage();
         if (strpos($message,
index 9730f743290abc4e3d58b287c5368068331877c7..b20af57445635e8a650ff2540c3b19dbfb26499c 100644 (file)
Binary files a/tools/extensions/org.civicrm.sms.clickatell.zip and b/tools/extensions/org.civicrm.sms.clickatell.zip differ
index 03a8cea3b277f44f6f61f3b472d6358092d14509..9330d372e57d9d22b6855bd7f586b4ba3fa8e0e1 100644 (file)
@@ -285,9 +285,8 @@ class org_civicrm_sms_clickatell extends CRM_SMS_Provider {
       }
       else {
         // TODO: Should add a failed activity instead.
-       
-        CRM_Core_Error::debug_log_message($response['data']  . " - for phone: {$postDataArray['to']}");
-        return;
+        CRM_Core_Error::debug_log_message($response['data'] . " - for phone: {$postDataArray['to']}");
+        return PEAR::raiseError($response['data'], null, PEAR_ERROR_RETURN);
       }
     }
   }
index 7c581aec36fb50207f2af6ad0cb13b7fe8f6dcc5..49a3e6df78ec823b4105fe7ad13a0e582b0872bc 100644 (file)
Binary files a/tools/extensions/org.civicrm.sms.twilio.zip and b/tools/extensions/org.civicrm.sms.twilio.zip differ
index a4eedc97db12afe1e3ca5698454b60d8b1d6f5ec..07fb7fde5e0900c0046ec401238126291ef800ac 100644 (file)
@@ -145,7 +145,7 @@ class org_civicrm_sms_twilio extends CRM_SMS_Provider {
    *
    * @param array the message with a to/from/text
    *
-   * @return mixed true on sucess or PEAR_Error object
+   * @return mixed true on success or PEAR_Error object
    * @access public
    */
   function send($recipients, $header, $message, $jobID = NULL) {
@@ -171,7 +171,14 @@ class org_civicrm_sms_twilio extends CRM_SMS_Provider {
         return $sid;
       }
       else {
-        return PEAR::raiseError($response['data']);
+        $errMsg = $send->RestException->Message
+          . ' For more information, see '
+          . $send->RestException->MoreInfo;
+        return PEAR::raiseError(
+          $errMsg,
+          null,
+          PEAR_ERROR_RETURN
+        );
       }
     }
   }
@@ -209,10 +216,10 @@ class org_civicrm_sms_twilio extends CRM_SMS_Provider {
     $response['http_code'] = curl_getinfo($this->_ch, CURLINFO_HTTP_CODE);
     
     if (empty($response['http_code'])) {
-      return PEAR::raiseError('No HTTP Status Code was returned.');
+      return PEAR::raiseError('No HTTP Status Code was returned.', null, PEAR_ERROR_RETURN);
     }
     elseif ($response['http_code'] === 0) {
-      return PEAR::raiseError('Cannot connect to the Twilio API Server.');
+      return PEAR::raiseError('Cannot connect to the Twilio API Server.', null, PEAR_ERROR_RETURN);
     }
 
     $response['data'] = $status;
@@ -220,4 +227,4 @@ class org_civicrm_sms_twilio extends CRM_SMS_Provider {
     
     return ($response);
   }
-}
\ No newline at end of file
+}