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

saved searches that use multi-select custom groups break during 4.4 -> 4.5 upgrade

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.5.5
    • Fix Version/s: 4.6
    • Component/s: Core CiviCRM
    • Labels:
      None
    • Documentation Required?:
      None

      Description

      This seems to be a regression caused by CRM-15061.

      CRM-15061 creates a new data structure, as saved in the civicrm_saved_search form_values field, for custom group/multi-select fields:

      custom_NN = array('value1', 'value4', 'value5');
      custon_NN_operator = 'or'

      In 4.4, the data structure is:

      custom_NN = array(
      'value1' => 1,
      'value2' =>
      'value3' =>
      'value4' => 1,
      'value5' => 1
      'CiviCRM_OP_OR' => 1
      )

      The 4.5 code properly saves new searches using the new data structure, but smart groups that have saved searches made during 4.4 still have the old structure which is incompatible with the new structure.

      One option is to change the code to auto-detect which data structure is coming in. But that seems like it will simply preserve cruft we could do with out.

      Here's some code that updates the saved search table converting to the new structure. I think this should be carefully reviewed since it could result in data loss:

      $sql = "SELECT id, form_values FROM civicrm_saved_search";
      $dao = CRM_Core_DAO::executeQuery($sql);
      while($dao->fetch()) {
      echo "Considering " . $dao->id . "\n";
      $new = $data = unserialize($dao->form_values);
      $update = FALSE;
      while(list($field, $data_value) = each($data)) {
      if(preg_match('/^custom_/', $field) && is_array($data_value)) {
      if(array_key_exists('CiviCRM_OP_OR', $data_value)) {
      // This indicates old-style data format. We need to fix it.
      $update = TRUE;
      $new_value = array();
      $op = 'and';
      if($data_value['CiviCRM_OP_OR'] == 1)

      { $op = 'or'; }

      while(list($k, $v) = each($data_value)) {
      if($v == 1)

      { $new_value[] = $k; }

      }
      // Overwrite old value.
      $new[$field] = $new_value;
      // Add new key for the operator.
      $new["$

      {field}

      _operator"] = $op;
      }
      }
      }
      if($update)

      { echo "Updating " . $dao->id . "\n"; $new = serialize($new); $sql = "UPDATE civicrm_saved_search SET form_values = %0 WHERE id = %1"; $params = array( 0 => array($new, 'String'), 1 => array($dao->id, 'Integer') ); CRM_Core_DAO::executeQuery($sql, $params); }

      }

        Attachments

          Activity

            People

            • Assignee:
              monish.deb Monish Deb
              Reporter:
              jamie Jamie McClelland
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: