From 4c85a2aae0c5c48bbb17557c6232675d2432df21 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Wed, 14 Jul 2021 10:11:48 +0200 Subject: [PATCH] fix: [tags:attachTagToObject] No longer return a failure message is relation already exists Fix #6569 --- app/Controller/TagsController.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Controller/TagsController.php b/app/Controller/TagsController.php index dc974e33a..6021e0e2f 100644 --- a/app/Controller/TagsController.php +++ b/app/Controller/TagsController.php @@ -785,6 +785,7 @@ class TagsController extends AppController } $successes = 0; $fails = array(); + $existingRelations = array(); foreach ($tags as $k => $tag) { if (is_numeric($tag)) { $conditions = array('Tag.id' => $tag); @@ -842,7 +843,9 @@ class TagsController extends AppController 'conditions' => $conditions )); if (!empty($existingAssociation)) { - $fails[] = __('%s already has the requested tag attached, no changes had to be made.', $objectType); + $message = __('%s already has the requested tag attached, no changes had to be made for tag %s.', $objectType, $existingTag['Tag']['name']); + $existingRelations[] = $existingTag['Tag']['name']; + $successes++; continue; } $this->$objectType->$connectorObject->create(); @@ -882,6 +885,9 @@ class TagsController extends AppController if ($successes > 0) { if ($successes > 1) { $message = __('Successfully attached %s tags to %s (%s)', $successes, $objectType, $object[$objectType]['id']); + if (!empty($existingRelations)) { + $message .= __('. %s already has the requested tag attached, no changes had to be made for tags %s.', $object[$objectType]['id'], json_encode($existingRelations)); + } } $message .= !empty($fails) ? PHP_EOL . $failedMessage : ''; return $this->RestResponse->saveSuccessResponse('Tags', 'attachTagToObject', false, $this->response->type(), $message);