<?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;
?>
This question has been answered by BobRay. See the first response.
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.
Will do - thanks
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.
Is the plugin marked as disabled? Right-click on it in the Elements tree to find out.