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

dev/core#502 fix bug on sorting by address fields when viewing search results by profile #13884

Merged
merged 1 commit into from
Mar 25, 2019

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Mar 24, 2019

Overview

Fixes a bug whereby a fatal error occurs if you attempt to export contacts after sorting by postal_code from a search profile

Before

Steps to reproduce:

Create a profile with e.g. the postal code field of the primary address
Perform a contact search using this profile for displaying the results
Sort the result by the postal code field
Tick the "all # records" radio button
Choose any action to perform on the result (e.g. "Print PDF document")

  • fatal error

After

works

Technical Details

@mattwire @jitendrapurohit I figured I'd fix this related bug before closing out this cleanup / fix up round. I note that there is still some obvious cleanup in the function to be done (consolidate orderBy & orderByArray, get rid of the switch) but I think those are also soooo obvious they could be left until next time someone touches that code

Comments

https://lab.civicrm.org/dev/core/issues/502

@civibot
Copy link

civibot bot commented Mar 24, 2019

(Standard links)

@civibot civibot bot added the master label Mar 24, 2019
$this->_element["{$tName}_id"] = 1;
$addressJoin = "\nLEFT JOIN civicrm_address $aName ON ($aName.contact_id = contact_a.id AND $aName.$lCond)";
$this->_tables[$tName] = $addressJoin;
list($aName, $addressJoin) = $this->addAddressTable($name, $lCond);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

extract this so we can re-use it from orderBy

FALSE, FALSE
);
return $value;
return $query->searchQuery(0, 0, $sort);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just removing passing of default values in this flow

… results by profile

Fixes a bug whereby a fatal error occurs if you attempt to export contacts after sorting by postal_code from
an search profile
@@ -1014,9 +1014,9 @@ public function addHierarchicalElements() {

foreach ($this->_returnProperties['location'] as $name => $elements) {
$lCond = self::getPrimaryCondition($name);
$locationTypeId = is_numeric($name) ? NULL : array_search($name, $locationTypes);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This just moves the line & makes it clearer how it is calculated. I didn't change usage of this var elsewhere in this PR n the end

if (empty($fieldSpec) && substr($field, 0, 2) === '1-') {
$fieldSpec = $this->getMetadataForField(substr($field, 2));
$this->addAddressTable('1-' . str_replace('civicrm_', '', $fieldSpec['table_name']), 'is_primary = 1');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Have tested the complete changes and confirm that it works fine on profile search through advanced search.

Maybe, if we extend the above condition to also support for primary location type "names" eg Home-, this will also fix the same problem in search builder? @eileenmcnaughton

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jitendrapurohit yeah - do we still have that problem in search builder or is it fixed now?

I'd rather not fix anything in this area without adding test cover so if we do still have a problem I think that would be better as a follow up

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah - do we still have that problem in search builder or is it fixed now?

We do have them, and it exists after this PR too. But can be fixed if the solution for Home- type is extended. There also seems to be other issues with address field search, eg

Advanced search -> select search profile -> select loc type = non primary -> search -> Error.

But I concur it also errors before this PR so these changes are better in than out as it fixes the main issue with profile search sorting 👍

@eileenmcnaughton eileenmcnaughton merged commit 1f1b3ba into civicrm:master Mar 25, 2019
@eileenmcnaughton eileenmcnaughton deleted the search_lastish branch March 25, 2019 07:17
@eileenmcnaughton
Copy link
Contributor Author

thanks @jitendrapurohit I might do one more PR to rip out that redundant switch if you are ok to review it?

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.

2 participants