We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    Not sure about Revo, but in Evo the OnDocPublished event is only triggered when an existing resource is explicitly published; new docs are already published by default so the event isn’t triggered. I use OnDocFormSave (or whatever it’s actually called) then check in the code to make sure it’s a new resource. The event passes the "mode" and "id" values; mode being either ’new’ or ’upd’.
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 3749
      • 24,544 Posts
      Quote from: OpenGeek at Jan 09, 2010, 11:08 AM

      All you need do is have the plugin listen on both OnDocPublished and OnDocFormSave to handle cases where someone is directly calling the publishing action, with it’s own event vs. editing a document and changing the published status (potentially along with a great many other things).

      I do not agree that this is a bug; it may not be totally intuitive to have to handle both events, but this is the way the event model is currently implemented and used.

      I tried messing with this and I’m not sure the logic makes sense. It looks like OnDocPublished is only invoked in the publish processor, and I can’t find any places where it’s being called. Neither the publish processor not OnDocPublished are fired by the resource create and update processors, which both publish documents. If OnDocPublished *is* called somewhere, it seems that a plugin listening to both events might execute the code twice unless there’s some system for deciding when OnDocPublished is and isn’t invoked. And that raises the question: why have an OnDocPublished event if it isn’t invoked every time a document is published. I have the same question with OnActivateUser.

      It seems to me that it would make more sense to invoke OnDocPublished in the resource object’s save() method and nowhere else (and OnActivateUser invoked in the user object’s save method).

      I was also surprised to find that there’s no OnResourceBeforeSave event to match all the other OnObjectBeforeSave events. That would be a logical place to check for publication if OnDocPublished is unreliable.

      I couldn’t see any method that would work when when a resource is set to published in code or bulk action (e.g. Batcher).
        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
        • 22303 MODX Staff
        • 10,725 Posts
        We’re not triggering all these form/action events inside the model. And you simply attach your processes to all the necessary events. The events are for extending the content management system, not the data model.

        OnDocPublished is for the resource/publish action/processor. The resource/create and resource/update processors have their own events.
          • 3749
          • 24,544 Posts
          Quote from: OpenGeek at Apr 11, 2011, 04:48 PM

          We’re not triggering all these form/action events inside the model. And you simply attach your processes to all the necessary events. The events are for extending the content management system, not the data model.

          OnDocPublished is for the resource/publish action/processor. The resource/create and resource/update processors have their own events.

          But we do trigger lots of OnBeforeObjectSave events in the model, no?

          And if some snippet or plugin that I have installed does this:

          resource->set('published','1');
          resource->save();
          


          What event would I listen for to catch that?

          Is there a reason why there’s no OnResourceBeforeSave event in the model layer?
            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
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            I would presume that when you manually publish (or do any other "event" function) you would have to trigger the event yourself. In Evo, it’s done with $modx->invokeEvent($evtName, $extParams=array()).

            The WebLoginPE snippet does this:
            $modx->invokeEvent("OnBeforeWebLogin", $parameters);
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org