$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;
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) {
$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)
$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()
);
}
}
*
* @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;
+ }
+}