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

Fix metadata on cancel_reason so it is an exportable field #12775

Merged
merged 1 commit into from Nov 8, 2018

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

Make cancel_reason searchable

Before

contribution search ignore the cancel_reason critieria

After

filter applied
screenshot 2018-09-05 17 46 23

Technical Details

This is an alternative to #12761 - it turns out the reason the default clause is not working is the field is not declared as 'exportable'.

I did consider adding a unique name in the xml but the unit test added when the field was added to the form used 'cancel_reason' so I switched the form field to have that name. As it was not previously working no smart groups will be harmed

Comments

@eileenmcnaughton
Copy link
Contributor Author

test this please

@sluc23
Copy link
Contributor

sluc23 commented Nov 5, 2018

@eileenmcnaughton I've tested this PR and confirm it works as expected in Contribution / Advanced Search and Builder for cancel_reason field using operators = and LIKE.

But IN operator returns and error

   [info] $Fatal Error Details = Array
(
    [callback] => Array
        (
            [0] => CRM_Core_Error
            [1] => handle
        )

    [code] => -2
    [message] => DB Error: syntax error
    [mode] => 16
    [debug_info] => SELECT DISTINCT UPPER(LEFT(contact_a.sort_name, 1)) as sort_name  FROM civicrm_contact contact_a LEFT JOIN civicrm_contribution ON civicrm_contribution.contact_id = contact_a.id  WHERE  (  ( civicrm_contribution.financial_type_id IN ("3", "1", "4", "2") AND civicrm_contribution.cancel_reason IN '' )  )  AND (contact_a.is_deleted = 0)    ORDER BY UPPER(LEFT(contact_a.sort_name, 1)) asc  [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' )  )  AND (contact_a.is_deleted = 0)    ORDER BY UPPER(LEFT(contact_a.sort_na' at line 1]
    [type] => DB_Error
    [user_info] => SELECT DISTINCT UPPER(LEFT(contact_a.sort_name, 1)) as sort_name  FROM civicrm_contact contact_a LEFT JOIN civicrm_contribution ON civicrm_contribution.contact_id = contact_a.id  WHERE  (  ( civicrm_contribution.financial_type_id IN ("3", "1", "4", "2") AND civicrm_contribution.cancel_reason IN '' )  )  AND (contact_a.is_deleted = 0)    ORDER BY UPPER(LEFT(contact_a.sort_name, 1)) asc  [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' )  )  AND (contact_a.is_deleted = 0)    ORDER BY UPPER(LEFT(contact_a.sort_na' at line 1]
    [to_string] => [db_error: message="DB Error: syntax error" code=-2 mode=callback callback=CRM_Core_Error::handle prefix="" info="SELECT DISTINCT UPPER(LEFT(contact_a.sort_name, 1)) as sort_name  FROM civicrm_contact contact_a LEFT JOIN civicrm_contribution ON civicrm_contribution.contact_id = contact_a.id  WHERE  (  ( civicrm_contribution.financial_type_id IN ("3", "1", "4", "2") AND civicrm_contribution.cancel_reason IN '' )  )  AND (contact_a.is_deleted = 0)    ORDER BY UPPER(LEFT(contact_a.sort_name, 1)) asc  [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' )  )  AND (contact_a.is_deleted = 0)    ORDER BY UPPER(LEFT(contact_a.sort_na' at line 1]"]
)

@eileenmcnaughton
Copy link
Contributor Author

@sluc23 it was trashing the data by applying trim to an array - see https://github.com/civicrm/civicrm-core/pull/12775/files#diff-0a639f0cf282805e238274495195e6a4R509

(I don't actually know that is a good place for trim anyway - I think the form layer & api layer do it and the lower layer may do too but that is an aside)

@sluc23
Copy link
Contributor

sluc23 commented Nov 5, 2018

@eileenmcnaughton now it works as expected with IN operator too. Tx for fixing this issue
I'll close #12761 referencing this one

This means it is available for searching
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants