Skip to content

Commit

Permalink
dev/core#4905 - Deprecate CustomGroup::getAllCustomGroupsByBaseEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Jan 13, 2024
1 parent bbb569a commit 2f9fa0c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 48 deletions.
21 changes: 6 additions & 15 deletions CRM/Core/BAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -1177,15 +1177,14 @@ 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();

// get 'Tab' and 'Tab with table' groups
$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 = [];
Expand Down Expand Up @@ -1233,32 +1232,24 @@ 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
*
* @return CRM_Core_DAO_CustomGroup
*/
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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 4 additions & 6 deletions CRM/Logging/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 17 additions & 22 deletions CRM/UF/Page/ProfileEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 3 additions & 5 deletions Civi/Core/SqlTrigger/TimestampTriggers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}
Expand Down

0 comments on commit 2f9fa0c

Please sign in to comment.