how can i delete child documents with tvs of a particular folder? I need to delete them on regular basis.
-
☆ A M B ☆
- 3,141 Posts
You can fetch the resources within PHP (so a Snippet or Plugin) and remove them like this:
$c = $modx->newQuery('modResource');
$c->where(array('parent' => 4));
$col = $modx->getCollection('modResource',$c);
foreach ($col as $res) {
$res->remove();
}
where 4 is the ID of your resource parent.
What kind of scenario are you dealing with that you need to delete resource regularly though?
-
☆ A M B ☆
- 3,141 Posts
It may be a better idea to instead of deleting and recreating the resources, to actual update the catalog resources with the latest data. That way, if your catalog provider has some issues one night it is run, you don't end up with an empty site. And it'd probably be far less resource intensive to update where needed too.
Yes that exactly is what I have right now. But it happens that some products in the remote catalog are deleted and it ends up having those products in the catalog on my site.
I thought but could not get idea on how to delete such products from my catalog without deleting the whole catalog. Any idea?
-
☆ A M B ☆
- 3,141 Posts
Hmm, that is a good question. If you'd store a unique ID in a TV or other resource field you could run a check on that.. but that'd be resource intensive too.
Forwarded a link to this topic to Bert Oost who has done similar work before and may have some thoughts on this.
-
☆ A M B ☆
- 279 Posts
As Mark told; recreating them isn't a good thing, I agree with that.
I think the best way to do this is first selecting all ID's (or some other value, like article-code) of all products and then keep tracking on the new and updated products. Compare the both lists and then you will have ID's which are no long in use, then foreach them and remove it.
This is the way I should do
[ed. note: bertoost last edited this post 15 years, 1 month ago.]
I am thinking that what if i just unpublish the catalog and then run the parser as i have it now?
What would be the snippet code for unpublishing?