-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathAdminController.cs
More file actions
68 lines (57 loc) · 2.3 KB
/
AdminController.cs
File metadata and controls
68 lines (57 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Localization;
using OrchardCore.Contents.VersionPruning.Drivers;
using OrchardCore.Contents.VersionPruning.Models;
using OrchardCore.Contents.VersionPruning.Services;
using OrchardCore.DisplayManagement.Notify;
using OrchardCore.Entities;
using OrchardCore.Modules;
using OrchardCore.Settings;
namespace OrchardCore.Contents.VersionPruning.Controllers;
public sealed class AdminController : Controller
{
private readonly IAuthorizationService _authorizationService;
private readonly IContentVersionPruningService _pruningService;
private readonly ISiteService _siteService;
private readonly IClock _clock;
private readonly INotifier _notifier;
internal readonly IHtmlLocalizer H;
public AdminController(
IAuthorizationService authorizationService,
IContentVersionPruningService pruningService,
ISiteService siteService,
IClock clock,
INotifier notifier,
IHtmlLocalizer<AdminController> htmlLocalizer)
{
_authorizationService = authorizationService;
_pruningService = pruningService;
_siteService = siteService;
_clock = clock;
_notifier = notifier;
H = htmlLocalizer;
}
[HttpPost]
public async Task<IActionResult> Prune()
{
if (!await _authorizationService.AuthorizeAsync(User, ContentVersionPruningPermissions.ManageContentVersionPruningSettings))
{
return Forbid();
}
var settings = await _siteService.GetSettingsAsync<ContentVersionPruningSettings>();
var pruned = await _pruningService.PruneVersionsAsync(settings);
var container = await _siteService.LoadSiteSettingsAsync();
container.Alter<ContentVersionPruningSettings>(nameof(ContentVersionPruningSettings), settings =>
{
settings.LastRunUtc = _clock.UtcNow;
});
await _siteService.UpdateSiteSettingsAsync(container);
await _notifier.SuccessAsync(H["Content version pruning completed. {0} version(s) deleted.", pruned]);
return RedirectToAction("Index", "Admin", new
{
area = "OrchardCore.Settings",
groupId = ContentVersionPruningSettingsDisplayDriver.GroupId,
});
}
}