Fix for CRM-12391
authorDeepak Srivastava <deepak.srivastava@webaccess.co.in>
Mon, 22 Apr 2013 12:14:49 +0000 (17:44 +0530)
committerDeepak Srivastava <deepak.srivastava@webaccess.co.in>
Mon, 22 Apr 2013 12:14:49 +0000 (17:44 +0530)
CRM/Activity/BAO/Activity.php
CRM/Contact/Form/Task/SMSCommon.php
CRM/SMS/Provider.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 996379dbbe79ea38d45d93b2e0aa2d7b395b9825..941e55c19ec54d4e71a9d0a70f69928afde6e19c 100644 (file)
@@ -1498,6 +1498,7 @@ LEFT JOIN   civicrm_case_activity ON ( civicrm_case_activity.activity_id = tbl.a
       );
     }
 
+    $success = 0;
     $escapeSmarty = $sent = FALSE;
     foreach ($contactDetails as $values) {
       $contactId = $values['contact_id'];
@@ -1533,10 +1534,11 @@ LEFT JOIN   civicrm_case_activity ON ( civicrm_case_activity.activity_id = tbl.a
         )) {
         // even a single successful delivery should set this falg to true
         $sent = TRUE;
+        $success++;
       }
     }
 
-    return array($sent, $activity->id);
+    return array($sent, $activity->id, $success);
   }
 
   /**
index d21c14495f87217e90b335494439eb6e6075eaba..79cbfd1aeae66f2d95518c577bec40e4559708d6 100644 (file)
@@ -170,7 +170,7 @@ class CRM_Contact_Form_Task_SMSCommon {
       }
     }
 
-    if (is_array($form->_contactIds) && $toSetDefault) {
+    if (is_array($form->_contactIds) && !empty($form->_contactIds) && $toSetDefault) {
       $returnProperties = array(
         'sort_name' => 1,
         'phone' => 1,
@@ -393,26 +393,27 @@ class CRM_Contact_Form_Task_SMSCommon {
     $smsParams = $thisValues;
     unset($smsParams['text_message']);
     $smsParams['provider_id'] = $fromSmsProviderId;
+    $contactIds = array_keys($form->_contactDetails);
+    $allContactIds = array_keys($form->_allContactDetails);
 
-    list($sent, $activityId) = CRM_Activity_BAO_Activity::sendSMS($formattedContactDetails,
+    list($sent, $activityId, $countSuccess) = CRM_Activity_BAO_Activity::sendSMS($formattedContactDetails,
       $thisValues,
       $smsParams,
-      array_keys($form->_contactDetails)
+      $contactIds
     );
 
     if ($sent) {
-      $count_success = count($form->_contactDetails);
-      CRM_Core_Session::setStatus(ts('One message was sent successfully.', array('plural' => '%count messages were sent successfully.', 'count' => $count_success)), ts('Message Sent', array('plural' => 'Messages Sent', 'count' => $count_success)), 'success');
+      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($form->_allContactDetails, $form->_contactDetails);
+    $smsNotSent = array_diff_assoc($allContactIds, $contactIds);
 
     if (!empty($smsNotSent)) {
       $not_sent = array();
-      foreach ($smsNotSent as $contactId => $values) {
-        $displayName    = $values['display_name'];
-        $phone          = $values['phone'];
+      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>";
       }
index ae9cbeaee6408a6f390f43f21b1103aaec5c3355..3bcf023234539e5fd263d02d7ae83f7b9f76dd23 100644 (file)
@@ -159,7 +159,7 @@ INNER JOIN civicrm_mailing_job mj ON mj.mailing_id = m.id AND mj.id = %1";
     return $value;
   }
 
-  function inbound($from, $body, $to = NULL, $trackID = NULL) {
+  function processInbound($from, $body, $to = NULL, $trackID = NULL) {
        $formatFrom   = $this->formatPhone($this->stripPhone($from), $like, "like"); 
     $escapedFrom  = CRM_Utils_Type::escape($formatFrom, 'String');
     $fromContactID = CRM_Core_DAO::singleValueQuery('SELECT contact_id FROM civicrm_phone WHERE phone LIKE "' . $escapedFrom . '"');
index 6d8308ce37692a18aaa3ded976c3c6b90dd911bf..9730f743290abc4e3d58b287c5368068331877c7 100644 (file)
Binary files a/tools/extensions/org.civicrm.sms.clickatell.zip and b/tools/extensions/org.civicrm.sms.clickatell.zip differ
index 6aeeb5d23e8d92437e7e4086329cddd99be687dc..03a8cea3b277f44f6f61f3b472d6358092d14509 100644 (file)
@@ -286,7 +286,7 @@ 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']);
+        CRM_Core_Error::debug_log_message($response['data']  . " - for phone: {$postDataArray['to']}");
         return;
       }
     }
@@ -385,7 +385,7 @@ class org_civicrm_sms_clickatell extends CRM_SMS_Provider {
     $fromPhone = $this->retrieve('from', 'String');
     $fromPhone = $this->formatPhone($this->stripPhone($fromPhone), $like, "like");
 
-    return parent::inbound($fromPhone, $this->retrieve('text', 'String'), NULL, $this->retrieve('moMsgId', 'String'));
+    return parent::processInbound($fromPhone, $this->retrieve('text', 'String'), NULL, $this->retrieve('moMsgId', 'String'));
   }
 
   /**
index eba3894bb3d79a511a64034292bc8fc781e79927..7c581aec36fb50207f2af6ad0cb13b7fe8f6dcc5 100644 (file)
Binary files a/tools/extensions/org.civicrm.sms.twilio.zip and b/tools/extensions/org.civicrm.sms.twilio.zip differ
index 783ea757e33882491e61a59b33aacf60f1d9ead9..a4eedc97db12afe1e3ca5698454b60d8b1d6f5ec 100644 (file)
@@ -183,7 +183,7 @@ class org_civicrm_sms_twilio extends CRM_SMS_Provider {
   function inbound() {
     $like      = "";
     $fromPhone = $this->retrieve('From', 'String');
-    return parent::inbound($fromPhone, $this->retrieve('Body', 'String'), NULL, $this->retrieve('SmsSid', 'String'));
+    return parent::processInbound($fromPhone, $this->retrieve('Body', 'String'), NULL, $this->retrieve('SmsSid', 'String'));
   }
   
   /**