Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Not possible to set userModification for object #4365
I have a custom object (product) importer that create and update objects. The import is started from a front controller or a console command. I have created a pimcore admin user to represent this import. I am trying to set this user as the user modifying the object using the setUserModification method of the object. This does not work, the object is modified with user 0 instead of the user I set on the object.
I have located the problem in the method updateModificationInfos of class Pimcore\Model\Element\AbstractElement. Here the userModification value I have set is overwritten with the current admin user instead. In my case this will be the system user since there are no active admin user.
I am unsure how to best solve this. My first idea was to only get the current user if the userModification property of the object is null. The problem then is that it will rarely be null. When an existing object is loaded the userModification property has the value from the last save. There is, as I see it, no reliable way of knowing if the value of userModification is a new set value or the value from last save.
Or maybe I am looking at this elephant from the completely wrong angle?
The user id set on object with setUserModification method should be saved to the objects table in database when calling save on the object.
System (id 0) is used instead.
$product = new \Pimcore\Model\DataObject\Product(); $product->setSku('test-product'); $product->setParentId(1); $product->setUserModification(3); $product->save();