Merge remote-tracking branch 'upstream/4.5' into 4.5-4.6-2015-03-16-17-24-33
authorkurund <kurund@civicrm.org>
Mon, 16 Mar 2015 11:54:51 +0000 (17:24 +0530)
committerkurund <kurund@civicrm.org>
Mon, 16 Mar 2015 11:54:51 +0000 (17:24 +0530)
CRM/Contact/BAO/ContactType.php
CRM/Core/BAO/CustomField.php
CRM/Upgrade/Incremental/php/FourFive.php [changed mode: 0644->0755]

index 789e7baa5542a7562c39710d851cdf92d676516b..7828a39c0d5090f83ce93a23ce1c5ac35e0b1e42 100644 (file)
@@ -386,6 +386,7 @@ WHERE  type.name IS NOT NULL
 
     $argString = $all ? 'CRM_CT_GSE_1' : 'CRM_CT_GSE_0';
     $argString .= $isSeparator ? '_1' : '_0';
+    $argString .= $separator;
     if (!array_key_exists($argString, $_cache)) {
       $cache = CRM_Utils_Cache::singleton();
       $_cache[$argString] = $cache->get($argString);
index 3a57e99bdf8fe6594b45dac0da3e1f8528167dd6..432bd3d27d0b3fa44d093e1e08be63da0bc59565 100644 (file)
@@ -1317,7 +1317,15 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
         break;
 
       case 'File':
-        if ($value) {
+        // In the context of displaying a profile, show file/image
+        if ($contactID && $value) {
+          $url = self::getFileURL($contactID, $fieldID, $value);
+          if ($url) {
+            $display = $url['file_url'];
+          }
+        }
+        // In other contexts show a paperclip icon
+        elseif ($value) {
           $icons = CRM_Core_BAO_File::paperIconAttachment('*', $value);
           $display = $icons[$value];
         }
old mode 100644 (file)
new mode 100755 (executable)
index e6dc429..8693259
@@ -312,6 +312,85 @@ DROP KEY `{$dao->CONSTRAINT_NAME}`";
     return TRUE;
   }
 
+  /**
+   * Upgrade function.
+   *
+   * @param string $rev
+   */
+  public function upgrade_4_5_9($rev) {
+    // Task to process sql.
+    $this->addTask(ts('Upgrade DB to 4.5.9: Fix saved searches consisting of multi-choice custom field(s)'), 'updateSavedSearch');
+
+    return TRUE;
+  }
+
+  /**
+   * Update saved search for multi-select custom fields on DB upgrade
+   *
+   * @param CRM_Queue_TaskContext $ctx
+   *
+   * @return bool TRUE for success
+   */
+  static function updateSavedSearch(CRM_Queue_TaskContext $ctx) {
+    $sql = "SELECT id, form_values FROM civicrm_saved_search";
+    $dao = CRM_Core_DAO::executeQuery($sql);
+    while ($dao->fetch()) {
+      $copy = $formValues = unserialize($dao->form_values);
+      $update = FALSE;
+      foreach ($copy as $field => $data_value) {
+        if (preg_match('/^custom_/', $field) && is_array($data_value) && !array_key_exists("${field}_operator", $formValues)) {
+          // Now check for CiviCRM_OP_OR as either key or value in the data_value array.
+          // This is the conclusive evidence of an old-style data format.
+          if(array_key_exists('CiviCRM_OP_OR', $data_value) || FALSE !== array_search('CiviCRM_OP_OR', $data_value)) {
+            // We have old style data. Mark this record to be updated.
+            $update = TRUE;
+            $op = 'and';
+            if(!preg_match('/^custom_([0-9]+)/', $field, $matches)) {
+              // fatal error?
+              continue;
+            }
+            $fieldID= $matches[1];
+            if (array_key_exists('CiviCRM_OP_OR', $data_value)) {
+              // This indicates data structure identified by jamie in the form:
+              // value1 => 1, value2 => , value3 => 1.
+              $data_value = array_keys($data_value, 1); 
+
+              // If CiviCRM_OP_OR - change OP from default to OR
+              if($data_value['CiviCRM_OP_OR'] == 1) {
+                $op = 'or';
+              }
+              unset($data_value['CiviCRM_OP_OR']);
+            }
+            else {
+              // The value is here, but it is not set as a key.
+              // This is using the style identified by Monish - the existence of the value
+              // indicates an OR search and values are set in the form of:
+              // 0 => value1, 1 => value1, 3 => value2.
+              $key = array_search('CiviCRM_OP_OR', $data_value);
+              $op = 'or';
+              unset($data_value[$key]);
+            }
+     
+            $formValues[$field] = $data_value;
+            $formValues["${field}_operator"] = $op;
+          }
+        }
+      }
+
+      if($update) { 
+        $sql = "UPDATE civicrm_saved_search SET form_values = %0 WHERE id = %1";
+        CRM_Core_DAO::executeQuery($sql,
+          array(
+            array(serialize($formValues), 'String'),
+            array($dao->id, 'Integer'),
+          )
+        );
+      }
+    }
+    return TRUE;
+  }
+
+
   /**
    * (Queue Task Callback)
    */