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

    in a plugin, i try to detect the OnResourceDuplicate Event, but nothing moves in the log panel when I duplicate a resource:

    if ($modx->event->name == 'OnResourceDuplicate') {
        
        $modx->setDebug(E_ALL & ~E_NOTICE);
        $modx->setLogLevel(modX::LOG_LEVEL_DEBUG); 
        $modx->log(modX::LOG_LEVEL_DEBUG,'HI OnResourceDuplicate');
        return;
    
    }
    


    Do I something wrong?

    Yes the right system event is selected... I use MODx Revolution 2.0.4-pl2, traditional distribution on Linux with php 5.2.14.

    Thanks for your help,
    Sylvain
      • 3749
      • 24,544 Posts
      Are you duplicating the resource in the Manager? That event is in the form layer so it won’t fire when you duplicate a resource using code unless you’re running the duplicate.php processor.
      You may need a $modx->setLogTarget() in there or, instead of messing with the log, just try this to make sure:

      die(’HI OnResourceDuplicate’);

      [Edit:] one more thing. you don’t need the if() statement at all if that’s the only event the plugin is tied to. You won’t be there unless the event has fired.
        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
        • 25910
        • 26 Posts
        Hi, thanks for your response.

        Are you duplicating the resource in the Manager? That event is in the form layer so it won’t fire when you duplicate a resource using code unless you’re running the duplicate.php processor.
        I try to duplicate document via the «duplicate» button or via the contextual menu in the resource tree, not using code. I suppose that will run the duplicate.php processor, am I right?

        I would like to get the document ID created by this action (when duplicating a document), is it possible? Do you have an example?

        [Edit:] one more thing. you don’t need the if() statement at all if that’s the only event the plugin is tied to. You won’t be there unless the event has fired.
        I use several events in my plugin, OnDocFormSave and OnDocFormPrerender. Both are responding when I write a log message (or code) into, but not OnResourceDuplicate.

          • 3749
          • 24,544 Posts
          I think it should be available in the plugin as

          $newResource->get('id');
            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
            • 25910
            • 26 Posts
            Hi,

            thank you very much for your advices. $newResource->get(’id’) is working fine. and I found why the onResourceDuplicate wasn’t working. Before my onResourceDuplicate event, I wrote:

            if ($resource == null) return;

            who was blocking the event... That was only useful for the other events, so I interverted parts of my code, that’s ok now.

            I would like to thank you also for your http://bobsguides.com/revolution-objects.html, that helped me a lot!

            Bye,
            S.



              • 3749
              • 24,544 Posts
              Glad you got it sorted. Thanks for the kind words. smiley
                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