Copied to clipboard

Flag this post as spam?

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


  • Jon Davis 16 posts 109 karma points
    Apr 04, 2018 @ 17:43
    Jon Davis
    0

    Deleted content still showing up in XPath search

    Hi,

    I'm on 7.6.4. Here's the scenario:

    1) A piece of content is unpublished and then deleted with the content service

    2) Later on, the content that was deleted turns up in the results of an XPath query.

    3) If I "Republish Entire Site" the content no longer turns up in the results of the XPath query.

    I attached a screenshot of a test where an XPath query returns a piece of content that was just unpublished and deleted. I thought that the call to UnPublish would remove the content from the cache. What am I missing here?

    enter image description here

    Thanks for your help!

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 06, 2018 @ 06:21
    Dave Woestenborghs
    0

    Hi Jon,

    Can you post your code. It seems to me that you are trying to do a xpath query before the cache is updated with the delete action.

    Dave

  • Jon Davis 16 posts 109 karma points
    Apr 06, 2018 @ 14:18
    Jon Davis
    0

    Hi Dave,

    Thanks for the response.

    Here's the method that unpublishes and deletes an author.

            private void permanentlyRemoveDeletedCoAuthors(List<int> oldAuthorsToDeleteById)
        {
            foreach (var authorToDeleteId in oldAuthorsToDeleteById)
            {
                var authorToDelete = contentService.GetById(authorToDeleteId);
                if (authorToDelete != null)
                {
                    contentService.UnPublish(authorToDelete);
                    contentService.Delete(authorToDelete);
                }
            }
        }
    

    At the very bottom of this next method is the XPath query that returns the author that was previously deleted. This method is not run immediately after the delete statement. It could be run minutes, hours or days after the delete. Until "Republish Entire Site" is called, the deleted author is returned by the query.

            public List<int> GetOtherArticleIdsByTheseAuthors(List<int> selectedAuthorIds)
        {
            //Build a query string that filters the authors based on the selectedAuthorIds parameter
            var matchAuthorsById_Query = "";
            selectedAuthorIds.ForEach(a => matchAuthorsById_Query += $"@id = '{a}' or ");
    
            //Use the query string to fetch the authors and return the authorPoolId for each match
            char[] charsToTrim = { ' ', 'o', 'r' };
            var authorPoolIds = _umbracoHelper
                                .TypedContentAtXPath($"//selectedAuthorsFolder/Author[{matchAuthorsById_Query.TrimEnd(charsToTrim)}]")
                                .Select(a => a.GetPropertyValue<int>("authorPoolId"))
                                .Distinct()
                                .ToList();
    
            //Now build a query string that filters authors by authorPoolId
            var matchAuthorsByAuthorPoolId_Query = "";
            authorPoolIds.ForEach(a => { matchAuthorsByAuthorPoolId_Query += $"authorPoolId = '{a}' or ";});
    
    
            return _umbracoHelper
                .TypedContentAtXPath($"//selectedAuthorsFolder/Author[{matchAuthorsByAuthorPoolId_Query.TrimEnd(charsToTrim)}]")
                .Select(u => u.GetPropertyValue<int>("articleId"))
                .Distinct()
                .ToList();
        }
    

    Here's a screenshot of an author with an id of 4627 being unpublished and deleted. enter image description here

    Here's a screenshot of the author with an id of 4627 showing up in the XPath query later on. enter image description here

    Thanks again for any feedback!

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 06, 2018 @ 14:23
    Dave Woestenborghs
    0

    Hi Jon,

    And what if you try this

    private void permanentlyRemoveDeletedCoAuthors(List

  • Jon Davis 16 posts 109 karma points
    Apr 06, 2018 @ 14:39
    Jon Davis
    0

    Hi Dave,

    This updated code had no affect. The deleted author was still returned by the XPath query.

            private void permanentlyRemoveDeletedCoAuthors(List<int> oldAuthorsToDeleteById)
        {
            foreach (var authorToDeleteId in oldAuthorsToDeleteById)
            {
                var authorToDelete = contentService.GetById(authorToDeleteId);
                if (authorToDelete != null)
                {
                    contentService.MoveToRecycleBin(authorToDelete);
                    contentService.Delete(authorToDelete);
                }
            }
        }
    
  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 06, 2018 @ 14:45
    Dave Woestenborghs
    0

    Hi Jon,

    Maybe you can call this after your delete method

    https://our.umbraco.org/documentation/Reference/Management/Services/ContentService#republishallint-userid--0

    This is the same as republish all which you were doing manually.

    Dave

  • Jon Davis 16 posts 109 karma points
    Apr 06, 2018 @ 15:27
    Jon Davis
    0

    Dave,

    This updated code also had no effect. The deleted author still shows up in the XPath query.

            private void permanentlyRemoveDeletedCoAuthors(List<int> oldAuthorsToDeleteById)
        {
            foreach (var authorToDeleteId in oldAuthorsToDeleteById)
            {
                var authorToDelete = contentService.GetById(authorToDeleteId);
                if (authorToDelete != null)
                {
                    contentService.MoveToRecycleBin(authorToDelete);
                    contentService.Delete(authorToDelete);
                    contentService.RePublishAll();
                }
            }
        }
    

    I'm calling permanentlyRemoveDeletedCoAuthors() from within ContentService_Saving(). Could my call to Delete() and RePublishAll() be conflicting with similar calls being made behind the scenes by Umbraco code?

    Thank you again for the help here.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 06, 2018 @ 15:52
    Dave Woestenborghs
    100

    Hi Jon,

    That could well be the cause. Is there a reason why it needs to be in the Saving event ?

    Can you try to do it in the Saved Event ?

    Dave

  • Jon Davis 16 posts 109 karma points
    Apr 06, 2018 @ 21:00
    Jon Davis
    0

    Hi Dave,

    I moved the calls to ContentService.Delete() to the very end of the ContentService_Saved() method. This appears to have resolved the issue.

    Thanks a bunch for your help!

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 06, 2018 @ 21:08
    Dave Woestenborghs
    0

    Don't forget to mark the topic as solution. So other can find the solution as well.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft