Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Umbraco.Core/Services/MediaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,6 @@ public void DeleteVersion(int id, int versionId, bool deletePriorVersions, int u
MoveToRecycleBinEventInfo<IMedia>[] moveInfo = moves.Select(x => new MoveToRecycleBinEventInfo<IMedia>(x.Item1, x.Item2)).ToArray();
scope.Notifications.Publish(new MediaMovedToRecycleBinNotification(moveInfo, messages).WithStateFrom(movingToRecycleBinNotification));
Audit(AuditType.Move, userId, media.Id, "Move Media to recycle bin");

scope.Complete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
// See LICENSE for more details.

using System.Globalization;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
using Umbraco.Extensions;
using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope;

namespace Umbraco.Cms.Core.Events;

Expand All @@ -21,21 +23,35 @@ public sealed class RelateOnTrashNotificationHandler :
private readonly IAuditService _auditService;
private readonly IEntityService _entityService;
private readonly IRelationService _relationService;
private readonly IScopeProvider _scopeProvider;
private readonly ICoreScopeProvider _scopeProvider;
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
private readonly ILocalizedTextService _textService;

[Obsolete("Use the new constructor instead, will be removed in V16")]
public RelateOnTrashNotificationHandler(
IRelationService relationService,
IEntityService entityService,
ILocalizedTextService textService,
IAuditService auditService,
IScopeProvider scopeProvider)
: this(relationService, entityService, textService, auditService, scopeProvider, StaticServiceProvider.Instance.GetRequiredService<IBackOfficeSecurityAccessor>())
{
}

public RelateOnTrashNotificationHandler(
IRelationService relationService,
IEntityService entityService,
ILocalizedTextService textService,
IAuditService auditService,
IScopeProvider scopeProvider,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
{
_relationService = relationService;
_entityService = entityService;
_textService = textService;
_auditService = auditService;
_scopeProvider = scopeProvider;
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
}

public void Handle(ContentMovedNotification notification)
Expand All @@ -56,7 +72,7 @@ public void Handle(ContentMovedNotification notification)

public void Handle(ContentMovedToRecycleBinNotification notification)
{
using (IScope scope = _scopeProvider.CreateScope())
using (ICoreScope scope = _scopeProvider.CreateCoreScope())
{
const string relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias;
IRelationType? relationType = _relationService.GetRelationTypeByAlias(relationTypeAlias);
Expand Down Expand Up @@ -90,7 +106,7 @@ public void Handle(ContentMovedToRecycleBinNotification notification)

_auditService.Add(
AuditType.Delete,
item.Entity.WriterId,
_backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.Id ?? item.Entity.WriterId,
item.Entity.Id,
UmbracoObjectTypes.Document.GetName(),
string.Format(_textService.Localize("recycleBin", "contentTrashed"), item.Entity.Id, originalParentId));
Expand Down Expand Up @@ -118,7 +134,7 @@ public void Handle(MediaMovedNotification notification)

public void Handle(MediaMovedToRecycleBinNotification notification)
{
using (IScope scope = _scopeProvider.CreateScope())
using (ICoreScope scope = _scopeProvider.CreateCoreScope())
{
const string relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias;
IRelationType? relationType = _relationService.GetRelationTypeByAlias(relationTypeAlias);
Expand Down Expand Up @@ -150,7 +166,7 @@ public void Handle(MediaMovedToRecycleBinNotification notification)
_relationService.Save(relation);
_auditService.Add(
AuditType.Delete,
item.Entity.CreatorId,
_backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.Id ?? item.Entity.WriterId,
item.Entity.Id,
UmbracoObjectTypes.Media.GetName(),
string.Format(_textService.Localize("recycleBin", "mediaTrashed"), item.Entity.Id, originalParentId));
Expand Down