chg: [individuals:capture] Prevent ID override and usage of _accessible property
parent
524dd10aae
commit
31d04b8ff4
|
@ -7,5 +7,9 @@ use Cake\ORM\Entity;
|
||||||
|
|
||||||
class Individual extends AppModel
|
class Individual extends AppModel
|
||||||
{
|
{
|
||||||
|
protected $_accessible = [
|
||||||
|
'*' => true,
|
||||||
|
'id' => false,
|
||||||
|
'uuid' => false,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
if (!$this->save($existingIndividual, ['associated' => false])) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
$individual = $existingIndividua;
|
|
||||||
}
|
}
|
||||||
$this->postCaptureActions($individual);
|
$savedEntity = $this->save($entityToSave, ['associated' => false]);
|
||||||
return $individual->id;
|
if (!$savedEntity) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$this->postCaptureActions($savedEntity);
|
||||||
|
return $savedEntity->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postCaptureActions($individual): void
|
public function postCaptureActions($individual): void
|
||||||
|
|
Loading…
Reference in New Issue