From 91e495f2519231175599f956e5b0d8b0078e106b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 17 Jan 2020 08:11:09 +0000 Subject: [PATCH] Add checking for duplicate ID. #298 --- src/Controller/StaticContentController.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Controller/StaticContentController.php b/src/Controller/StaticContentController.php index affe3fd3..395736d4 100644 --- a/src/Controller/StaticContentController.php +++ b/src/Controller/StaticContentController.php @@ -134,7 +134,8 @@ class StaticContentController extends Controller $row = new StaticContent(); // set and save values - $row->setID($req->request->get('id')); + $id = $req->request->get('id'); + $row->setID($id); $row->setContent($req->request->get('content')); // validate @@ -143,6 +144,14 @@ class StaticContentController extends Controller // initialize error list $error_array = []; + // check for duplicate ID + $result = $em->getRepository(StaticContent::class)->find($id); + if ($result != null) + { + error_log($id); + $error_array['id'] = 'Duplicate ID exists.'; + } + // add errors to list foreach ($errors as $error) { $error_array[$error->getPropertyPath()] = $error->getMessage(); @@ -213,6 +222,14 @@ class StaticContentController extends Controller // initialize error list $error_array = []; + // check for duplicate ID + $result = $em->getRepository(StaticContent::class)->find($id); + if ($result != null) + { + error_log($id); + $error_array['id'] = 'Duplicate ID exists.'; + } + // add errors to list foreach ($errors as $error) { $error_array[$error->getPropertyPath()] = $error->getMessage();