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?
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.
Here's a screenshot of the author with an id of 4627 showing up in the XPath query later on.
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?
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?
Thanks for your help!
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
Hi Dave,
Thanks for the response.
Here's the method that unpublishes and deletes an author.
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.
Here's a screenshot of an author with an id of 4627 being unpublished and deleted.
Here's a screenshot of the author with an id of 4627 showing up in the XPath query later on.
Thanks again for any feedback!
Hi Jon,
And what if you try this
private void permanentlyRemoveDeletedCoAuthors(List
Hi Dave,
This updated code had no affect. The deleted author was still returned by the XPath query.
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
Dave,
This updated code also had no effect. The deleted author still shows up in the XPath query.
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.
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
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!
Don't forget to mark the topic as solution. So other can find the solution as well.
Dave
is working on a reply...