CiviCRM log triggers don't fire on CASCADE DELETE
Overview
When there is a CASCADE DELETE on an entity record, it does not trigger the CiviCRM log for the records (such as from a custom field attached to an entity) that are deleted as a result of the cascade. This behavior makes it difficult to restore custom data from the log tables when the entity it was attached to is deleted and then needs to be restored.
Reproduction steps
- Create a custom field to be Used For Grants (Administer > Custom data and Screens > Custom Fields > Add Set of Custom Fields)
- Create a new Grant record and be sure to fill out the custom field(s) (CiviGrant > New Grant)
- Delete the grant record (CiviGrant Dashboard > View > Delete)
- View the log table of the custom field and you will note that there is no delete log_action on the custom field in question
- If using the command line or a SQL editor like DBeaver, you can use the following command to note the lack of the delete action from the custom field civicrm_log table. (Be sure to change tablename to the actual log table's name).
SELECT id, log_date, log_action FROM tablename;
Current behaviour
If a record is deleted as a result of a CASCADE DELETE, then the action is not logged in the applicable civicrm_log table.
Expected behaviour
The log triggers should fire on records that are deleted, even if as a result of a CASCADE DELETE.
Comments
This issue has been previously noted on this post on Stack Overflow.