[REF] further simplification of custom field create action
authoreileen <emcnaughton@wikimedia.org>
Mon, 1 Jul 2019 23:43:45 +0000 (11:43 +1200)
committereileen <emcnaughton@wikimedia.org>
Thu, 4 Jul 2019 21:46:28 +0000 (09:46 +1200)
CRM/Core/BAO/CustomField.php

index 88732fddc30268284c9037fc9bc2bb99b4bb94ea..6011f179c270491f5576a5c0a5fc07dac9202c04 100644 (file)
@@ -160,35 +160,25 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     $customField->copyValues($params);
     $customField->save();
 
-    // make sure all values are present in the object for further processing
-    $customField->find(TRUE);
+    $indexExist = empty($params['id']) ? FALSE : CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable');
 
-    $triggerRebuild = CRM_Utils_Array::value('triggerRebuild', $params, TRUE);
     //create/drop the index when we toggle the is_searchable flag
     $op = empty($params['id']) ? 'add' : 'modify';
-    if ($op == 'modify') {
-      $indexExist = FALSE;
-      //as during create if field is_searchable we had created index.
-      if (!empty($params['id'])) {
-        $indexExist = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable');
-      }
-      self::createField($customField, $op, $indexExist, $triggerRebuild);
-    }
-    else {
+    if ($op !== 'modify') {
       if (!isset($origParams['column_name'])) {
         $params['column_name'] .= "_{$customField->id}";
       }
       $customField->column_name = $params['column_name'];
       $customField->save();
-      // make sure all values are present in the object
-      $customField->find(TRUE);
-
-      self::createField($customField, $op, FALSE, $triggerRebuild);
     }
 
-    // complete transaction
+    // complete transaction - note that any table alterations include an implicit commit so this is largely meaningless.
     $transaction->commit();
 
+    // make sure all values are present in the object for further processing
+    $customField->find(TRUE);
+    self::createField($customField, $op, $indexExist, CRM_Utils_Array::value('triggerRebuild', $params, TRUE));
+
     CRM_Utils_Hook::post(($op === 'add' ? 'create' : 'edit'), 'CustomField', $customField->id, $customField);
 
     CRM_Utils_System::flushCache();