Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mike Chambers 635 posts 1252 karma points c-trib
    Jun 22, 2023 @ 16:42
    Mike Chambers
    0

    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?

  • Mike Chambers 635 posts 1252 karma points c-trib
    Jun 23, 2023 @ 10:40
    Mike Chambers
    0

    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";
                        }
                    }
    
                }
            }
        }
    }
    
  • Mike Chambers 635 posts 1252 karma points c-trib
    Jun 23, 2023 @ 11:50
    Mike Chambers
    0

    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);
                }
            }
        }
    
  • Richard Soeteman 4036 posts 12864 karma points MVP
    Jun 26, 2023 @ 06:12
    Richard Soeteman
    0

    Great you found the answer I was about to reply, use Notifications :-)

Please Sign in or register to post replies

Write your reply to:

Draft