CIWEMB-33: Fix creating custom fields with logging on #92
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR backports the patch civicrm#21019 which fixes a DB syntax error when creating custom fields via the CiviCRM API if CiviCRM logging feature was on.
Before
Creating custom fields is not working via CiviCRM API.
After
Creating custom fields is working via CiviCRM API.
Technical Details
When creating custom fields via CiviCRM API like
CiviCRM will create a table to store the data e.g. for the custom group
cpd_activity
with the id 40, CiviCRM creates thecivicrm_value_cpd_activity_40
. If the logging feature is on, another table will be createdlog_civicrm_value_cpd_activity_40
.For each new custom field we create via the CiviCRM API, CiviCRM alters the
civicrm_value_*
and alters the logging table to create a column for each custom field e.g. for the custom fieldcpd_title
the columncpd_title_145
will be created in two places where the 145 is itsid
in thecivicrm_custom_fields
table.CiviCRM fails at altering the logging table because the code send the custom field
name
instead of itscolumn_name
at the line CustomField.php#L157Which results in creating a wrong query to create the logging table
ALTER TABLE log_civicrm_value_cpd_activity_40 ADD
, the missing part of this query is because CiviCRM tries to search for the line in the "create query" of the tablecivicrm_value_cpd_activity_40
that match the regexThe regex will not match any line in the "create query" of the table
civicrm_value_cpd_activity_40
This is the relevant part in the function Schema::_getColumnQuery
The patch uses the column name instead of the field so that CiviCRM can generate the query successfully.