Skip to content

Commit a5f9bba

Browse files
authored
Ensure appropriate create and update dates are set on updated dictionary items to allow distinguishing between created and update for server events. (#19925)
1 parent a39bc0e commit a5f9bba

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Umbraco.Core/Services/DictionaryItemService.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,25 @@ public async Task<Attempt<IDictionaryItem, DictionaryItemOperationStatus>> Creat
159159
/// <inheritdoc />
160160
public async Task<Attempt<IDictionaryItem, DictionaryItemOperationStatus>> UpdateAsync(
161161
IDictionaryItem dictionaryItem, Guid userKey)
162-
=> await SaveAsync(
162+
{
163+
// Create and update dates aren't tracked for dictionary items. They exist on IDictionaryItem due to the
164+
// inheritance from IEntity, but we don't store them.
165+
// However we have logic in ServerEventSender that will provide SignalR events for created and update operations,
166+
// where these dates are used to distinguish between the two (whether or not the entity has an identity cannot
167+
// be used here, as these events fire after persistence when the identity is known for both creates and updates).
168+
// So ensure we set something that can be distinguished here.
169+
if (dictionaryItem.CreateDate == default)
170+
{
171+
dictionaryItem.CreateDate = DateTime.MinValue;
172+
}
173+
174+
if (dictionaryItem.UpdateDate == default)
175+
{
176+
// TODO (V17): To align with updates of system dates, this needs to change to DateTime.UtcNow.
177+
dictionaryItem.UpdateDate = DateTime.Now;
178+
}
179+
180+
return await SaveAsync(
163181
dictionaryItem,
164182
() =>
165183
{
@@ -174,6 +192,7 @@ public async Task<Attempt<IDictionaryItem, DictionaryItemOperationStatus>> Updat
174192
AuditType.Save,
175193
"Update DictionaryItem",
176194
userKey);
195+
}
177196

178197
/// <inheritdoc />
179198
public async Task<Attempt<IDictionaryItem?, DictionaryItemOperationStatus>> DeleteAsync(Guid id, Guid userKey)

0 commit comments

Comments
 (0)