fix: API tag and event edits keep the assignment date and user of the tag links that stay (#8545)

This commit is contained in:
Harsh Singh authored and GitHub committed 2026-11-29 17:39:12 -05:00
1 parent 185c542356
commit bbbbc81faf
3 files changed
+30 -2

No files matched your search

@@ -0,0 +1,28 @@
<?php
// Events_Tags carries when and by whom each tag was assigned. Cake saves a hasAndBelongsToMany list
// with 'unique' => 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);
?>
+1 -1
View File
@@ -130,7 +130,7 @@ class Event extends AppModel {
'joinTable' => 'Events_Tags',
'foreignKey' => 'EventId',
'associationForeignKey' => 'TagId',
'unique' => true,
'unique' => 'keepExisting',
'dependent' => false,
'conditions' => '',
'fields' => '',
+1 -1
View File
@@ -83,7 +83,7 @@ class Tag extends AppModel {
'joinTable' => 'Events_Tags',
'foreignKey' => 'TagId',
'associationForeignKey' => 'EventId',
'unique'=>true,
'unique'=>'keepExisting',
'dependent' => false,
'conditions' => '',
'fields' => '',