Copied to clipboard

Flag this post as spam?

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


  • nickornotto 397 posts 900 karma points
    Sep 06, 2017 @ 13:41
    nickornotto
    0

    How to permanently delete IPublishedContent dynamically?

    I'm creating new nodes (IContent), saving and publishing.

    Then I'm executing the same script, checking the content (IPublishedContent) exists and deleting IContent using IPublishedContent Id.

    Then checking if IPublishedContent exists - it exists - while IContent doesn't exist any more.

    umbraco.config is not getting updated (the nodes still exist).

    How to permanently delete IPublishedContent dynamically?

    IPublishedContent existingContent = rootNode.Children.FirstOrDefault(i => i.DocumentTypeAlias == "MyAlias" && i.GetPropertyValue("propertyId").ToString() == item.PropertyId.ToString());
                IContent content;
    
                string name = item.Title;
    
                    if (existingContent != null) // after deleteing the IContent the next time I run the script the existingContent is not null and picks up the content which does not exist anymore
                    {
                        content = _contentService.GetById(existingContent.Id); // second run content is empty while existingContent still exists
    
                        // delete content - only second run (first run Delete line is commented out
                        if (content != null)
                        {
                            _contentService.Delete(content); // here content getting deleted
                        }
                    }
    
    ...
    
    var createResponse = _contentService.SaveAndPublishWithStatus(content);
    
  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Sep 06, 2017 @ 14:16
    Alex Skrypnyk
    0

    Hi Manila

    I think you can republish content with this method:

    Services.ContentService.RePublishAll();
    

    Thanks

    Alex

  • nickornotto 397 posts 900 karma points
    Sep 06, 2017 @ 14:19
    nickornotto
    0

    I don't want to republish all content, I want to find the content by IPublishedContent id.

    So I can update it or delete it.

    Currently I can find IPublishedContent but if I want to find IContent by its Id it's null and I need to create another content and publish which ends up in duplicating the content.

    And in the back office old content (which I already deleted but still exists as IPublishedContent) and newly added content reappears.

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Sep 06, 2017 @ 14:27
    Alex Skrypnyk
    2

    Another solution is to unpublish node before deletion:

                    _contentService.UnPublish(content);
                    _contentService.Delete(content); // here content getting deleted
    
  • nickornotto 397 posts 900 karma points
    Sep 06, 2017 @ 14:32
    nickornotto
    0

    What if the content has been already been deleted but still exists as IPublishedContent?

    I need to remove IPublishedContent permanently - wherever it resides

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Sep 06, 2017 @ 14:32
    Alex Skrypnyk
    0

    If the content has been deleted, you have to republish all site once.

  • nickornotto 397 posts 900 karma points
    Sep 06, 2017 @ 14:49
    nickornotto
    0

    I can't republish all site because I cannot publish other items which should remain unpublished.

    Can I republish only selected node's children?

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Sep 06, 2017 @ 14:54
    Alex Skrypnyk
    0

    Manila, republish is republishing only existing published content, content items that have been removed will not be published during republish.

    Alex

  • nickornotto 397 posts 900 karma points
    Sep 06, 2017 @ 15:13
    nickornotto
    0

    Ok

    I did

    _contentService.RePublishAll();
    

    then

                foreach(IPublishedContent published in rootNode.Children)
                {
                    // published exists
                    IContent cont = _contentService.GetById(published.Id);
                    // cont still doesn't exist so I cannot unpublish it
                    if(cont != null)
                    {
                        _contentService.UnPublish(cont);
                    }
                }
    

    Cont still doesn't exist so I cannot unpublish it.

    Although some content exists but then

    _contentService.UnPublish(cont);

    does nothing - the content stays published and displays in bakc office.

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Sep 06, 2017 @ 15:25
    Alex Skrypnyk
    0

    You can see published and unpublished content in the back office.

  • nickornotto 397 posts 900 karma points
    Sep 06, 2017 @ 15:34
    nickornotto
    0

    The content I've just unpublished appears to be published and I've just said I can still get it as IPublishedContent - it means it remains published.

    The problem remains - even though the content is published I cannot get it using

    _contentService.GetById(existingpublishedcontent.Id);
    

    which returns null.

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Sep 06, 2017 @ 15:37
    Alex Skrypnyk
    100

    Manila, if _contentService.GetById(existingpublishedcontent.Id); returns null - it means that in database no this content anymore.

    If you still see it on the front end as "IPublishedContent" then you have this content only in xml, republish all should fix it.

    Or try to remove umbraco.config

    Thanks

    Alex

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Sep 08, 2017 @ 12:29
    Alex Skrypnyk
    0

    Hi Manila

    Did you solve the issue? Share with our community please.

    THanks,

    Alex

  • nickornotto 397 posts 900 karma points
    Sep 12, 2017 @ 08:57
    nickornotto
    0

    Thanks.

    That's what I needed to know!

Please Sign in or register to post replies

Write your reply to:

Draft