Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-8000

saved search with no criteria triggers errors

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Duplicate
    • Affects Version/s: 3.3.5, 3.3.6
    • Fix Version/s: 3.4.3
    • Component/s: None
    • Labels:
      None

      Description

      this is admittedly a fringe issue...

      if you create a saved search with no criteria (i.e. all contacts), it can cause unexpected errors downstream when its used. here's the flow and use case:

      Contact_BAO_SavedSearch::contactIDsSQL($id) is called early in the process, which calls:
      self::getSearchParams($id)
      > if that call returns no value we get the fatal error "No contactID clause"

      getSearchParams retrieves the form values, then runs it through:
      CRM_Contact_BAO_Query::convertFormValues( $fv ) which calls fixWhereValues()

      anyway, long and short is that the formValues will only contain the metadata and empty field values, which means fixWhereValues and convertFormValues returns null, and we get the error above. here's a sample print_r of $fv

      Array
      (
      [qfKey] => 2aaf8aa6d38288a8ed393f321569fbd1_6382
      [sort_name] =>
      [contact_type] =>
      [group] =>
      [tag] =>
      [task] => 13
      [radio_ts] => ts_all
      [uf_group_id] => 11
      [component_mode] => 1
      )

      fixWhereValues ignores qfKey, task, ts_all, uf_group_id, component_mode

      so basically, if we use this saved search where contactIDsSQL is called, it breaks things.

      I ran into this because this saved search was used on the Include/Exclude Group/Tag custom search (Group.php). end user wanted to include all contacts and then exclude specific groups. yes – they don't technically need to do that – they could just leave the include groups box empty and it assumes all. but the saved search is valid, so this returns an unexpected error regardless.

      further, it looks like that function is called when processing groups for mailings – which could be a very legitimate reason to create an "all records in db" group (for inclusion in the mailing). there are also a few other custom searches uses that method.

      since this is kind of a special situation, it may be sufficient to ask if there is any criteria when a saved search is being saved, and if not, to add "%" to the sort_name field. a bit hackish, but it would work.

        Attachments

          Activity

            People

            • Assignee:
              lobo Donald A. Lobo
              Reporter:
              lcdweb Brian Shaughnessy
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: