From bbbbc81faf961aea4fc4732002bc84cfa2fa8a03 Mon Sep 17 00:00:00 2001 From: Harsh Singh <143034341+singhharsh1708@users.noreply.github.com> Date: Mon, 30 Nov 2026 04:09:12 +0530 Subject: [PATCH] fix: API tag and event edits keep the assignment date and user of the tag links that stay (#8545) --- .../test_api_tag_links_keep_assignment.php | 28 +++++++++++++++++++ web/api/app/Model/Event.php | 2 +- web/api/app/Model/Tag.php | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/php/test_api_tag_links_keep_assignment.php diff --git a/tests/php/test_api_tag_links_keep_assignment.php b/tests/php/test_api_tag_links_keep_assignment.php new file mode 100644 index 0000000000..7df464d8b7 --- /dev/null +++ b/tests/php/test_api_tag_links_keep_assignment.php @@ -0,0 +1,28 @@ + true by deleting every link of the record and inserting the list again, so a tag +// or event edit that sent an Event or Tag list lost AssignedDate and AssignedBy of the links that +// stayed. 'keepExisting' only deletes the links that left the list and inserts the new ones. +// +// Pure source scan: +// php tests/php/test_api_tag_links_keep_assignment.php + +$passes = 0; +$failures = 0; + +function check($ok, $what) { + global $passes, $failures; + if ($ok) { $passes++; echo "ok - $what\n"; } else { $failures++; echo "not ok - $what\n"; } +} + +foreach (array('Tag', 'Event') as $model) { + $content = file_get_contents(__DIR__.'/../../web/api/app/Model/'.$model.'.php'); + check(preg_match("/'joinTable'\s*=>\s*'Events_Tags'[^)]*'unique'\s*=>\s*'keepExisting'/s", $content) === 1, + "$model keeps the Events_Tags links that stay in a saved list"); + check(preg_match("/'joinTable'\s*=>\s*'Events_Tags'[^)]*'unique'\s*=>\s*true/s", $content) !== 1, + "$model does not delete and reinsert every Events_Tags link"); +} + +echo "\n$passes passed, $failures failed\n"; +exit($failures ? 1 : 0); +?> diff --git a/web/api/app/Model/Event.php b/web/api/app/Model/Event.php index 1559306583..0c2659b7fa 100644 --- a/web/api/app/Model/Event.php +++ b/web/api/app/Model/Event.php @@ -130,7 +130,7 @@ class Event extends AppModel { 'joinTable' => 'Events_Tags', 'foreignKey' => 'EventId', 'associationForeignKey' => 'TagId', - 'unique' => true, + 'unique' => 'keepExisting', 'dependent' => false, 'conditions' => '', 'fields' => '', diff --git a/web/api/app/Model/Tag.php b/web/api/app/Model/Tag.php index f6205fe7a4..9f89aa00f9 100644 --- a/web/api/app/Model/Tag.php +++ b/web/api/app/Model/Tag.php @@ -83,7 +83,7 @@ class Tag extends AppModel { 'joinTable' => 'Events_Tags', 'foreignKey' => 'TagId', 'associationForeignKey' => 'EventId', - 'unique'=>true, + 'unique'=>'keepExisting', 'dependent' => false, 'conditions' => '', 'fields' => '',