We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37138
    • 12 Posts
    how can i delete child documents with tvs of a particular folder? I need to delete them on regular basis.
      • 18373 ☆ 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?
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 37138
        • 12 Posts
        Ii am parsing a catalog from another site. Just need to delete the catalog before parsing again on regular base.
        thx i will try that smiley
          • 18373 ☆ 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.
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 37138
            • 12 Posts
            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?
              • 18373 ☆ 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. tongue

              Forwarded a link to this topic to Bert Oost who has done similar work before and may have some thoughts on this.
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 3186 ☆ 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.]
                  MODX Ambassador (NL) & Professional MODX developer
                  Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
                  MODX e-commerce solution SimpleCart
                  • 37138
                  • 12 Posts
                  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?