-
Notifications
You must be signed in to change notification settings - Fork 2
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
$template->childTemplates & $template->parentTemplates not updated when template is deleted #802
Comments
Unless it's resulting in a visible error somewhere (?), this one is expected, and not a problem. When references are encoded (rather than existing in their own DB column), it's not necessary (and sometimes not practical) that they be removed until the next time the value holding them is modified and/or saved. |
I don't remember if I came across an error, but I probably did or I wouldn't have noticed this discrepancy. In a couple of my modules I do checks on whether there a template has childTemplates and I believe these would be incorrect with the current behavior. I use modules from other devs that also do this check. I noticed in ProcessPageListerPro.module there is:
Maybe I am misunderstanding something, but won't this return |
The line(s) you mentioned in Lister/ListerPro are just optimizations to skip over an additional check if the value happens to be empty. There are many instances where ProcessWire core as well as both core and 3rd party modules keep track of these kinds of settings in encoded values. All configurable modules and fields work in this way as well. The childTemplates setting on templates is just one of potentially hundreds. Settings like this are adjusted at the time the object that encodes the setting is saved. It wouldn't be practical or efficient otherwise. When we need a setting that is automatically adjusted in the manner you described, we reserve a dedicated DB column or table for it, which is what enables it to be efficiently managed in that way. |
So if a module author want to get an accurate result for whether a template has a particular template in its childTemplates, what is the recommended way to check this? Do we need to check the childTemplates property and then do an additional check to see if each of the returned IDs are actually valid templates? |
Maybe something like this below (?)
|
Ok, sorry, I guess that was the wrong question because in your example the template has to exist or the function will throw an error. I am talking about a situation where you want to know if a template has any childTemplate restrictions and currently it will return the IDs of templates which may no longer exist and the count will be wrong. I guess I am talking a relatively uncommon need. I just don't like that there is incorrect data stored. |
@ryancramerdesign - I have actually come across an error with this. This line: https://github.com/processwire/processwire/blob/649d2569abc10bac43e98ca98db474dd3d6603ca/wire/modules/PagePermissions.module#L849 causes a: PHP Notice: Trying to get property 'useRoles' of non-object Note that the notice doesn't show for superusers so that might confuse you at first. |
@ryancramerdesign - actually, it's possible for the error to show for superusers. I am seeing this with Tracy's RequestInfo panel - it makes a call to see if the page has addable() permission and if you have one of these deleted childTemplates, it gives you that "Trying to get property 'useRoles' of non-object" error. |
I believe my suggested fix in #543 would resolve this issue too. Specifically this addition: if(!$template) continue; // childTemplates may contain IDs for templates since deleted |
@ryancramerdesign Bumping this for your consideration. |
@ryancramerdesign - I am still getting the |
@netcarver - could you please remove the "not a bug" tag? Maybe that will get Ryan's attention again. My logs are being polluted with: Thanks! |
@ryancramerdesign Still seems to be an issue. |
OK, I finally decided to deal with the error messages myself because it was getting a bit silly :) This script makes it quick and easy to figure out which templates have Of course this could easily be adjusted to automatically remove Anyway, it would be nice if when a template is deleted, other templates were scanned for its ID in their |
@adrianbj what do you think of adding such fixes to a dedicated module? We could have fixes in place quickly (and publicly) and @ryancramerdesign could easily test those fixes and add them to the core. I've created a module for this: https://github.com/BernhardBaumrock/PwCoreFixes |
Hi @BernhardBaumrock - I like your proactive approach to the PwCoreFixes module, but I fear that it might actually slow down fixing these things because if users start adopting it, they'll be less likely to add their voice to the actual issue reports and so Ryan won't see that the issue affects other users as well. I hope I am wrong though and I really appreciate your effort! Here is a hook based fix for cleaning up both the child and parent templates when a template is deleted. Feel free to add it to your module if you'd like.
|
Just an FYI about that code example above - obviously that will do a complete cleanup of all orphaned templates in |
@ryancramerdesign - can you please reconsider this. I am still getting this error:
and it's pretty clear why :) |
Short description of the issue
If you delete a template that has been added to another template's
childTemplates
array, it is not removed from this arrayExpected behavior
It should be automatically removed.
Actual behavior
It isn't removed.
Optional: Screenshots/Links that demonstrate the issue
Your screenshots/links go here.
Steps to reproduce the issue
The text was updated successfully, but these errors were encountered: