Hi James, What version of MODx did you get your "publishDraftCopy" plugin working on? I have just followed the instructions on
https://ichosemodx.wordpress.com/2010/08/02/updating-a-published-resource-from-a-draft-copy and
http://ichosemodx.wordpress.com/2010/08/03/publishing-a-resource-from-a-draft-copy-revised-now-with-tvs but it does not work on REVO 2.2.7?
Did you get any further with developing this into a fully working solution? I'd love to chat about this as I am very keen on getting a proper CMS workflow into MODx ASAP.
With the plugin code inputed - on save of any resource - the manager falls over and the "Saving" progress bar never disapears to show the resource has been updated...? Something not right somewhere... The Plugin code I am using is:
<?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();
$restructedFields = 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;
?>
Let me know...
[ed. note: dubbs last edited this post 13 years, 2 months ago.]