1
0
Fork 0
mirror of synced 2024-09-28 15:31:43 +12:00

Recreate original on create failure with new key

This commit is contained in:
Jake Barnby 2024-09-05 20:41:50 +12:00
parent a28f19ff3c
commit 3f99f01953
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C

View file

@ -389,14 +389,19 @@ function updateAttribute(
if (!empty($newKey) && $key !== $newKey) {
// Delete attribute and recreate since we can't modify IDs
$original = clone $attribute;
$dbForProject->deleteDocument('attributes', $attribute->getId());
$attribute
->setAttribute('$id', ID::custom($db->getInternalId() . '_' . $collection->getInternalId() . '_' . $newKey))
->setAttribute('key', $newKey);
$attribute = $dbForProject->withTransaction(function () use ($dbForProject, $attribute) {
$dbForProject->deleteDocument('attributes', $attribute->getId());
return $dbForProject->createDocument('attributes', $attribute);
});
try {
$attribute = $dbForProject->createDocument('attributes', $attribute);
} catch (\Throwable) {
$attribute = $dbForProject->createDocument('attributes', $original);
}
} else {
$attribute = $dbForProject->updateDocument('attributes', $db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key, $attribute);
}