-
-
Notifications
You must be signed in to change notification settings - Fork 824
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#2709 Enable logging for custom data tables with non-standard names #20918
Conversation
(Standard links)
|
@eileenmcnaughton In what situation would a custom group table get a non-standard name? This does happen with some extensions by the way (eg. |
@mattwire I would have thought that sort of information is available via the entityTypes hook but maybe its just not easily exposed to the logging system / logging system doesn't work with entityTypes |
@mattwire we have non standard names for custom tables & custom fields in our custom code simply because we want to have the same table names across life & dev installs and to keep them simple and clean. This makes is a lot easier for integrations that interact directly with the database. Specifying the table name & field name is supported via unit tests - but there is no reason for there to be any implied 'magic' - which is what we currently have. As @seamuslee001 says - you can declare entity tables via the hook (which is called if you use the xml + civix to generate your entity) - the missing piece is for our schema to have a parameter for 'logging' - or rather, it DOES but it maps to the change log not to the db logging which is what I mean. I do think that would be good in the schema and it would be used for core tables too - but it IS a separate issue |
@seamuslee001 @eileenmcnaughton Thanks for clarifying. I'm happy with the concept here. Do either of you have any idea why logging doesn't work with extension entity tables when they have non-standard names? .. and whether that could be fixed easily? A good example is civirules where all tables start with |
@mattwire it comes from https://github.com/civicrm/civicrm-core/pull/20918/files#diff-38921d05e11c37ba518426a68b4d962a6df048cbfc87f41c0e67dd02dc9c86faR129
Steps would be
|
@eileenmcnaughton yes agree - |
I've added https://lab.civicrm.org/dev/core/-/issues/2712 for the logging issue - looks like I have a jenkins issue here |
test passes locally - let's see if that works |
// include these BEFORE the hook is called. | ||
$customFieldDAO = CRM_Core_DAO::executeQuery(" | ||
SELECT DISTINCT table_name as TABLE_NAME FROM civicrm_custom_group | ||
where table_name NOT LIKE 'civicrm_%'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting: The underscore is a wildcard character with LIKE, so this would skip some intended tables (e.g. one called civicrmstuff
), except because line 129 includes those tables when it didn't intend to, it works out. So 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I think you need to use a "regex" here ie:
where table_name NOT LIKE 'civicrm_%'; | |
where table_name NOT LIKE 'civicrm\_%'; |
(see api/v3/System.utf8conversion)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes just then a table like 'civicrm4ever' would get included twice but you could run array_unique on the results. Or could change line 129 to also do \_
, but a problem would be that that would start excluding non-custom-field tables that were being logged before if they had names like civicrm4ever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@demeritcowboy @mattwire that is the same WHERE as is used to include a few lines earlier so it's basically
- step one include all tables where table_name LIKE 'civicrm_%';
- step two include custom tables WHERE table_name NOT LIKE 'civicrm_%';
I tried doing it as a union but the charset didn't match when ci ran
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(ie the WHERE clause only exists because we might as well not get ones we already have)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently if you have table called civicrm4eva then it will be included regardless of whether it is a custom table or not - I don't want to change that and I don't think this will.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right that's why I gave the shrug - this PR as-is is the most consistent, with the downside the queries are technically wrong, but they complement each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@demeritcowboy yeah & changing would create a functional change - which I don't want to do
Overview
dev/core#2709 Enable logging for custom data tables with non-standard names
Before
When a custom group is created and the table_name is specified as 'something random' and then logging is enabled, logging is not enabled for the table
After
Logging behaviour follows normal standards. As with any other table the hook can be used to opt the table out of logging
Technical Details
One line change + comments + test
Comments