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

Answered Draft resources

    • 51020
    • 670 Posts
    One thing I would love to be able to do is save a 'draft' version of a live resource, so that contributors can check it over, and once happy, publish it - which would overwrite the live resource, as a way of people reviewing changes BEFORE they go live.

    After searching around, I found a very old post, which had a plugin which could do just that - but I think that due to the age of this it's not valid for the latest version of Modx Rev as it's not working:

    https://ichosemodx.wordpress.com/2010/08/03/publishing-a-resource-from-a-draft-copy-revised-now-with-tvs/


    This is the plugin code, which is bound to “OnDocFormSave” which fires just after a resource is saved through the manager form:

    <?php
    $pagetitle = $resource->get(‘pagetitle’);
    //if the “draft” flag is in the title AND the user “published” the draft
    if (
    (preg_match(‘/\(draft-(?P<id>\d+)-\)/’, $pagetitle, $results ))&&
    ($resource->get(‘published’))
    ) {
    // the ID of the resource  to publish to
    $prodID = $results[‘id’];
    // if $prodID represents a real & published resource
    if ($prodResource = $modx->getObject(‘modResource’,
    array(‘id’=>$prodID,’published’=>1))) {
    $newVals = $resource->toArray();
    $restrictedFields = array(‘alias’=>”,’parent’=>”); //fields not to update
    $filteredVals = array_diff_key($newVals,$restrictedFields);
    $prodResource->fromArray($filteredVals);
    
    //take out the “draft” token before setting pagetitle
    $prodResource->set(‘pagetitle’, str_replace($results[0], ”, $pagetitle));
    $prodResource->save();
    
    $newTVs = $resource->getMany(‘TemplateVars’);
    foreach ($newTVs as $TV) {
    $newval = $TV->getValue($resource->get(‘id’));
    $TV->setValue($prodResource->get(‘id’), $newval);
    $TV->save();
    }
    
    }
    //unpublish the draft resource
    $resource->set(‘published’, 0);
    $resource->save();
    }
    return;
    ?>
    


    With this installed, it simply hangs when trying to save a resource.
    Any ideas on either how I can get this to work, or does someone have another way of creating drafts of resources which can then be published and retain the original ID?

    Thanks for your thoughts!
    Andy

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

      • 37105
      • 194 Posts
      Take a look at this extra https://extras.io/extras/preview/. They have also a more compicated extra called Workflow.

      I also discovered another project like https://github.com/modxcms/Revise
        Codeplaza Webdesign: for professional websites at low cost
        • 3749
        • 24,544 Posts
        You might take a look at StageCoach. It lets you stage updated versions of existing resources. Anyone can review the new version before the date that it replaces the current one.
          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
          • 51020
          • 670 Posts
          Thanks bob a I will definitely take a look at that - sounds perfect!
            • 3749
            • 24,544 Posts
            It hasn't been tested for quite a while, so there could be problems with the current version of MODX. Let me know if you run into trouble.
              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
              • 51020
              • 670 Posts
              Will do - thanks
                • 51020
                • 670 Posts
                Quote from: BobRay at Feb 25, 2017, 04:15 AM
                It hasn't been tested for quite a while, so there could be problems with the current version of MODX. Let me know if you run into trouble.

                I have installed this. I'm not sure what should happen, but if I have a resource (1) and create a new resource (2) and select the Stage ID of 1, I'm expecting the content of 2 to replace the content of 1 - but what it's doing is leaving the content of Resource 1 as it is, but appending the modification date to the pagetitle.

                But the new resource (2) content isn't live in its place.

                Am I doing something wrong?

                Thanks
                Andy
                  • 51020
                  • 670 Posts
                  Quote from: tm2000 at Feb 25, 2017, 07:16 AM
                  Will do - thanks

                  Quote from: BobRay at Feb 25, 2017, 04:15 AM
                  It hasn't been tested for quite a while, so there could be problems with the current version of MODX. Let me know if you run into trouble.

                  Also Bob - I'm finding that the staged resources aren't going into the staged resources folder.
                  Also, I selected a future time/date on the new resource, but the time stamp on the original Live resource pagetitle changed instantly to that future time/date stamp. But the new content didn't go live.

                  I'm running the latest version of Modx Rev.

                  Regards
                  Andy
                    • 3749
                    • 24,544 Posts
                    Is the plugin marked as disabled? Right-click on it in the Elements tree to find out.
                      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
                      • 51020
                      • 670 Posts
                      Quote from: BobRay at Feb 27, 2017, 07:34 PM
                      Is the plugin marked as disabled? Right-click on it in the Elements tree to find out.

                      No itsnit disabled.
                      It's doing something - but not what I'm expecting
                      The staging date isn't being honoured and I thought that if you added a resource id, it would replace the content of that resource when the date was current.