We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38371
    • 42 Posts
    Hello,

    I have a situation where I want to remove all entries from a table that have a certain value on one of their columns (e.g., the "cost" column value is below "300").

    Now, there is the modObjectRemoveProcessor which I can utilize. However, this processor removes only one entry. That is why I was wondering if it would be the best practice to create a custom processor extending the modObjectProcessor that would just:

    • collect all necessary entries and
    • just call the modObjectRemoveProcessor for each one of the above.

    Or perhaps is there a more appropriate way for this kind of query?


    Thanks a lot.
      • 33968
      • 863 Posts
      You could use a modObjectGetListProcessor, and then override the iterate() method and call object->remove() inside the loop.

      You could also call $this->modx->runProcessor() on modObjectRemoveProcessor if you want to use all the permission checks, etc.
        • 3749
        • 24,544 Posts
        You could also do the permission check yourself (if it's needed) and, use getCollection() to get the objects, and then remove them:

        <?php
        /* I'm too tired to do the query ;) */
        
        $objects = $modx->getCollection('modWhatever', $c);
        
        foreach ($objects as $object) {
            $object->remove();
        }



        ------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using.
        MODX info for everyone: http://bobsguides.com/modx.html
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting