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: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The following table outlines the versions of the project that are currently supp
|-----------------|-----------------|----------------------|-------------|
| [13.x](https://github.com/jcdcdev/jcdcdev.Umbraco.ReadingTime/tree/v13) | 13 | 2025-12-14 | 2026-12-14 |
| [17.x](https://github.com/jcdcdev/jcdcdev.Umbraco.ReadingTime/tree/v17) | 17 | 2027-11-27 | 2028-11-27 |
| [18.x](https://github.com/jcdcdev/jcdcdev.Umbraco.ReadingTime/tree/v18) | 18 | 2027-03-25 | 2027-06-25 |

## Unsupported Versions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface IReadingTimeService
Task ScanAll();
Task Process(IContent item);
Task<int> DeleteAsync(Guid key);
Task<int> DeleteAsync(IEnumerable<Guid> keys);
Task<ReadingTimeDto?> GetAsync(Guid key, Guid dataTypeKey);
Task<ReadingTimeDto?> GetAsync(Guid key, int dataTypeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using jcdcdev.Umbraco.ReadingTime.Core.PropertyEditors;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Extensions;
Expand All @@ -18,18 +17,41 @@ public class ReadingTimeNotificationHandler :
{
private readonly ILocalizedTextService _localizedTextService;
private readonly IReadingTimeService _readingTimeService;
private readonly IContentService _contentService;

public ReadingTimeNotificationHandler(IReadingTimeService readingTimeService, ILocalizedTextService localizedTextService)
private const int ChildrenPageSize = 1000;

public ReadingTimeNotificationHandler(IReadingTimeService readingTimeService, ILocalizedTextService localizedTextService, IContentService contentService)
{
_readingTimeService = readingTimeService;
_localizedTextService = localizedTextService;
_contentService = contentService;
}

// Both ContentDeletingNotification and ContentEmptyingRecycleBinNotification are called during emptying a global Recycle Bin empty operation
// Since individual deletes from within the Bin trigger just the ContentDeletingNotification and not the latter, this should cover both use cases
public async Task HandleAsync(ContentDeletingNotification notification, CancellationToken cancellationToken)
{
foreach (var content in notification.DeletedEntities)
foreach (var item in notification.DeletedEntities)
{
await _readingTimeService.DeleteAsync(content.Key);
var toDelete = new List<Guid> { item.Key };
var pageIndex = 0;

List<Guid> pagedDescendants;

do
{
pagedDescendants = _contentService
.GetPagedDescendants(item.Id, pageIndex, ChildrenPageSize, out _)
.Select(x => x.Key)
.ToList();

toDelete.AddRange(pagedDescendants);

pageIndex++;
} while (pagedDescendants.Count == ChildrenPageSize);

await _readingTimeService.DeleteAsync(toDelete);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace jcdcdev.Umbraco.ReadingTime.Infrastructure.Persistence;
public interface IReadingTimeRepository
{
Task<int> DeleteAsync(Guid key);
Task<int> DeleteAsync(IEnumerable<Guid> key);
Task<ReadingTimeDto> GetOrCreate(Guid key, IDataType dataType);
Task PersistAsync(ReadingTimeDto dto);
Task<ReadingTimeDto?> Get(Guid key, int dataTypeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ public Task<int> DeleteAsync(Guid key)
return Task.FromResult(data);
}

public Task<int> DeleteAsync(IEnumerable<Guid> keys)
{
using var scope = _scopeProvider.CreateScope();

var sql = scope.SqlContext
.Sql()
.Delete<ReadingTimePoco>()
.WhereIn<ReadingTimePoco>(x => x.Key, keys);

var data = scope.Database.Execute(sql);

scope.Complete();

return Task.FromResult(data);
}

public async Task<ReadingTimeDto> GetOrCreate(Guid key, IDataType dataType)
{
var dto = await Get(key, dataType.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public async Task<int> DeleteAsync(Guid key)
return await _readingTimeRepository.DeleteAsync(key);
}

public async Task<int> DeleteAsync(IEnumerable<Guid> keys)
{
_logger.LogDebug("Deleting reading time for {Keys}", keys);
return await _readingTimeRepository.DeleteAsync(keys);
}

public async Task ScanTree(int homeId)
{
var content = _contentService.GetById(homeId);
Expand Down
Loading