I’m not totally clear on what you’re doing and I’m especially unclear on why, but hopefully this will help some.
There is no OnBefore event for duplication, but I’m not sure you need it. You could certainly make that a feature request, but I don’t see the purpose since I don’t think there’s anything you could do there that you can’t do in OnResourceDuplicate. Maybe I’m missing something.
I think you may have to give up the idea of only doing it the first time (which I’m not sure I understand the purpose of, since new children may be created for every duplication). You can easily tell when a resource is being saved for the first time, but it would be impossible to know whether a resource is being *duplicated* for the first time, IMO, without storing and checking all the IDs of previously duplicated resources, which kind of defeats the purpose. I guess you could create a boolean TV called "duplicated", but I think it would cost you more time than it saves.
In converting your plugin to Revo, the first step would be to make sure that OnResourceDuplicate is actually firing. It’s in the duplicate processor and not all processors are "active" (actually used) in the current version. MODX may or may not be calling that processor when duplicating a resource with the right-click menu, for example. If not, I think you’re SOL until the processor becomes "active."
FYI, there is no alert() in Revo, so you’ll have to write to the error log to see what’s happening using $modx->log().
Bear in mind that TV values are actually independent of resources in the DB-- IOW, there’s no need to retrieve, change, or save a resource in order to set one of its TVs.
What you’re doing should be much simpler with xPDO.
At the point of OnResourceDuplicate, you have reference variables pointing to both the old and new resource and neither the new resource nor the children have been saved yet, but the new children do exist.
You can use $newResource->getChildIds() and just loop through that array to set the TV values:
$tv = $modx->getObject('modTemplateVar', $id); // $id = ID of the TV
$childIds = $newResource->getChildIds();
foreach($childIds as $childId) {
$tv->setValue($childId, 'TEMP');
}
You’ll have $oldResource->hasTempalateVar() to see if the parent has the TV.
As for modifying the parent ($oldResource), I think you can just get the TV and make your changes to it using $tv->setValue() as above.
Hope this helps.