From 9ba9653965c8a9f1cb9a85c99b34796165656fc3 Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Wed, 21 Feb 2018 10:38:24 +0100 Subject: [PATCH] FEAT Entity update --- src/app/entity/controllers/EntityController.php | 11 ++++++++++- src/app/entity/models/EntityModelAbstract.php | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/app/entity/controllers/EntityController.php b/src/app/entity/controllers/EntityController.php index 271ee9b7713..ae4299df192 100644 --- a/src/app/entity/controllers/EntityController.php +++ b/src/app/entity/controllers/EntityController.php @@ -199,7 +199,16 @@ class EntityController return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); } - unset($data['entity_id']); + $neededData = [ + 'entity_label', 'short_label', 'entity_type', 'adrs_1', 'adrs_2', 'adrs_3', + 'zipcode', 'city', 'country', 'email', 'business_id', 'parent_entity_id', + 'entity_path', 'ldap_id', 'archival_agreement', 'archival_agency', 'entity_full_name' + ]; + foreach ($data as $key => $value) { + if (!in_array($key, $neededData)) { + unset($data[$key]); + } + } EntityModel::update(['set' => $data, 'where' => ['entity_id = ?'], 'data' => [$aArgs['id']]]); HistoryController::add([ 'tableName' => 'entities', diff --git a/src/app/entity/models/EntityModelAbstract.php b/src/app/entity/models/EntityModelAbstract.php index bbd0115bcc6..315866b10ca 100644 --- a/src/app/entity/models/EntityModelAbstract.php +++ b/src/app/entity/models/EntityModelAbstract.php @@ -91,6 +91,11 @@ class EntityModelAbstract { ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); + ValidatorModel::stringType($aArgs['set'], [ + 'entity_label', 'short_label', 'entity_type', 'adrs_1', 'adrs_2', 'adrs_3', + 'zipcode', 'city', 'country', 'email', 'business_id', 'parent_entity_id', + 'entity_path', 'ldap_id', 'transferring_agency', 'archival_agreement', 'archival_agency', 'entity_full_name' + ]); DatabaseModel::update([ 'table' => 'entities', -- GitLab