Change Object Parent / Key without Flushing Saved but Unpublished Changes #16962
-
If I have "saved" but not "published" (ie in DB) changes to an Object, is there anyway to change an Object's Parent (or Key) without also flushing (i.e. saving) those other changes to the DB? We would like to change an Object's Parent as it moves through a workflow (so that our users can easily find all of the Objects at a given state). However we are not publishing (to the DB) until the final state of the workflow. Unfortunately any change to the Parent field requires a "save", which then flushes all the other saved but unpublished changes to the DB. Is there any way around this, where I can selectively update in the DB only certain fields (ie the Parent)? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 14 replies
-
This is a quite complex question. There is definitely no way to selectively update single fields only. But when you load the current object from the database you will get the currently stored database state/entry. When you then only change the parent and save the object with disabled object versioning (Version::disable()) you will only change the parent in the database and not infect or create any versions. In the unpublished version you would then need to ensure that it does not get moved back to the original folder as soon as it get's published. When you want to do this some kind of event listener within the workflow you could do something like: |
Beta Was this translation helpful? Give feedback.
-
The data object (so the database state) and it's version are two relatively independent things. The version is a php serialized version of the object on a given timestamp in the filesystem. So it contains all attributes 1:1 as they were when you saved the object and the version was created. So when you are working with the normal PHP API you will not get the latest version but the data object (database representation). The whole topic of "replacing" the data base state with information from the filesystem version is done in the Pimcore backend (see e.g. here https://github.com/pimcore/admin-ui-classic-bundle/blob/d191bcd0184f77e3ac9d25270ee02a4fcc2496aa/src/Controller/Admin/DataObject/DataObjectController.php#L302). So when you open the object you will see the latest version instead of the database content. When you then publish the object the version information will be persistet in the database. |
Beta Was this translation helpful? Give feedback.
This version date is based on the modification date. The reason why it does not work is that the modification date only is set as dirty when it actually changes:
https://github.com/pimcore/pimcore/blob/11.x/models/Element/AbstractElement.php#L162
All of this seems to be really some kind of hack, but if you would like to achieve that the published checkbox is still there, you would need something like this: