Check for duplicate keys on media if we know it's a fresh entity (#15838)
Co-authored-by: Sven Geusens <sge@umbraco.dk>
This commit is contained in:
@@ -144,6 +144,7 @@ internal sealed class MediaEditingService
|
||||
// these are the only result states currently expected from Save
|
||||
OperationResultType.Success => ContentEditingOperationStatus.Success,
|
||||
OperationResultType.FailedCancelledByEvent => ContentEditingOperationStatus.CancelledByNotification,
|
||||
OperationResultType.FailedDuplicateKey => ContentEditingOperationStatus.DuplicateKey,
|
||||
|
||||
// for any other state we'll return "unknown" so we know that we need to amend this
|
||||
_ => ContentEditingOperationStatus.Unknown
|
||||
|
||||
@@ -756,6 +756,13 @@ namespace Umbraco.Cms.Core.Services
|
||||
scope.WriteLock(Constants.Locks.MediaTree);
|
||||
if (media.HasIdentity == false)
|
||||
{
|
||||
if (_entityRepository.Get(media.Key, UmbracoObjectTypes.Media.GetGuid()) is not null)
|
||||
{
|
||||
scope.Complete();
|
||||
return Attempt.Fail<OperationResult?>(
|
||||
new OperationResult(OperationResultType.FailedDuplicateKey, eventMessages));
|
||||
}
|
||||
|
||||
media.CreatorId = userId;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,5 +40,10 @@ public enum OperationResultType : byte
|
||||
/// </summary>
|
||||
NoOperation = Failed | 6, // TODO: shouldn't it be a success?
|
||||
|
||||
/// <summary>
|
||||
/// The operation could not complete due to duplicate key detection
|
||||
/// </summary>
|
||||
FailedDuplicateKey = Failed | 7
|
||||
|
||||
// TODO: In the future, we might need to add more operations statuses, potentially like 'FailedByPermissions', etc...
|
||||
}
|
||||
|
||||
@@ -18,5 +18,6 @@ public enum ContentEditingOperationStatus
|
||||
SortingInvalid,
|
||||
PropertyValidationError,
|
||||
InvalidCulture,
|
||||
Unknown
|
||||
DuplicateKey,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user