]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add a method to get the list of tags from the TagNotFound Exception
authorJoas Schilling <nickvergessen@owncloud.com>
Tue, 1 Dec 2015 13:51:26 +0000 (14:51 +0100)
committerJoas Schilling <nickvergessen@owncloud.com>
Tue, 1 Dec 2015 13:54:34 +0000 (14:54 +0100)
lib/private/systemtag/systemtagmanager.php
lib/private/systemtag/systemtagobjectmapper.php
lib/public/systemtag/isystemtagmanager.php
lib/public/systemtag/tagnotfoundexception.php
tests/lib/systemtag/systemtagmanagertest.php

index 3cc45fc9524c325796e737172efa74e2a4f77b58..8caf10d69da0fca001b9fd887b7d1d05753dfca7 100644 (file)
@@ -94,7 +94,9 @@ class SystemTagManager implements ISystemTagManager {
                $result->closeCursor();
 
                if (count($tags) !== count($tagIds)) {
-                       throw new TagNotFoundException(json_encode(array_diff($tagIds, array_keys($tags))));
+                       throw new TagNotFoundException(
+                               'Tag id(s) not found', 0, null, array_diff($tagIds, array_keys($tags))
+                       );
                }
 
                return $tags;
@@ -218,7 +220,7 @@ class SystemTagManager implements ISystemTagManager {
                try {
                        if ($query->execute() === 0) {
                                throw new TagNotFoundException(
-                                       'Tag ("' . $tagName . '", '. $userVisible . ', ' . $userAssignable . ') does not exist'
+                                       'Tag does not exist', 0, null, [$tagId]
                                );
                        }
                } catch (UniqueConstraintViolationException $e) {
@@ -238,6 +240,13 @@ class SystemTagManager implements ISystemTagManager {
                        $tagIds = [$tagIds];
                }
 
+               $tagNotFoundException = null;
+               try {
+                       $this->getTagsById($tagIds);
+               } catch (TagNotFoundException $e) {
+                       $tagNotFoundException = $e;
+               }
+
                // delete relationships first
                $query = $this->connection->getQueryBuilder();
                $query->delete(SystemTagObjectMapper::RELATION_TABLE)
@@ -248,11 +257,12 @@ class SystemTagManager implements ISystemTagManager {
                $query = $this->connection->getQueryBuilder();
                $query->delete(self::TAG_TABLE)
                        ->where($query->expr()->in('id', $query->createParameter('tagids')))
-                       ->setParameter('tagids', $tagIds, Connection::PARAM_INT_ARRAY);
+                       ->setParameter('tagids', $tagIds, Connection::PARAM_INT_ARRAY)
+                       ->execute();
 
-               if ($query->execute() === 0) {
+               if ($tagNotFoundException !== null) {
                        throw new TagNotFoundException(
-                               'Tag does not exist'
+                               'Tag id(s) not found', 0, $tagNotFoundException, $tagNotFoundException->getMissingTags()
                        );
                }
        }
index d8ff069910d32c41f97def555296ef9453c3bd3c..75f2631a010b5b5a5270426172d94e1b63083941 100644 (file)
@@ -219,7 +219,9 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
                                $tags
                        );
                        $missingTagIds = array_diff($tagIds, $foundTagIds);
-                       throw new TagNotFoundException('Tags ' . json_encode($missingTagIds) . ' do not exist');
+                       throw new TagNotFoundException(
+                               'Tags not found', 0, null, $missingTagIds
+                       );
                }
        }
 }
index ffdaf03879ede4f057156e1094b22c0fd3d7d478..4e3b263e56c97a5c644598276accd7859f440925 100644 (file)
@@ -106,7 +106,7 @@ interface ISystemTagManager {
         *
         * @param string|array $tagIds array of tag ids
         *
-        * @throws \OCP\SystemTag\TagNotFoundException if tag did not exist
+        * @throws \OCP\SystemTag\TagNotFoundException if at least one tag did not exist
         *
         * @since 9.0.0
         */
index 94bb07c8c12c979328eee0085e1813d161702f1d..d0a35eb59e9381ea2b3812ed8f2fb3982c0cff9c 100644 (file)
@@ -26,4 +26,30 @@ namespace OCP\SystemTag;
  *
  * @since 9.0.0
  */
-class TagNotFoundException extends \RuntimeException {}
+class TagNotFoundException extends \RuntimeException {
+
+       /** @var string[] */
+       protected $tags;
+
+       /**
+        * TagNotFoundException constructor.
+        *
+        * @param string $message
+        * @param int $code
+        * @param \Exception $previous
+        * @param string[] $tags
+        * @since 9.0.0
+        */
+       public function __construct($message = '', $code = 0, \Exception $previous = null, array $tags = []) {
+               parent::__construct($message, $code, $previous);
+               $this->tags = $tags;
+       }
+
+       /**
+        * @return string[]
+        * @since 9.0.0
+        */
+       public function getMissingTags() {
+               return $this->tags;
+       }
+}
index 0a192f01f414d3287223add62ec8c59c60635ce0..ad06b16e055737469bb21d21273836bba320d36e 100644 (file)
@@ -40,7 +40,7 @@ class SystemTagManagerTest extends TestCase {
 
                $this->connection = \OC::$server->getDatabaseConnection();
                $this->tagManager = new SystemTagManager($this->connection);
-       } 
+       }
 
        public function tearDown() {
                $query = $this->connection->getQueryBuilder();