From f45a42ba1547d9489c208d9dd210682f26d7af4a Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 4 Jul 2019 11:33:51 +1200 Subject: [PATCH] [REF] extract portion that creates the custom field record --- CRM/Core/BAO/CustomField.php | 58 ++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index e28e0fcd90..8d23280394 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -152,30 +152,9 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { * @return CRM_Core_DAO_CustomField */ public static function create($params) { - $transaction = new CRM_Core_Transaction(); - $params = self::prepareCreate($params); - - $customField = new CRM_Core_DAO_CustomField(); - $customField->copyValues($params); - $customField->save(); - - $indexExist = empty($params['id']) ? FALSE : CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable'); - - //create/drop the index when we toggle the is_searchable flag + $customField = self::createCustomFieldRecord($params); $op = empty($params['id']) ? 'add' : 'modify'; - if ($op !== 'modify') { - if ($params['is_append_field_id_to_column_name']) { - $params['column_name'] .= "_{$customField->id}"; - } - $customField->column_name = $params['column_name']; - $customField->save(); - } - - // 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); + $indexExist = empty($params['id']) ? FALSE : CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable'); self::createField($customField, $op, $indexExist, CRM_Utils_Array::value('triggerRebuild', $params, TRUE)); CRM_Utils_Hook::post(($op === 'add' ? 'create' : 'edit'), 'CustomField', $customField->id, $customField); @@ -1965,6 +1944,39 @@ WHERE id IN ( %1, %2 ) return $params; } + /** + * Create database entry for custom field and related option groups. + * + * @param array $params + * + * @return CRM_Core_DAO_CustomField + */ + protected static function createCustomFieldRecord($params) { + $transaction = new CRM_Core_Transaction(); + $params = self::prepareCreate($params); + + $customField = new CRM_Core_DAO_CustomField(); + $customField->copyValues($params); + $customField->save(); + + //create/drop the index when we toggle the is_searchable flag + $op = empty($params['id']) ? 'add' : 'modify'; + if ($op !== 'modify') { + if ($params['is_append_field_id_to_column_name']) { + $params['column_name'] .= "_{$customField->id}"; + } + $customField->column_name = $params['column_name']; + $customField->save(); + } + + // 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); + return $customField; + } + /** * Move custom data from one contact to another. * -- 2.25.1