-
- 670 Posts
Hi,
Following from an issue I found that bob was trying to help with, I have noticed I have several Resources in the Database that do not appear in the Manager at all. They were permanently deleted at some point (ie. they are not in the resource tree with a strikethru).
1. Any idea how this can happen?
2. Is it safe to manually delete these resources from the modx_site_content table?
Thanks
Andy
-
- 5,888 Posts
1. could have some reasons
for example have no parent or show_in_tree = 1 or hide_children_in_tree of the parent = 0
2.no, you have also to remove related objects like child-resources or TVs, better use the resource->remove - method
-
- 5,888 Posts
$removeresources = '1,2,3,4';
$c = $modx->newQuery('modResource');
$c->where(array('id:IN'=>explode(',',$removeresources)));
if ($docs = $modx->getCollection('modResource', $c)){
foreach ($docs as $doc) {
$doc->remove();
}
}
be carefull!
-
- 24,544 Posts
Andy, There are several reasons for resources not to show in the tree. That's standard if they were created with the Articles or Collections extras. They could also have their 'show_in_tree' field set to false. Having an invalid parent or being a descendant of a resource with an invalid parent will also hide them.
As Bruno suggests, it's never a good idea to delete them in the database because they can leave behind orphaned intersects that connect them to TVs and Templates. There might also be children that would still exist but now wouldn't show in the tree. Those would be there forever, cluttering up the DB unless you remove them properly with code like Bruno's.
You could also remove them safely with the Batcher extra.
-
- 670 Posts
Should I just re-install Articles to see if they re-appear?
-
- 5,888 Posts
you modified this line to your needs?
$removeresources = '1,2,3,4';