Prevent an update of a location when there is a location with the same name.

Fixes #23
This commit is contained in:
Tim Schumacher 2015-03-21 15:55:49 +01:00
parent 97a71875e9
commit 175f99809d
2 changed files with 23 additions and 2 deletions

View file

@ -143,8 +143,18 @@ class LocationController extends Controller
} }
if ($location->name != $request->get('name')) { if ($location->name != $request->get('name')) {
$location->name = $request->get('name'); // someone changed the name of the location, lets check if the location already exists
$location->slug = $location->generateSlug($location->name, $em); $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->streetaddress = $request->get('streetaddress');
$location->streetnumber = $request->get('streetnumber'); $location->streetnumber = $request->get('streetnumber');

View file

@ -29,6 +29,17 @@
<div class="ui column"> <div class="ui column">
<form method="post" <form method="post"
action="{{ path('location_update',{'slug':entity.slug}) }}"> action="{{ path('location_update',{'slug':entity.slug}) }}">
{% set errors = app.session.flashbag.get('error') %}
{% if errors|length > 0 %}
<div class="ui error message">
<div class="header">Bitte korrigiere folgende Fehler:</div>
<ul class="list">
{% for flashMessage in errors %}
<li>{{ flashMessage }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<div class="ui form segment"> <div class="ui form segment">
<div class="field"> <div class="field">
<label class="" for="location-name">Name</label> <label class="" for="location-name">Name</label>