From 175f99809d9ff6a9e5b32619db3bf6f7ad2341f9 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 21 Mar 2015 15:55:49 +0100 Subject: [PATCH] Prevent an update of a location when there is a location with the same name. Fixes #23 --- .../Controller/LocationController.php | 14 ++++++++++++-- .../Resources/views/Location/edit.html.twig | 11 +++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php index 64b174a..a9ec487 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php @@ -143,8 +143,18 @@ class LocationController extends Controller } if ($location->name != $request->get('name')) { - $location->name = $request->get('name'); - $location->slug = $location->generateSlug($location->name, $em); + // someone changed the name of the location, lets check if the location already exists + $new_location = $repo->findOneBy(['name' => $request->get('name')]); + if (is_null($new_location)) { + $location->name = $request->get('name'); + $location->slug = $location->generateSlug($location->name, $em); + } else { + $request->getSession()->getFlashBag()->add( + 'error', + 'Ort mit diesem Namen existiert bereits.' + ); + return $this->redirect($this->generateUrl('location_edit', array('slug' => $location->slug))); + } } $location->streetaddress = $request->get('streetaddress'); $location->streetnumber = $request->get('streetnumber'); diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/views/Location/edit.html.twig b/src/Hackspace/Bundle/CalciferBundle/Resources/views/Location/edit.html.twig index 6eb61de..5142616 100644 --- a/src/Hackspace/Bundle/CalciferBundle/Resources/views/Location/edit.html.twig +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/views/Location/edit.html.twig @@ -29,6 +29,17 @@
+ {% set errors = app.session.flashbag.get('error') %} + {% if errors|length > 0 %} +
+
Bitte korrigiere folgende Fehler:
+
    + {% for flashMessage in errors %} +
  • {{ flashMessage }}
  • + {% endfor %} +
+
+ {% endif %}