Did you clear the cache before running it (and again after)? If not, it may find the deleted children in the cache.
I also changed the code above to ignore deleted but not purged children.
[ed. note: BobRay last edited this post 13 years, 6 months ago.]
-
☆ A M B ☆
- 79 Posts
I'm on modx cloud so i've installed your add on CacheClear. I have my parent page "parent1" and "subpage1", when i create my "subpage1" "parent"'s container checkbox is automaticalle checked, perfect. Now if i remove "subpage1", "parent1"'s checkbox container is still checked, even after i saved the document and clear the cache. I mght do something wrong.
Is it correct if you clear the cache manually (on the Site Menu) and reload the page?
BTW, CacheClear doesn't do anything unless you preview the CacheClear Resource. Are you thinking of CacheMaster?
Let's try making it simpler:
<?php
/* Utility snippet to set container status for all existing resources */
$docs = $modx->getIterator('modResource');
foreach ($docs as $doc) {
$children = $doc->getMany('Children', array('deleted' => 0));
$setting = ! empty($children)? true : false;
$doc->set('isFolder', $setting);
$doc->save();
unset($children);
}
BTW, you are putting a tag for this snippet in a resource and previewing the resource to run it, right? Also, it should be called uncached:
[[!SnippetName]]
-
☆ A M B ☆
- 79 Posts
Yes i call the snippet in my template, the resource is uncached, i clear the cache, but container checkbox is still checked after i removed the subpage.
I don't know what to suggest (assuming that the snippet tag has the exclamation point: !). It's very rare, but sometimes there are resources that don't show up in the tree.
-
☆ A M B ☆
- 79 Posts
i create "parent1" and "subpage1". I drop "subpage1" somewhere else in the menu, i save, then "parent1" is not a container anymore but "subpage1" is now.
You don't want the snippet tag in your template. It will slow down your page loads and you may not see the results until later.
You want to put the tag in a resource and preview that resource when you want to set all the container status of all resources on the site.