diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/bootstrap.php | 2 | ||||
| -rw-r--r-- | lib/classes/JsonApi/Routes/ShortUrls/ShortUrlCreate.php | 9 |
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/bootstrap.php b/lib/bootstrap.php index b1b336e..4d83992 100644 --- a/lib/bootstrap.php +++ b/lib/bootstrap.php @@ -1,4 +1,4 @@ -<?php + <?php # Lifter010: TODO /* * Copyright (c) 2009 Stud.IP CoreGroup diff --git a/lib/classes/JsonApi/Routes/ShortUrls/ShortUrlCreate.php b/lib/classes/JsonApi/Routes/ShortUrls/ShortUrlCreate.php index db2a856..1b8524a 100644 --- a/lib/classes/JsonApi/Routes/ShortUrls/ShortUrlCreate.php +++ b/lib/classes/JsonApi/Routes/ShortUrls/ShortUrlCreate.php @@ -2,6 +2,7 @@ namespace JsonApi\Routes\ShortUrls; +use ShortUrl; use JsonApi\Errors\AuthorizationFailedException; use JsonApi\Errors\ConflictException; use JsonApi\JsonApiController; @@ -26,12 +27,14 @@ final class ShortUrlCreate extends JsonApiController $json = $this->validate($request, $args); - if (\ShortUrl::countBySql('path = ? AND user_id = ?', [ $json['data']['attributes']['path'], $user->id]) > 0) { - throw new ConflictException(_('Sie haben für diese Seite bereits eine Kurz-URL erstellt!')); + $short_url = ShortUrl::findOneBySQL('`path` = ? AND `user_id` = ?', [$json['data']['attributes']['path'], $user->id]); + + if ($short_url) { + return $this->getContentResponse($short_url); } if (\ShortUrl::countBySql('alias = ?', [ $json['data']['attributes']['alias']])) { - throw new ConflictException(_('Sie haben für diese Seite bereits eine Kurz-URL erstellt!')); + throw new ConflictException(_('Der verwendete Alias existiert bereits.')); } $short_url = \ShortUrl::create([ |
