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

    I'm trying to write a plugin that listens for the OnDocUnPublished event for a resource *outside of the context menu.

    When a resource has reached it's unpublished date/time I want the system to move that resource to become a child of another resource i.e. Once a resource has been unpublished, remove the child from 'active articles' and make the parent the 'archive' resource.

    After consulting the docs however it seems the 'OnDocUnPublished' event only gets fired when triggered through the context menu:

    Called when a Resource is unpublished via the Unpublish context menu.

    Is there a system event that I can listen out for that will help me accomplish this?

    Quite new to MODx, so forgive me if it's clearly in the docs - I have looked to no avail.

    Many thanks
      • 4172
      • 5,888 Posts
      you can try 'OnResourceAutoPublish'

      https://github.com/modxcms/revolution/blob/master/core/model/modx/modcachemanager.class.php#L673

      [Edit]
      Seems this does only return a count of published/unpublished resources. [ed. note: Bruno17 last edited this post 9 years ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 50278
        • 2 Posts
        Thanks for the response regardless
          • 3749
          • 24,544 Posts
          OnDocUnpublished fires whenever the resource/unpublish processor is called. I would think any code that unpublished a doc would call that processor. I could definitely be wrong.

          [Update] I'm definitely wrong. No event is called in the autoPublish() method in the modCacheManager class other than OnResourceAutoPublish, and Bruno is correct that it's useless for you. Since this runs on every page load, calling the processor would probably slow it down too much. You could probably add some code there to iterate through the result set and add the Ids to the array sent to OnResourceAutoPublish, but it would slow down page loads and your changes would be overwritten when you upgrade MODX.

          If you can identify the resources you want this to happen to (e.g., unpublished Articles with parent=active articles ID, and an empty pub_date), you could write a utility snippet to do it and run it as a cron job once a day (or more). You could also put it in a plugin attached to a login event or something else that wouldn't fire too often.
            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