partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit dda82a63c098ea6171c9d1b0a266c10f53db79ab
parent 2eb694c76066c26add067c1c38319bbcf9a4b6ff
Author: felicitus <felicitus@felicitus.org>
Date:   Sat, 28 Jan 2012 17:17:51 +0100

Better error message when a storage location already exists, fixes #132

Diffstat:
Msrc/backend/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocationService.php | 17++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocationService.php b/src/backend/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocationService.php @@ -1,11 +1,13 @@ <?php namespace de\RaumZeitLabor\PartKeepr\StorageLocation; + use de\RaumZeitLabor\PartKeepr\Service\RestfulService; declare(encoding = 'UTF-8'); use de\RaumZeitLabor\PartKeepr\Service\Service; use de\RaumZeitLabor\PartKeepr\Part\PartManager, + de\RaumZeitLabor\PartKeepr\Util\SerializableException, de\RaumZeitLabor\PartKeepr\Stock\StockEntry, de\RaumZeitLabor\PartKeepr\PartKeepr, de\RaumZeitLabor\PartKeepr\Session\SessionManager; @@ -41,7 +43,20 @@ class StorageLocationService extends Service implements RestfulService { $storageLocation->deserialize($this->getParameters()); PartKeepr::getEM()->persist($storageLocation); - PartKeepr::getEM()->flush(); + + try { + PartKeepr::getEM()->flush(); + } catch (\PDOException $e) { + if ($e->getCode() == "23505") { + $exception = new SerializableException(sprintf(PartKeepr::i18n("Storage Location %s already exists!"), $storageLocation->getName())); + $exception->setDetail(sprintf(PartKeepr::i18n("You tried to add the storage location %s, but a storage location with the same name already exists."), $storageLocation->getName())); + + throw $exception; + } else { + throw $e; + } + } + return array("data" => $storageLocation->serialize()); }