I am trying to delete specific nodes from the recycle bin using contentService.Delete(IContent node).
The returning OperationResult has Success = true, but the node still exists in the recycle bin.
Here is my code:
var updatedBefore = DateTime.Now.AddDays(-30);
var nodes = _contentService.GetPagedContentInRecycleBin(0, int.MaxValue, out long totalRecords, new Query<IContent>(scope.SqlContext).Where(x => x.UpdateDate < updatedBefore));
foreach (var node in nodes)
{
_contentService.Delete(node);
}
I know I can use .EmptyRecycleBin()to empty the recycle bin, but I only want nodes older than X days to be deleted.
We've used to do the same in V7, although mostly for the media archive:
var mediaService = Services.MediaService;
var files = mediaService.GetMediaInRecycleBin();
foreach (IMedia file in files)
{
if ((DateTime.Now - file.UpdateDate).Days > 60)
{
mediaService.Delete(file);
}
}
So it would say it's a bug if similar doesn't work in V8.
How are you confirming whether the items has in fact been deleted? Running the code again or checking manually in the backoffice whether the items have been deleted? I think there has been some issues in the past with lookups in the content service being cached, so that could explain why.
I've got the same problem, using autoComplete: true but because it was not working i've also added scope.Complete(). But they are still not deleted.
Do i miss something in my code?
using (var scope = this.scopeProvider.CreateScope(autoComplete: true))
{
var mediaRecords = this.mediaService.GetPagedMediaInRecycleBin(0, int.MaxValue, out long totalMediaRecords, new Query<IMedia>(scope.SqlContext).Where(x => x.UpdateDate < updatedBefore));
foreach (var mediaRecord in mediaRecords)
{
try
{
this.mediaService.Delete(mediaRecord);
this.LogToFile(string.Format("Media {0} ({1}) deleted.", mediaRecord.Name, mediaRecord.Id));
}
catch (Exception ex)
{
this.LogToFile(string.Format("Error deleting Media {0} ({1}): {2}.", mediaRecord.Name, mediaRecord.Id, ex.Message));
}
}
scope.Complete();
}
ContentService.Delete() not deleting the node
I am trying to delete specific nodes from the recycle bin using
contentService.Delete(IContent node)
.The returning
OperationResult
hasSuccess = true
, but the node still exists in the recycle bin.Here is my code:
I know I can use
.EmptyRecycleBin()
to empty the recycle bin, but I only want nodes older than X days to be deleted.Is this a bug, or am I doing something wrong?
We've used to do the same in V7, although mostly for the media archive:
So it would say it's a bug if similar doesn't work in V8.
How are you confirming whether the items has in fact been deleted? Running the code again or checking manually in the backoffice whether the items have been deleted? I think there has been some issues in the past with lookups in the content service being cached, so that could explain why.
Both running the code again and checking manually in the backoffice.
Forgot to complete the scope 🤦♂️ #h5is :)
I've got the same problem, using autoComplete: true but because it was not working i've also added scope.Complete(). But they are still not deleted. Do i miss something in my code?
is working on a reply...