if (!$customInfo) {
return;
}
+ $select = ['f.name', 'f.data_type', 'f.label', 'f.column_name', 'f.option_group_id', 'f.serialize', 'f.fk_entity'];
+ // Prevent errors during upgrade by only selecting fields supported by the current version
+ $supportedFields = \CRM_Utils_Array::prefixKeys(\CRM_Core_BAO_CustomField::getSupportedFields(), 'f.');
+ $select = array_intersect($select, array_keys($supportedFields));
+ // Also select fields from the custom_group table (these fields are so old we don't have to worry about upgrade issues)
+ $select = array_merge(['g.name as custom_group_name', 'g.table_name', 'g.is_multiple'], $select);
$fieldData = \CRM_Utils_SQL_Select::from('civicrm_custom_field f')
->join('custom_group', 'INNER JOIN civicrm_custom_group g ON g.id = f.custom_group_id')
- ->select(['g.name as custom_group_name', 'g.table_name', 'g.is_multiple', 'f.name', 'f.data_type', 'label', 'column_name', 'option_group_id', 'serialize', 'fk_entity'])
+ ->select($select)
->where('g.extends IN (@entity)', ['@entity' => $customInfo['extends']])
->where('g.is_active')
->where('f.is_active')
$customTable->addTableLink('entity_id', $joinable);
}
- if ($fieldData->data_type === 'EntityReference') {
- $targetTable = \CRM_Core_BAO_CustomGroup::getTableNameByEntityName($fieldData->fk_entity);
+ if ($fieldData->data_type === 'EntityReference' && isset($fieldData->fk_entity)) {
+ $targetTable = AllCoreTables::getTableForEntityName($fieldData->fk_entity);
$joinable = new Joinable($targetTable, 'id', $fieldData->name);
$customTable->addTableLink($fieldData->column_name, $joinable);
}