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-21214 Fix crashes when 'null' string is passed in via API #11324

Merged
merged 1 commit into from
Nov 25, 2017

Conversation

mattwire
Copy link
Contributor

@mattwire mattwire commented Nov 24, 2017

Overview

This is a followup fix for the changes made in #11019.

Before

When using Address.create API with master_id = 'null' (string) CiviCRM crashes.

After

When using Address.create API with master_id = 'null' (string) CiviCRM does not crash.

Technical Details

The string 'null' is passed in via the CiviCRM API and we need to catch that otherwise SQL functions crash as they are expecting an integer.

@colemanw As merger of the original PR (#11019) could you take a look at this?


@@ -153,7 +153,7 @@ public static function add(&$params, $fixAddress) {
}

// (prevent chaining 1 and 3) CRM-21214
if (CRM_Utils_Array::value('master_id', $params)) {
if (!CRM_Utils_System::isNull($params['master_id'])) {
Copy link
Member

Choose a reason for hiding this comment

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

Changing CRM_Utils_Array::value to CRM_Utils_System::isNull has another implication in that php will throw a warning if the array item is not set at all. To avoid this do

if (isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cheers, updated.

@mattwire mattwire force-pushed the CRM-21214_followup_fix_crashes branch 2 times, most recently from c42166b to c320f13 Compare November 24, 2017 17:50
@@ -537,7 +537,7 @@ public static function &getValues($entityBlock, $microformat = FALSE, $fieldName
$values['display'] = $address->display;
$values['display_text'] = $address->display_text;

if (is_numeric($address->master_id)) {
if (isset($params['master_id']) && !CRM_Utils_System::isNull($address->master_id)) {
Copy link
Member

Choose a reason for hiding this comment

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

Wait now you've changed the meaning of this conditional. Are you sure about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No... I've fixed that now.

@mattwire mattwire force-pushed the CRM-21214_followup_fix_crashes branch from c320f13 to 6b60d8a Compare November 25, 2017 09:45
@colemanw colemanw merged commit 72e2879 into civicrm:master Nov 25, 2017
sluc23 pushed a commit to ixiam/civicrm-core that referenced this pull request Jan 10, 2018
…_crashes

CRM-21214 Fix crashes when 'null' string is passed in via API
@mattwire mattwire deleted the CRM-21214_followup_fix_crashes branch January 17, 2018 13:11
urlisse added a commit to coopsymbiotic/webform_civicrm that referenced this pull request Mar 20, 2018
This fixes the issue of address fields that won't update with CiviCRM 4.7.28. Maybe some other changes are still required regarding this module's usage of null values. 

However, it seems that core is set to also accept `'null'` strings soon along with `NULL` values... 

https://www.drupal.org/project/webform_civicrm/issues/2948459
civicrm/civicrm-core#11324
@JKingsnorth
Copy link
Contributor

@mattwire Thanks very much for this, we just ran aground on this, and your fix is greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants