* Update to proper casing * Fixed naming --------- Co-authored-by: Zeegaan <nge@umbraco.dk> Co-authored-by: Andreas Zerbst <andr317c@live.dk>
51 lines
2.0 KiB
C#
51 lines
2.0 KiB
C#
using Microsoft.Extensions.Options;
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
using Umbraco.Cms.Core.DeliveryApi;
|
|
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Cms.Core.Models.PublishedContent;
|
|
using Umbraco.Cms.Core.Notifications;
|
|
using Umbraco.Cms.Core.PublishedCache;
|
|
using Umbraco.Cms.Core.Services;
|
|
using Umbraco.Cms.Core.Sync;
|
|
|
|
namespace Umbraco.Cms.Core.Webhooks.Events;
|
|
|
|
[WebhookEvent("Content was published", Constants.WebhookEvents.Types.Content)]
|
|
public class ContentPublishWebhookEvent : WebhookEventContentBase<ContentPublishedNotification, IContent>
|
|
{
|
|
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
|
|
private readonly IApiContentBuilder _apiContentBuilder;
|
|
|
|
public ContentPublishWebhookEvent(
|
|
IWebhookFiringService webhookFiringService,
|
|
IWebhookService webhookService,
|
|
IOptionsMonitor<WebhookSettings> webhookSettings,
|
|
IServerRoleAccessor serverRoleAccessor,
|
|
IPublishedSnapshotAccessor publishedSnapshotAccessor,
|
|
IApiContentBuilder apiContentBuilder)
|
|
: base(
|
|
webhookFiringService,
|
|
webhookService,
|
|
webhookSettings,
|
|
serverRoleAccessor)
|
|
{
|
|
_publishedSnapshotAccessor = publishedSnapshotAccessor;
|
|
_apiContentBuilder = apiContentBuilder;
|
|
}
|
|
|
|
public override string Alias => Constants.WebhookEvents.Aliases.ContentPublish;
|
|
|
|
protected override IEnumerable<IContent> GetEntitiesFromNotification(ContentPublishedNotification notification) => notification.PublishedEntities;
|
|
|
|
protected override object? ConvertEntityToRequestPayload(IContent entity)
|
|
{
|
|
if (_publishedSnapshotAccessor.TryGetPublishedSnapshot(out IPublishedSnapshot? publishedSnapshot) is false || publishedSnapshot!.Content is null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
IPublishedContent? publishedContent = publishedSnapshot.Content.GetById(entity.Key);
|
|
return publishedContent is null ? null : _apiContentBuilder.Build(publishedContent);
|
|
}
|
|
}
|