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

Conversation

mattwire
Copy link
Contributor

@mattwire mattwire commented Nov 8, 2017

Overview

Allow "Outbound SMS" when Mobile is not primary phone number

Before

When a contact has a mobile phone number but it is not the primary number the "Outbound SMS" action is removed from the contact actions.

After

When a contact has a mobile phone number but it is not the primary number the "Outbound SMS" action is allowed, and will use the first available mobile number from the contact.


@mattwire mattwire changed the title Allow "Outbound SMS" when Mobile is not primary phone number CRM-21405 Allow "Outbound SMS" when Mobile is not primary phone number Nov 8, 2017
@mattwire
Copy link
Contributor Author

mattwire commented Nov 8, 2017

@JKingsnorth Are you able to review this please?

@mattwire mattwire force-pushed the CRM-21405_outboundsms_mobile_notprimary branch from 1892bdd to 8a7d7a4 Compare November 8, 2017 11:59
@mattwire
Copy link
Contributor Author

Jenkins test this please

@mattwire
Copy link
Contributor Author

mattwire commented Feb 6, 2018

@JKingsnorth @monishdeb @michaelmcandrew Be great if we could get this simple SMS PR reviewed/merged :-)

@michaelmcandrew
Copy link
Contributor

Hi @mattwire

I did some manual UI testing on this. Here are the results in the format "Conditions -> Could I see the outbound SMS action?"

  • No mobile number - No
  • Primary mobile number - Yes
  • Secondary mobile number - Yes
  • Primary mobile number + DO NOT SMS - No
  • Secondary mobile number + DO NOT SMS - No

So it looks like it is working nicely.

I presume that the following section is API chaining but I am slightly baffled as to how it works. I would have thought that if you want to get a field from the contact entity, you need to reference the contact entity somewhere.

$phone = civicrm_api3('Phone', 'getsingle', array(
  'return' => array("contact_id.do_not_sms", "phone"),
  'phone_type_id' => $mobileTypeID,
  'contact_id' => $contactId,
  'options' => array('limit' => 1, 'sort' => "is_primary DESC"),

Maybe the phone API is randomly returning some fields from the contact. Or maybe it is a documented feature that I am not aware of.

On the one hand, I am hesitant to suggest modifying code that works / passes the manual testing I did.

On the other hand, if this is an undocumented way of using the phone API that is not guaranteed to work in the future, it would be good to change it.

Do you have any ideas about that?

@michaelmcandrew
Copy link
Contributor

@mattwire - I rewrote the api call to use explicit chaining - let me know what you think.

@mattwire
Copy link
Contributor Author

@michaelmcandrew That's fine - happy with your changes. I think both work :-) So, do you think this is good to merge?

try {
$phone = civicrm_api3('Phone', 'getsingle', array(
'contact_id' => $contactId,
'phone_type_id' => $mobileTypeID,
Copy link
Member

Choose a reason for hiding this comment

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

Please use

-  'phone_type_id' => $mobileTypeID,
+ 'phone_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'phone_type_id', 'Mobile'),

as I can see $mobileTypeID isn't used anywhere else

Copy link
Contributor

Choose a reason for hiding this comment

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

looks good

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 👍

@monishdeb
Copy link
Member

Apart from the minor change mentioned in the patch and based on @michaelmcandrew feedback, this PR good to merge. Will it be possible to replicate this behavior in a unit test?

@michaelmcandrew
Copy link
Contributor

michaelmcandrew commented Feb 15, 2018 via email

@michaelmcandrew
Copy link
Contributor

Sorry @monishdeb, I sent that previous message from my email and had not seen your message - have replied now.

@monishdeb
Copy link
Member

@michaelmcandrew no problem and thanks for your quick response. @mattwire can you please make the minor change mentioned in the patch?

@mattwire mattwire force-pushed the CRM-21405_outboundsms_mobile_notprimary branch from 304e9ce to c9184ed Compare February 16, 2018 09:06
@mattwire
Copy link
Contributor Author

@monishdeb I've made the changes as requested. Merge on pass?

@monishdeb
Copy link
Member

Absolutely 👍

@monishdeb monishdeb merged commit 56715f8 into civicrm:master Feb 16, 2018
@mlutfy mlutfy added this to the 4.7.32 milestone Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants