Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/photos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-08-08 17:13:32 +0300
committerLouis Chemineau <louis@chmn.me>2022-08-22 21:03:52 +0300
commit3b62ffb0f9cecd656823505dde0a9e754a76f820 (patch)
tree983c2405f6320e4fc463ac24dd8fe19ab82a7cd3 /lib
parent9c68a0fbfe8878419038e47aaebb8283cdab14ab (diff)
better error for duplicate
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'lib')
-rw-r--r--lib/Album/AlbumMapper.php20
-rw-r--r--lib/Exception/AlreadyInAlbumException.php28
2 files changed, 41 insertions, 7 deletions
diff --git a/lib/Album/AlbumMapper.php b/lib/Album/AlbumMapper.php
index 6d119322..1084b550 100644
--- a/lib/Album/AlbumMapper.php
+++ b/lib/Album/AlbumMapper.php
@@ -23,6 +23,8 @@ declare(strict_types=1);
namespace OCA\Photos\Album;
+use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
+use OCA\Photos\Exception\AlreadyInAlbumException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\IMimeTypeLoader;
use OCP\IDBConnection;
@@ -138,13 +140,17 @@ class AlbumMapper {
}
public function addFile(int $albumId, int $fileId): void {
- $query = $this->connection->getQueryBuilder();
- $query->insert("photos_albums_files")
- ->values([
- "album_id" => $query->createNamedParameter($albumId, IQueryBuilder::PARAM_INT),
- "file_id" => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)
- ]);
- $query->executeStatement();
+ try {
+ $query = $this->connection->getQueryBuilder();
+ $query->insert("photos_albums_files")
+ ->values([
+ "album_id" => $query->createNamedParameter($albumId, IQueryBuilder::PARAM_INT),
+ "file_id" => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)
+ ]);
+ $query->executeStatement();
+ } catch (UniqueConstraintViolationException $e) {
+ throw new AlreadyInAlbumException("File already in album", 0, $e);
+ }
}
public function removeFile(int $albumId, int $fileId): void {
diff --git a/lib/Exception/AlreadyInAlbumException.php b/lib/Exception/AlreadyInAlbumException.php
new file mode 100644
index 00000000..9c7d7fe3
--- /dev/null
+++ b/lib/Exception/AlreadyInAlbumException.php
@@ -0,0 +1,28 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Photos\Exception;
+
+class AlreadyInAlbumException extends \Exception {
+
+}