Currently if a node type is deleted, extraneous entries are left behind in the variable table by modules like comment and upload. This is probably not a real problem except if sites add and delete a lot of node types.
Two possible approaches to cleaning up the variable table when a node type is deleted:
1) Each module that adds elements to the node type form should implement hook_node_type and clean up when they get the 'delete' $op. This is the simplest, in a sense, but more burden on contrib module authors to get it right.
2) The node module should do its best to clean up automatically.
Patch implementing approach #1 attached for review.
Note, this is a relatively atomic bit of the issues originally discussed here: http://drupal.org/node/88633
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | collect_garbage_if_a-104572-21.patch | 3.84 KB | parashram |
| #15 | extra_vars-104572-15.patch | 1.55 KB | 13rac1 |
| #11 | 104572.patch | 1.72 KB | douggreen |
| #6 | type_deletion_cleanup6x_3.patch | 2 KB | pwolanin |
| #4 | type_deletion_cleanup6x_2.patch | 1.78 KB | pwolanin |
Comments
Comment #1
Jaza commentedpwolanin, although I'm all for approach #1, it's not going to get committed. Dries indicated very clearly in http://drupal.org/node/88633 that he hates hook_node_type(), so there's no way that he's going to let more implementations of it get committed.
Therefore, in the interests of getting this bug fixed (albeit not in the cleanest way), could you please modify your patch to implement approach #2 instead. You can probably once again use the
node_type_excluded_keysmechanism that you introduced earlier in http://drupal.org/node/88633.Comment #2
pwolanin commentedOk, here is a simplified version of approach #2 (automatic cleanup)- the keys used to generate the variable names are themselves saved as a variable, and then used to delete variables if the type is deleted.
Comment #3
pwolanin commentedI think #2 is the way to go based on the current API- the array_merge() to keep a list of all past variables may not totally be necessary, but I think it insures a maximum of garbage collection.
Comment #4
pwolanin commentedPatch re-rolled for HEAD (previous one applies fine, but with offset).
Any reason this is not RTBC?
Comment #5
pwolanin commentedbump - needs to be re-rolled
Comment #6
pwolanin commentedPatch re-rolled for HEAD (previous one applies fine, but with offset).
Comment #7
catchStill applies with offset. My variables table contains all kinds of cruft (> 1000 rows) so I'm all for cleanup, but not qualified to review the code.
Comment #8
pwolanin commentedI guess also the question of whether this is worth while to do depends on whether node types are ever deleted on a typical site.
Comment #9
dman commentedI vote for it being worthwhile, because although not typical, the UI does allow it to happen. But actually doing so puts the site into an unstable state that can't be repaired without messing with the DB. Thus, repairing the DB when appropriate is a good thing.
Comment #10
catchEspecially when starting off a site for the first time, you can be making and deleting content types quite a lot. Also, if you had two content types and wanted to merge them into one, it'd be handy to have a two-click solution rather than update node set type where ....
Comment #11
douggreen commentedI also think this is needed after discovering that my site, after a year of development, has 500 of these variables cluttering up the variable table. Patch still applied, albeit not cleanly, here's the one re-rolled for 7.x.
Comment #13
Anonymous (not verified) commented#11: 104572.patch queued for re-testing.
Comment #15
13rac1 commentedRe-rolled for current dev.
Comment #16
alan d. commentedThis may have to be rolled against 8.x first. Has anyone checked?
Comment #17
thedavidmeister commentedyes, can we check if this is an issue in D8? but also, can we write some tests for this regardless of what version we roll against?
Comment #18
dcam commentedAdded #1933374: Deleted content types leave a bunch of variables behind as a related issue. There's almost certainly some duplication of work between the two issues, but I didn't check thoroughly.
Comment #19
parashram commentedYes, https://www.drupal.org/node/1933374 is same like this issue, So following variables should be
additional_settings__active_tab_NODETYPE
language_content_type_NODETYPE
menu_options_NODETYPE
menu_parent_NODETYPE
save_continue_NODETYPE
Thanks:
Parashram
Comment #20
parashram commentedComment #21
parashram commentedComment #22
parashram commentedComment #23
parashram commentedComment #25
parashram commented