Thought I might be able to do it via cancelling the publish.. as below using !hasIdentity for a new item.. but seems the auto publish calls publish twice.. I get a publish without Identity and then a publish with identity on the same UID from the single record import :-(
public class ContentPublishing : INotificationHandler<ContentPublishingNotification>
{
public void Handle(ContentPublishingNotification notification)
{
foreach (var node in notification.PublishedEntities)
{
if (node.ContentType.Alias.Equals("tenderPage"))
{
// new item
if (node.Name?.Equals("MidEastAntrimBoroughCouncilNI.210623") ?? false)
{
if (!node.HasIdentity)
{
notification.CancelOperation(new EventMessage("Publishing Cancelled",
"Initial import has this flagged as do not display.",
EventMessageType.Info));
}
else
{
var x = "published";
}
}
}
}
}
}
Aah.. we have notifications in cmsImport.. this did the trick making sure not to AutoPublish
public void Handle(RecordImportedNotification<IContent> notification)
{
var scopeProps = new Dictionary<string, object> { { "@ImportFields", notification.Items } };
using (_logger.BeginScope(scopeProps))
{
if (notification.ProviderAlias == "ContentImportProvider")
{
// used to publish dependant on a csv property, AutoPublish should be false
if (!notification.Item.Published)
{
if (notification.Items["TenderDisplay"]?.ToString()?.Equals("1") ?? false)
{
_contentService.SaveAndPublish(notification.Item);
_logger.LogInformation("RecordImporting PUBLISHED content {primaryKey}", notification.PrimaryKeyValue);
}
}
_logger.LogInformation("RecordImporting content {primaryKey}", notification.PrimaryKeyValue);
}
}
}
Conditional Publishing on csv field?
Rather than just auto publish all imported content nodes, can we have a boolean value from the csv dictate publishing?
I guess a work around is to import the field and translate to a date for the publishschedule via a field provider, but that seems a little hacky?
Thought I might be able to do it via cancelling the publish.. as below using !hasIdentity for a new item.. but seems the auto publish calls publish twice.. I get a publish without Identity and then a publish with identity on the same UID from the single record import :-(
Aah.. we have notifications in cmsImport.. this did the trick making sure not to AutoPublish
Great you found the answer I was about to reply, use Notifications :-)
is working on a reply...