We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37743
    • 49 Posts
    So... having some great times with the new class-based processors. Setting up CMPs that pull from external API data sources, so as such I don't have a DB model to use.

    I can really see the power available with the processors, but when trying to use them for non-db data it just seems a bit hacky, and I wanted to get some opinions on best practice.

    so.. here's my custom processor...
    <?php 
    class McmCampaignRemoveProcessor extends modObjectRemoveProcessor {
        public $languageTopics = array('mcm:default');
        public $classKey = 'McmCampaign';
        public $objectType = 'mcm.campaign';
    
    //-----------------------------------------------------------------------------------------------------------	
    //-----------------------------------------------------------------------------------------------------------	
    public function initialize(){
    		global $modx;
    		
    		$modx->addPackage('delete',$modx->getOption('core_path').'components/mcm/'.'processors/campaigns/','');
    
    		require_once $modx->getOption('core_path').'components/mcm/lib/mcm/ModxCampaignMonitor.class.php';
    		$this->MCM = new ModxCampaignMonitor();
    		
            return parent::initialize(); 
        }//
    
    //-----------------------------------------------------------------------------------------------------------	
    //-----------------------------------------------------------------------------------------------------------	
    public function process(){
    		global $modx;
    		$props = $this->getProperties();
    		
    	/*	if($result != "SUCCESS"){
    			return $this->failure('ERROR '.print_r($result,true).' - Unknown');
    		};
    	*/	
    		return $this->failure('Campaign has been deleted');
    	}//
    }
    return 'McmCampaignRemoveProcessor';


    Now I have followed this outline for create & getList processors without a problem, but as soon as I try with a remove processor it kept kicking up _err_ns errors. I eventually got around the issue by changing the initialize() function to return true rather than the parent value but this approach just seems a bit hacky, maybe its just me.

    Should I be extending a higher-level class to get a non-db processor?
      • 28215
      • 4,149 Posts
      Yes; only use the modObject*Processor classes if you are representing xPDOObjects in your processors. They are designed for quick class bridges.

      If you are representing external data, I recommend overriding modProcessor.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 37743
        • 49 Posts
        yet again, straight in there with the info i was looking for, solved my issues a treat. Thanks Shaun... it's almost like you build this sh*t or something! tongue