diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index f4bfaab87cb7..705d3ec1568d 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -1177,7 +1177,6 @@ public static function &getGroupDetail($groupId = NULL, $searchable = NULL, &$ex * @deprecated since 5.71, will be removed around 5.85 */ public static function &getActiveGroups($entityType, $path, $cidToken = '%%cid%%') { - CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_BAO_CustomGroup::getPermitted'); // for Group's $customGroupDAO = new CRM_Core_DAO_CustomGroup(); @@ -1185,7 +1184,7 @@ public static function &getActiveGroups($entityType, $path, $cidToken = '%%cid%% $customGroupDAO->whereAdd("style IN ('Tab', 'Tab with table')"); $customGroupDAO->whereAdd("is_active = 1"); - // add whereAdd for entity type + // Emits a noisy deprecation notice self::_addWhereAdd($customGroupDAO, $entityType, $cidToken); $groups = []; @@ -1233,9 +1232,7 @@ public static function getTableNameByEntityName($entityType) { } /** - * Get a list of custom groups which extend a given entity type. - * If there are custom-groups which only apply to certain subtypes, - * those WILL be included. + * @deprecated since 5.71 will be removed around 5.85 * * @param string $entityType * @@ -1243,22 +1240,16 @@ public static function getTableNameByEntityName($entityType) { */ public static function getAllCustomGroupsByBaseEntity($entityType) { $customGroupDAO = new CRM_Core_DAO_CustomGroup(); + // Emits a noisy deprecation notice self::_addWhereAdd($customGroupDAO, $entityType, NULL, TRUE); return $customGroupDAO; } /** - * Add the whereAdd clause for the DAO depending on the type of entity - * the custom group is extending. - * - * @param object $customGroupDAO - * @param string $entityType - * What entity are we extending here ?. - * - * @param int $entityID - * @param bool $allSubtypes + * @deprecated since 5.71 will be removed around 5.85 */ private static function _addWhereAdd(&$customGroupDAO, $entityType, $entityID = NULL, $allSubtypes = FALSE) { + CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_BAO_CustomGroup::getFiltered'); $addSubtypeClause = FALSE; // This function isn't really accessible with user data but since the string // is not passed as a param to the query CRM_Core_DAO::escapeString seems like a harmless @@ -1522,7 +1513,7 @@ public static function setDefaults(&$groupTree, &$defaults, $viewMode = FALSE, $ } /** - * Old function only called from one place... + * @deprecated function only called from one place... * @see CRM_Dedupe_Finder::formatParams * * @param array $groupTree diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index d527e21b6dfc..cee6d0c17b36 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -640,6 +640,9 @@ public static function formatFieldValues(array &$fieldValues) { * @return mixed */ protected static function formatFieldValue($value, ?array $fieldSpec) { + if ($value === '') { + return NULL; + } if (!isset($value) || !isset($fieldSpec)) { return $value; } diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index 1baedd577efd..992f4b06141f 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -203,13 +203,11 @@ public function customDataLogTables() { */ public function entityCustomDataLogTables($extends) { $customGroupTables = []; - $customGroupDAO = CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity($extends); - $customGroupDAO->find(); - while ($customGroupDAO->fetch()) { - // logging is disabled for the table (e.g by hook) then $this->logs[$customGroupDAO->table_name] + foreach (CRM_Core_BAO_CustomGroup::getFiltered(['extends' => $extends]) as $customGroup) { + // logging is disabled for the table (e.g by hook) then $this->logs[$customGroup['table_name']] // will be empty. - if (!empty($this->logs[$customGroupDAO->table_name])) { - $customGroupTables[$customGroupDAO->table_name] = $this->logs[$customGroupDAO->table_name]; + if (!empty($this->logs[$customGroup['table_name']])) { + $customGroupTables[$customGroup['table_name']] = $this->logs[$customGroup['table_name']]; } } return $customGroupTables; diff --git a/CRM/UF/Page/ProfileEditor.php b/CRM/UF/Page/ProfileEditor.php index 8222086ddabc..22c31c3822cc 100644 --- a/CRM/UF/Page/ProfileEditor.php +++ b/CRM/UF/Page/ProfileEditor.php @@ -300,33 +300,28 @@ public static function convertCiviModelToBackboneModel($extends, $title, $availa 'is_addable' => FALSE, ]; - $customGroup = CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity($extends); - $customGroup->orderBy('weight'); - $customGroup->is_active = 1; - $customGroup->find(); - while ($customGroup->fetch()) { - $sectionName = 'cg_' . $customGroup->id; + $customGroups = \CRM_Core_BAO_CustomGroup::getFiltered(['extends' => $extends, 'is_active' => TRUE]); + foreach ($customGroups as $customGroup) { + $sectionName = 'cg_' . $customGroup['id']; $section = [ - 'title' => ts('%1: %2', [1 => $title, 2 => $customGroup->title]), - 'is_addable' => !$customGroup->is_reserved, - 'custom_group_id' => $customGroup->id, - 'extends_entity_column_id' => $customGroup->extends_entity_column_id, - 'extends_entity_column_value' => CRM_Utils_Array::explodePadded($customGroup->extends_entity_column_value), - 'is_reserved' => (bool) $customGroup->is_reserved, + 'title' => ts('%1: %2', [1 => $title, 2 => $customGroup['title']]), + 'is_addable' => !$customGroup['is_reserved'], + 'custom_group_id' => (string) $customGroup['id'], + 'extends_entity_column_id' => $customGroup['extends_entity_column_id'], + 'extends_entity_column_value' => $customGroup['extends_entity_column_value'], + 'is_reserved' => $customGroup['is_reserved'], ]; $result['sections'][$sectionName] = $section; - } - - // put fields in their sections - $fields = CRM_Core_BAO_CustomField::getFields($extends); - foreach ($fields as $fieldId => $field) { - $sectionName = 'cg_' . $field['custom_group_id']; - $fieldName = 'custom_' . $fieldId; - if (isset($result['schema'][$fieldName])) { - $result['schema'][$fieldName]['section'] = $sectionName; - $result['schema'][$fieldName]['civiIsMultiple'] = (bool) CRM_Core_BAO_CustomField::isMultiRecordField($fieldId); + // put fields in their sections + foreach ($customGroup['fields'] as $field) { + $fieldName = 'custom_' . $field['id']; + if (isset($result['schema'][$fieldName])) { + $result['schema'][$fieldName]['section'] = $sectionName; + $result['schema'][$fieldName]['civiIsMultiple'] = (bool) CRM_Core_BAO_CustomField::isMultiRecordField($field['id']); + } } } + return $result; } diff --git a/Civi/Core/SqlTrigger/TimestampTriggers.php b/Civi/Core/SqlTrigger/TimestampTriggers.php index 3e613cf45be0..33798d08b6fd 100644 --- a/Civi/Core/SqlTrigger/TimestampTriggers.php +++ b/Civi/Core/SqlTrigger/TimestampTriggers.php @@ -299,12 +299,10 @@ public function getAllRelations() { $relations = $this->getRelations(); if ($this->getCustomDataEntity()) { - $customGroupDAO = \CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity($this->getCustomDataEntity()); - $customGroupDAO->is_multiple = 0; - $customGroupDAO->find(); - while ($customGroupDAO->fetch()) { + $customGroups = \CRM_Core_BAO_CustomGroup::getFiltered(['extends' => $this->getCustomDataEntity(), 'is_multiple' => FALSE]); + foreach ($customGroups as $customGroup) { $relations[] = [ - 'table' => $customGroupDAO->table_name, + 'table' => $customGroup['table_name'], 'column' => 'entity_id', ]; }