Closed ascheider closed 1 year ago
Which Pimcore event exactly do you mean? Currently the preAdd
, preUpdate
and postUpdate
events for the corresponding target element type do get triggered, so in your case https://github.com/pimcore/pimcore/blob/d4d577dec5487130cb2c5bd62993080df7438267/lib/Event/DataObjectEvents.php#L25, right?
@BlackbitDevs i debuged the issue. You are right, the event is called. The problem is, after uuid generation i set the uuid with setter, but do not save object, because it is saved by core afterwards:
$uuId = \str_replace('-', '', Uid::v4()->__toString()); $obj->setInternalid($uuId);
So if i add the object via admin, the uuid is set and saved to the object. But if i import the object and set uuid, data director does not persists this data afterwards and the uuid field is empty in the object.
Correct, the reason is the optimized saving - only mapped import fields get saved while Pimcore always saves all fields (which makes it slow). Now there are 2 options for you to get the UUID saved:
$params['currentObjectData']['id']
: if it is empty, a new object got created instead of updating an existing one.@BlackbitDevs Nice. Thanks. I will try it 👍
Pimcore has many standard data object events, where things can be manipulated. We have event for the customer, where we use pre add event, to generate uuid. This is done one time on creation. If we import objects with data director, the uuid is missing, because the event is not triggered from data director. Unfortunately i can not use callback function to generate uuid's like Uid::v4()->__toString(), because the will be overwritten if i execute import more than once. is it possible to add/fire pre add event, if object is fresh created via data director? Thanks!