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 to everyone,

    I would like to create a Processor that will delete multiple objects at once. A similar example is the deletion of multiple users from the "Manage Users" menu.

    However, the Processor of the above action is a script while I would like to use a class-based Processor.

    That is why I was thinking of extending the modObjectProcessor and on the "process" method utilize the custom "removeProcesor" I have created for this specific class of objects.

    Example Code
    file: removeall.class.php

    class myRemoveAllProcessor extends modObjectProcessor {
    ...  
    
      public function process() {
        foreach ($objects as $object) {
          $this->modx->runProcessor('my/object/remove/', $object->toArray(), array(
            'processors_path' => 'path/to/my/processors/'
          ));
        }
      }
    
    ...
    }


    However, because I have not seen it anywhere inside the MODx source I would like to know if there is anything wrong with calling one Processor from inside another?

    And if this is considered bad practice, could anyone suggest another solution to this problem?


    Thanks a lot.
      • 3749
      • 24,544 Posts
      I don't think there is anything wrong with that, but I think this would do what the processor does (I could be wrong):

      foreach($objects as $object) {
          $object->remove();
      }


      Here is an example of a multiple remove processor in Quip:

      class QuipThreadNotificationRemoveMultipleProcessor extends modProcessor {
          public function initialize() {
              $notifications = $this->getProperty('notifications');
              if (empty($notifications)) {
                  return $this->modx->lexicon('quip.notification_err_ns');
              }
              return parent::initialize();
          }
          public function process() {
              $notifications = explode(',',$this->getProperty('notifications'));
              foreach ($notifications as $notificationId) {
                  /** @var $notification quipCommentNotify */
                  $notification = $this->modx->getObject('quipCommentNotify',$notificationId);
                  if (empty($notification)) {
                      $this->modx->log(modX::LOG_LEVEL_ERROR,'[Quip] Notification not found to remove with ID `'.$notificationId.'`');
                      continue;
                  }
                  $notification->remove();
              }
      
              return $this->success();
          }
      }
      return 'QuipThreadNotificationRemoveMultipleProcessor';



      ------------------------------------------------------------------------------------------
      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