Possible to change a working copy programmatically

I’m trying to listen to the publish event of a page, and by looking at how a field has changed I want to programmatically alter another page.

It all works, but the issue I’m seeing is if an editor has created a working copy of the page (which happens quite easily often without you actually wanting to), when I publish and change the page. He or she could later come in and publish the working copy, removing my changes.

It seems possible to load the working copy programmatically, but can you save any changes to it somehow? (Without publishing it).

One option would be to delete their working copy, but that doesn’t seem nice,

Litium version: 6.1.2-patch-1806080803

On the same way you set the value on the Page entity you can set the same value on the WorkingCopy entity to not get that value overwritten when the working copy is published.

So it is immedietely persisted when SetValue is called on the field?

Yes, that is how it is working in the older domain model. If you should update many properties it can be better to get the carrier from the entity and make all updates there and then run the UpdateFromCarrier method on the entity.