Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21405 Allow "Outbound SMS" when Mobile is not primary phone number #11252

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions CRM/Activity/Form/ActivityLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,22 @@ public static function commonBuildQuickForm($self) {
continue;
}
// Check for existence of a mobile phone and ! do not SMS privacy setting
$mobileTypeID = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'phone_type_id', 'Mobile');
list($name, $phone, $doNotSMS) = CRM_Contact_BAO_Contact_Location::getPhoneDetails($contactId, $mobileTypeID);
if (!$doNotSMS && $phone) {
try {
$phone = civicrm_api3('Phone', 'getsingle', array(
'contact_id' => $contactId,
'phone_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'phone_type_id', 'Mobile'),
'return' => array('phone', 'contact_id'),
'options' => array('limit' => 1, 'sort' => "is_primary DESC"),
'api.Contact.getsingle' => array(
'id' => '$value.contact_id',
'return' => 'do_not_sms',
),
));
}
catch (CiviCRM_API3_Exception $e) {
continue;
}
if (!$phone['api.Contact.getsingle']['do_not_sms'] && $phone['phone']) {
Copy link
Member

@monishdeb monishdeb Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this doesn't throw notice errors as it will hit continue before that, at line 94 if $phone is empty

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the contact does not have a phone, then getsingle will indeed throw an exception which will get caught, so no notice will be shown. I ran the code to check that this actually happened.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool 👍

$url = 'civicrm/activity/sms/add';
}
else {
Expand Down
2 changes: 2 additions & 0 deletions CRM/Contact/BAO/Contact/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public static function getEmailDetails($id, $isPrimary = TRUE, $locationTypeID =
}

/**
* @deprecated Not used anywhere, use the Phone API instead
* Get the sms number and display name of a contact.
*
* @param int $id
Expand All @@ -84,6 +85,7 @@ public static function getEmailDetails($id, $isPrimary = TRUE, $locationTypeID =
* tuple of display_name and sms if found, or (null,null)
*/
public static function getPhoneDetails($id, $type = NULL) {
Civi::log()->warning('Deprecated function CRM_Contact_BAO_Contact_Location::getPhoneDetails, use Phone.get API instead', array('civi.tag' => 'deprecated'));
if (!$id) {
return array(NULL, NULL);
}
Expand Down