We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10378
    • 375 Posts
    I have created a CRC with container and child resource handling (similar to Articles extra). I use the new modResource properties field (available since MODx 2.2.x) to store some container settings.
    My question is: How can I update all properties fields of child resources when the resource container properties are updated?

    In a processor I do this to update all child resources:

        public function afterSave() {
            // update properties of all child resources (merge with existing properties)
            $parentProperties = $this->object->getProperties('goodnews');
    
            foreach ($this->object->getIterator('Children') as $child) {
                $child->setProperties($parentProperties, 'goodnews');
                if (!$child->save()) {
                    $this->modx->log(modX::LOG_LEVEL_ERROR, "Could not change properties of child resource {$child->get('id')}", '', __METHOD__, __FILE__, __LINE__);
                }
            }
    
            //todo: clear cache?
            
            return parent::afterSave();
        }
    


    I dont know which class/method to override/use to reach this effect. The UpdateManagerController class cant be the right place...
    I had a look at the Articles sources, but they also don't update child resource settings when the container resource is updated.

    Very specific question - I know - but hopefully someone could give me a hint!?

    Thanks,
    Martin

    This question has been answered by markh. See the first response.

      Freelancer @bitego http://www.bitego.com
      ---
      GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
      More infos here: http://www.bitego.com/extras/goodnews/
    • discuss.answer
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      I personally wouldn't store container properties in the child resources at all.

      But to answer your question, you could override the save method on the actual modResource extended class and handle stuff from there. Or in your update processor.
        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.
        • 10378
        • 375 Posts
        Quote from: markh at May 17, 2013, 01:08 PM
        I personally wouldn't store container properties in the child resources at all.

        Hi Mark,

        in my case it's needed you will see... Those container settings are related to the child resources.

        Quote from: markh at May 17, 2013, 01:08 PM

        But to answer your question, you could override the save method on the actual modResource extended class and handle stuff from there. Or in your update processor.

        Thats it. Oh boy - shame on me... should really have a break now! smiley

        Thanks Mark!
          Freelancer @bitego http://www.bitego.com
          ---
          GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
          More infos here: http://www.bitego.com/extras/goodnews/