Problem/Motivation
target_id_intis kept synchronized withtarget_idby a database trigger. Per #3204103-12: Use virtual index instead of triggers, this is useful in case any code writes to the DER field's database tables directly, without going through Drupal's Entity API.- However, per #2930423: MySQL triggers aren't supported on all hosting platforms, database triggers aren't supported on all hosting platforms.
- Futhermore, writing to Drupal's entity or field tables without going through Drupal's Entity API is problematic for plenty of other reasons, such as then various hooks don't get called. Therefore, many sites don't do this.
Steps to reproduce
Proposed resolution
Change DynamicEntityReferenceItem to also keep target_id_int in sync via Drupal. I think that all that needs to be done for this is:
DynamicEntityReferenceItem::schema()would need to addtarget_id_intas another column.DynamicEntityReferenceItemwould need to override__get()such that whentarget_id_intis passed, it returns the integer value oftarget_id, otherwise call the parent getter.
This could be in addition to leaving the existing trigger approach in place, so that sites where triggers are supported continue to get the benefit of the column staying synchronized even when target_id is updated in the database via something other than the Entity API. But this would enable sites where triggers aren't supported to also be able to use DER 4.x, so long as those sites don't update DER's database values without using the Entity API.
Remaining tasks
- The latest patch has duplicate code creating the int column. It's now part of the field item schema, but the IntColumnHandler classes still create it too. So we need to remove the column creation from the IntColumnHandler classes while leaving the trigger creation in place.
- The latest patch still needs a hook_update_N() function written in order to make the update path tests pass.
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | der-3276723-12.patch | 13.77 KB | effulgentsia |
| #11 | der-3276723-11.patch | 13.7 KB | effulgentsia |
| #8 | der-3276723-8.patch | 7.02 KB | effulgentsia |
| #7 | der-3276723-7.patch | 6.78 KB | effulgentsia |
| #5 | der-3276723-5.patch | 764 bytes | effulgentsia |
Issue fork dynamic_entity_reference-3276723
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
larowlanThis sounds a hell of a lot simpler
I'd be in favour of it
Comment #3
effulgentsia commentedUpdating title and summary based on #3204103-12: Use virtual index instead of triggers.
Comment #4
effulgentsia commentedFirst, just wanting to see which tests fail without the trigger. NR for testbot only.
Comment #5
effulgentsia commentedCoding standards checks aren't happy with commenting out lines of code, so removing them instead.
Comment #7
effulgentsia commentedHere's a start. Still needs work, but NR for testbot.
Comment #8
effulgentsia commentedComment #10
effulgentsia commentedI'm pausing work on this for now, but assigning to myself to remember to pick it up again soon.
Comment #11
effulgentsia commentedThis adds test subclasses for each test that failed in #5. This way, the pre-existing tests keep testing with the pre-existing IntColumnHandler classes, and these new tests run those same tests again with a NULL implementation of IntColumnHandler to emulate an environment where database triggers don't run.
The kernel tests all pass, but the update path tests all fail, because this patch still needs to implement a hook_update_N() function. That might be a bit tricky. Not sure when I'll have time to get to it, so unassigning myself for now.
In addition to the update function, still todo on this patch is to also change the pre-existing IntColumnHandler classes to not create the column (since the field item now does that), and to limit themselves to only creating the trigger.
Comment #12
effulgentsia commentedFixed coding standards violations.
Comment #14
larowlannit, no need for else here
(die else die 🏴☠️)
In terms of the update, we can look at how date_recur added a new column https://cgit.drupalcode.org/date_recur/commit/date_recur.install?id=8039... for an example
Comment #15
ronraney commentedHas there been a resolution or change to this since 2022? I'm not certain, but we may have an issue with triggers as it relates to our hosting platform. I see a "failed testing" for most or all of the patches.
Comment #16
jibranI'd say #3204103: Use virtual index instead of triggers is the way forward here. I'm planning to work on it in a couple of weeks time.
Comment #17
ronraney commentedHello, I'm running out of time due to changes in MySQL. We've had a workaround in place that is no longer working. It the only working solution to downgrade to 1.x(3.x in D10)?
Comment #19
larowlanComment #21
larowlanCommitted to 5.x dev
Looking for folks to test the update path and report back