chg: [individuals:capture] Prevent ID override and usage of _accessible property

pull/67/head
mokaddem 2021-06-28 14:04:01 +02:00
parent 524dd10aae
commit 31d04b8ff4
2 changed files with 18 additions and 19 deletions

View File

@ -7,5 +7,9 @@ use Cake\ORM\Entity;
class Individual extends AppModel
{
protected $_accessible = [
'*' => true,
'id' => false,
'uuid' => false,
];
}

View File

@ -55,26 +55,21 @@ class IndividualsTable extends AppTable
return null;
}
if (empty($existingIndividual)) {
$entity = $this->newEntity($individual, ['associated' => []]);
if (!$this->save($entity)) {
return null;
}
$individual = $entity;
$entity = $this->newEmptyEntity();
$this->patchEntity($entity, $individual, [
'accessibleFields' => ['uuid' => true]
]);
$entityToSave = $entity;
} else {
$reserved = ['id', 'uuid', 'metaFields'];
foreach ($individual as $field => $value) {
if (in_array($field, $reserved)) {
continue;
}
$existingIndividual->$field = $value;
}
if (!$this->save($existingIndividual, ['associated' => false])) {
return null;
}
$individual = $existingIndividua;
$this->patchEntity($existingIndividual, $individual);
$entityToSave = $existingIndividual;
}
$this->postCaptureActions($individual);
return $individual->id;
$savedEntity = $this->save($entityToSave, ['associated' => false]);
if (!$savedEntity) {
return null;
}
$this->postCaptureActions($savedEntity);
return $savedEntity->id;
}
public function postCaptureActions($individual): void