Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#1093: Bckport Fix to v.5.19 to Add Custom Fields to Logging Tables #15642

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CRM/Core/BAO/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public static function create($params) {
* Default parameters to be be merged into each of the params.
*/
public static function bulkSave($bulkParams, $defaults = []) {
$sql = $tables = $customFields = [];
$addedColumns = $sql = $tables = $customFields = [];
foreach ($bulkParams as $index => $fieldParams) {
$params = array_merge($defaults, $fieldParams);
$customField = self::createCustomFieldRecord($params);
Expand All @@ -194,11 +194,19 @@ public static function bulkSave($bulkParams, $defaults = []) {
$params['table_name'] = $tables[$params['custom_group_id']];
}
$sql[$params['table_name']][] = $fieldSQL;
$addedColumns[$params['table_name']][] = $customField->name;
$customFields[$index] = $customField;
}

foreach ($sql as $tableName => $statements) {
// CRM-7007: do not i18n-rewrite this query
CRM_Core_DAO::executeQuery("ALTER TABLE $tableName " . implode(', ', $statements), [], TRUE, NULL, FALSE, FALSE);

if (CRM_Core_Config::singleton()->logging) {
$logging = new CRM_Logging_Schema();
$logging->fixSchemaDifferencesFor($tableName, ['ADD' => $addedColumns[$tableName]]);
}

Civi::service('sql_triggers')->rebuild($params['table_name'], TRUE);
}
CRM_Utils_System::flushCache();
Expand Down