Hi,
I'm subclassing \Espo\Services\Record to intercept updates for a custom Entity. There I'm overriding beforeUpdateEntity() to find out what attributes are being updated. Looking at the updateEntity($id, $data) method it seems to me that beforeUpdateEntity($entity, $data) is actually misplaced because its called just after $entity->set($data).. shouldn't be moved before 'setting' new data? If not how could I find which attributes values are being updated?
thanks, best regards,
Michele
I'm subclassing \Espo\Services\Record to intercept updates for a custom Entity. There I'm overriding beforeUpdateEntity() to find out what attributes are being updated. Looking at the updateEntity($id, $data) method it seems to me that beforeUpdateEntity($entity, $data) is actually misplaced because its called just after $entity->set($data).. shouldn't be moved before 'setting' new data? If not how could I find which attributes values are being updated?
Code:
public function updateEntity($id, $data)
{
unset($data->deleted);
if (empty($id)) {
throw new BadRequest();
}
$this->filterInput($data);
$this->handleInput($data);
unset($data->modifiedById);
unset($data->modifiedByName);
unset($data->modifiedAt);
unset($data->createdById);
unset($data->createdByName);
unset($data->createdAt);
if ($this->getEntityBeforeUpdate) {
$entity = $this->getEntity($id);
} else {
$entity = $this->getRepository()->get($id);
}
if (!$entity) {
throw new NotFound();
}
if (!$this->getAcl()->check($entity, 'edit')) {
throw new Forbidden();
}
$entity->set($data);
$this->beforeUpdateEntity($entity, $data);
if (!$this->isValid($entity)) {
throw new BadRequest();
}
if (!$this->checkAssignment($entity)) {
throw new Forbidden();
}
if ($this->checkForDuplicatesInUpdate) {
$this->processDuplicateCheck($entity, $data);
}
if ($this->storeEntity($entity)) {
$this->afterUpdateEntity($entity, $data);
$this->prepareEntityForOutput($entity);
$this->processActionHistoryRecord('update', $entity);
return $entity;
}
throw new Error();
}
Michele

Comment