We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18174
    • 116 Posts
    Just to get this clear:
    If I duplicate a container containing documents the OnRecourceDuplicate is generally fired only for the container, not for the containing child resources?
    In combination with babel plugin there is a pretty nasty bug while duplicating resources with children. While on the actual resource the babel TV's are initialized but not for the children.
    Could anybody clarify?
    best regards
    manu
      • 18174
      • 116 Posts
      Sorry for pushing this thread. But to understand the basics it's important to me to get this right: why is the OnResourceDuplicate event fired only on the actual as a parent resource and not also on the child resources? Is this a bug - or a feature? Therefore everybody using this event in a plugin has to do a recursion over the child resources possibly there (seen in the SimpleSearchIndexer plugin)?
      regards
      manu

      BTW: why is the post above not found by searching "OnResourceDuplicate"?
        • 3749
        • 24,544 Posts
        The resource/duplicate processor fires OnResourceDuplicate, then calls $resource->duplicate, which duplicates the children if that option is set. The duplicate method of the modResource object doesn't fire *any* events, so that's why the event is only fired once.

        I think it's a general principle in MODX that events are fired in the processors, if possible, and since the processor isn't really doing the duplication and definitely doesn't duplicate the children, it can't fire an event for each child.

        I *think* the code to invoke OnResourceDuplicate could be moved (with some modifications) to the modResource duplicate() method, just above the duplicate children section, just below the line where $duplicateChildren is set, but I'm not sure what the side effects might be. If you try this, back everything up and be sure to remove the invokeEvent code from the processor or it will execute twice.

        This is my best guess about what the code would look like in the modResource->dupicate() method:

        $this->modx->invokeEvent('OnResourceDuplicate',array(
                    'newResource' => &$newResource,
                    'oldResource' => &$oldResource,
                    'newName' => $newName,
                    'duplicateChildren' => $duplicateChildren,
                    'prefixDuplicate' => $prefixDuplicate,
                    'publishedMode' => $publishedMode,
                ));        
        


        [Update] I filed a feature request for this: http://tracker.modx.com/issues/9960 [ed. note: BobRay last edited this post 13 years, 3 months ago.]
          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
          • 18174
          • 116 Posts
          Thanks Bob for your clarification.
          I can do it well without a core hack.
          .. And the next one wants to write a duplicate plugin just for the initiating resource an not for the children... It's probably harder to determine if the resource to duplicate is the initial resource or is the child of.
          But it's good to clarify.
          As you see in my 1st post, the babel plugin has to be completed in this regard.
          best regards
          manu
            • 3749
            • 24,544 Posts
            I'm glad you found something that works, though I was hoping you'd test my hack and comment on the feature request. wink


              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
              • 18174
              • 116 Posts
              Hi Bob
              I tried your succestions, moved the invokeEvent from the controller to the place in duplicate() in modresource.class.php (changed argument &$oldResource to 'oldResource' => $this).
              But it doesn't work as expected. The initial resource is duplicated but the invokeEvent('OnResourceDuplicate') isnt executed (no error logged, no mgr log entry) and the child resources aren't duplicated either. If I comment out the invokeEvent command, the duplication works.
              Sofar till now, any ideas?
              regards
              manu [ed. note: manu37 last edited this post 13 years, 3 months ago.]
                • 3749
                • 24,544 Posts
                There must be something wrong with my code, but I can't see what it is. Sorry.
                  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