I've been trying to help out on this issue. https://tracker.moodle.org/browse/MDL-59227 I tried to elicit help for a while, but recently found out that this is the place to go. Thought I might see if anyone was willing to take a look. Basically we are trying to differentiate a copied object from the original.
The issue we had was trying to dynamically find the id in the right table. newcmid is the id for a different table it seems. If anyone has any suggestions or wants to take our work and run with it feel free to comment below and I'll see what sort of collaboration I can work on.