Problem/Motivation
#2282119: Make the Entity Field API handle field purging will add support for purging base fields, which means that the purging process can be moved out of the Field module.
Proposed resolution
Move the field purging code from the Field module (field_purge.inc) to a separate service provided by Entity Field API.
The new service is FieldPurger which is a standalone class with no interface.
We also convert field.settings.purge_batch_size to Settings::get('purge_batch_size') since it is environment specific.
Remaining tasks
Review
User interface changes
N/A
API changes
API addition: a new core service FieldPurger has been added to handle the purging of deleted field data.
Data model changes
N/A
| Comment | File | Size | Author |
|---|
Issue fork drupal-2907780
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:
- 2907780-add-a-field-v2
changes, plain diff MR !14682
- 2907780-add-a-field
changes, plain diff MR !10514
Comments
Comment #2
amateescu commentedThis is postponed on #2282119: Make the Entity Field API handle field purging and #2280639: Add the FieldStorageDefinition class to define field storage definitions in hook_entity_field_storage_info().
Comment #3
plachDiscussed this with @amateescu and we agreed to re-scope this to perform all the final clean-ups to make sure the Entity Field API is fully capable of dealing with purging of any field, flavor including non-configurable bundle fields, and get rid of any dependency on the Field module.
Comment #4
amateescu commentedDeleting bundle fields has been implemented in #2282119: Make the Entity Field API handle field purging after all, so this issue is only about cleaning up
field_purge.inc.Comment #5
amateescu commentedWith great pride I give you.. the field purgatory! :D
Comment #6
amateescu commentedMissed a few spots :/
Comment #9
plachNice :)
Are these comments still valid? The pointed issue is closed/fixed.
80 chars ;)
It would be nice if we instantiated the service just once :)
Comment #10
cosmicdreams commentedOr, is it more like a Recycle bin? Where you place data before you decide it should be deleted for good.
Therefore, is this the beginning of a Trash bin in core for content?
Edit:
Well, not the beginning, as @amateescu will surely point out: https://www.drupal.org/project/trash
Comment #11
masipila commentedYay, #2282119: Make the Entity Field API handle field purging just landed!
According to #2, this is still postponed on #2280639: Add the FieldStorageDefinition class to define field storage definitions in hook_entity_field_storage_info().
The thing here is that we have #2906470: Orphan comments and entries in comment_entity_statistics after comment field instance has been deleted which is postponed on this one and #2906470: Orphan comments and entries in comment_entity_statistics after comment field instance has been deleted is critical (and blocking Migrate Drupal from coming stable).
So the chain is #2906470: Orphan comments and entries in comment_entity_statistics after comment field instance has been deleted depends on #2907780: Add a field purger service which depends on #2280639: Add the FieldStorageDefinition class to define field storage definitions in hook_entity_field_storage_info().
@amateescu or anyone else, can you confirm that I've understood the dependencies correctly? If yes, should we bump this and #2280639: Add the FieldStorageDefinition class to define field storage definitions in hook_entity_field_storage_info() to critical as well?
Cheers,
Markus
Comment #12
amateescu commented@masipila, actually I implemented the ability to purge bundle fields in #2282119-42: Make the Entity Field API handle field purging, so #2906470: Orphan comments and entries in comment_entity_statistics after comment field instance has been deleted should be good to go from that POV :)
Comment #13
amateescu commented@yched, what can I say.. I was speechless from laughing out loud :D There are some valid concerns in there but I'm afraid we need to find someone who is more spiritual to give us a definitive answer. However, I hope your Sunday was not so bad after all ;)
@cosmicdreams, this is more like the garbage truck that already picked up your trash and it's on its way to the garbage dump. If you hurry up and you're willing to wade through the pile of trash, you might be able to recover some of the data from your deleted fields :D
@plach,
1. The @todos are useless but the comments are still valid since we can not purge the data if the entity type class is not available anymore.
2. Fixed.
3. Fixed the places where we were calling the service more than 3 times. For one or two calls.. it's not worth the effort IMO :)
Comment #14
cosmicdreams commentedIf I'm understanding you correctly, this "purgatory" service is not like a trash bin because some process to delete the items in the bin is actively processing. Despite that active purging process, it is still possible to save the items, if you act strategically and quickly.
Like: https://youtu.be/QtQPmDjuA5s
If that's the case, why would we allow that saving of items that have been marked for purging and are actively being purged?
Comment #15
amateescu commentedLOL, that scene fits this whole discussion perfectly :D
Allowing deleted data to be recovered is not really something that we do on purpose. It's just that it needs to sit there until the service comes up and says "hey, I'm going to delete this piece of field data permanently, is there anyone out there who cares and wants to do something about it?". So until that happens for every piece of data, we have to keep it stashed away somewhere :)
Comment #16
cosmicdreams commentedAnd that description does not match a recycle bin because the directive to finally delete the data has been given and a process is actively deleting data that has already passed that system-driven check of whether something needs that data or not?
Because without that context of having a processing actively deleting data underway, what you've just described is a trash bin / recycle bin.
Comment #17
amateescu commentedRight, but that context is important because that's pretty much what field purging is about.
Comment #19
dillix commentedWill this service delete fields marked with deleted flag when base entity for this field does't exist anymore? I have 3 ghost fields marked with deleted flag, but field_cron() can't delete them because commerce changed entity name without update its fields on alpha->beta stage.
Comment #20
plachThis kind change needs to go into the development branch first. Backport is considered afterwards.
Comment #21
dillix commented@plach what should we do with ghost fields?
Comment #31
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #32
cosmicdreams commentedComment #33
karishmaamin commentedRe-rolled patch against 10.1.x. Please review
Comment #34
tanuj. commentedTried to fix CCF on #33
attached interdiff file
Comment #35
tanuj. commentedadded wrong patch file on #34
Tried to fix CCF on #33
attached interdiff file
Comment #36
nikhil_110 commentedFix CCF on #33 & Attached Interdiff file
Comment #40
catchThis could use an update now that OOP hooks are in.
Comment #42
anmolgoyal74 commentedComment #44
stborchertComment #45
anmolgoyal74 commentedI have re-rolled the patch and used OOP hooks to purge the field definitions. I did it as a part of contribution sprint at DrupalCon Singapore 2024.
Comment #46
immaculatexavier commentedHi @anmolgoyal74
The reroll seems to be good.
Fix PHPCS Violations:
Go through the generated PHPCS report and resolve the coding standard violations. This may involve reformatting the code, adding missing docblocks, or updating variable names.
Address PHPStan Issues:
Review the PHPStan analysis and resolve any potential type mismatches, missing variables, or logical errors.
Comment #47
immaculatexavier commentedComment #48
anmolgoyal74 commentedComment #49
amateescu commentedWhile this issue was quite a nice trip down memory lane, I wasn't really serious with the previous service name :)
Updated it to "field purger" and brought this old patch up to current core standards, with a change record as well: https://www.drupal.org/node/3494023
Comment #50
nicxvan commentedWent through it a couple of times.
Just one question in the mr.
Comment #51
smustgrave commentedComment seems valid.
Also will need test coverage for the update hook around the config updates.
Comment #54
nicxvan commentedI think this is ready for review again!
I rebased on main
I updated deprecation versions
I added a deprecation to the file itself
I'm not sure on the system update number
The only bit from the rebase was moving where the field_purge_batch was called from since that test was refactored to handle update multiple types
There is some discussion about this being postponed, but I don't see any reason to postpone this.
I took care of my comment from the other MR but it was trivial, just copying a log.
I'm not sure what test coverage updates like that usually get, do you have an example?
I also removed the require once for the purger and the outdated comment.
Comment #56
nicxvan commentedI don't see any discussion about moving that config, why was it moved to system, I'm not sure we want to do that do we?
Edit: nevermind, it's because the purger service was moved to the core field subsystem.
Comment #57
berdirComment #58
nicxvan commentedComment #59
nicxvan commentedDiscussed this on slack a bit, there really doesn't seem to be a need for the interface since it doesn't look like it needs to be fully swapped out.
If someone needs more they can subclass it and still override it.
Comment #61
nicxvan commentedComment #62
berdirThis needs another rebase.
Comment #63
claudiu.cristeaLet's try to bring it to finish
Comment #64
andypostsummary needs to be polished and config settings needs to be mentioned in CR and schema deprecation possibly provided
Comment #65
nicxvan commented#3571593-19: Deprecate translation.path config in favor of settings details how we should handle the config to settings I think.
https://git.drupalcode.org/project/drupal/-/merge_requests/14644#note_72...
Comment #66
nicxvan commentedComment #67
nicxvan commentedPushed this a bit further.
I removed the new config added the old back with the deprecation.
I added the new settings.
I need to remove the update hook and replace it with the correct post update hook.
Comment #68
nicxvan commentedComment #69
nicxvan commentedI updated the Issue summary and Change record.
I finished converting this to follow the pattern from the translation path issue.
I'll keep an eye on tests, but this should be ready.
Comment #70
nicxvan commentedMeant to set needs review!
Comment #71
nicxvan commentedComment #72
claudiu.cristeaDid a review, see the MR
Comment #73
nicxvan commentedI have addressed all feedback but deprecating
field_purge_fieldandfield_purge_field_storagewithout replacement.I asked @amateescu on slack and he has it on his list to review.
Tagging for subsystem maintainer review.
Comment #74
claudiu.cristeaThank you, @nicxvan. There's still one thing left related to the visibility of FieldPurger::purgeFieldDefinition() and FieldPurger::purgeFieldStorageDefinition(). Let's wait for a 3rd opinion
Comment #75
nicxvan commentedYes, sorry that is what I meant, if we change the visibility then we need to deprecate without replacement.
I now agree with you we should, but it's really a decision for the field maintainer so I'll hold off for now.
Comment #76
amateescu commentedReviewed the MR.
Comment #77
nicxvan commentedI made them protected, updated the deprecations and addressed all feedback.
Comment #78
claudiu.cristeaReady to RTBC this but I've just noticed we need to update the CR https://www.drupal.org/node/3494023 because of the methods made protected.
Comment #79
claudiu.cristeaThank you. CR is reflecting now the changes. I cannot see anything else, this is ready.
Comment #80
larowlanReviewed this and left a couple of minor questions/nits
This is really close - would be good to resolve if
was meant to be
Because a one letter typo gives it a whole different meaning :)
Comment #81
nicxvan commentedI addressed all of your feedback thanks!
I didn't change the logger channel for the reason that @berdir stated.
I did see that potential typo, I only didn't reach out for clarification because this:
Comment #82
nicxvan commented@larowlan said I could self rtbc, one is addressed the feedback.
Comment #83
alexpottNice work everyone - great to see this finally nearly done. Can we get a follow-up to remove the field.settings config object from Drupal 13.
One thing we need to address... we remove the config from config/install but we leave it lying around empty in the post update. See comment on MR.
Comment #84
nicxvan commented#3587460: Remove the field.settings config object from Drupal 13 Here we go!
Should we add this as a comment somewhere?
Comment #85
nicxvan commentedThe suggestion was applied and looks correct. I've created the follow up and @alexpott confirmed we do not need a todo anywhere so I think all feedback has been addressed.
Comment #86
alexpottJust noticed another thing in the update... sorry.
Comment #87
claudiu.cristeaI've applied the suggestion.
Comment #88
alexpottCommitted and pushed 867318c3996 to main and bfd87c3dda1 to 11.x. Thanks!
Comment #93
pingwin4egThe config name and its key were misnamed in the commit and the change record. The config name
field.settingsbecamefield.field_settings, and its keypurge_batch_size-field_purge_batch_sizefor some reason.I opened a follow-up issue - #3622469: Fix field.settings:purge_batch_size config name and key and updated the CR.
Also, shouldn't the new setting be documented in
default.settings.php?