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 class Individual extends AppModel
{ {
protected $_accessible = [
'*' => true,
'id' => false,
'uuid' => false,
];
} }

View File

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