Hi,
I have nodes which has expire date. When this date comes I want to send an email notification to some people. I was thinking of handling the Umbraco.Core.Services.ContentService.UnPublished method, but this method is not called when the unpublish is done automatically.
Can you give me idea how I can achieve my requirements?
According to the documentation that should give you all content that has an expire date greater than today's date. You do have some content scheduled to unpublish, don't you?
Hi, Dan,
I checked the code of Umbraco 7.7.9 and 7.12.3 and it seems that there is discrepancies: Here is what the IContentService definition is:
/// <summary>
/// Gets a collection of <see cref="IContent"/> objects, which has an expiration date greater then today
/// </summary>
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
IEnumerable<IContent> GetContentForExpiration();
and the ContentService implementation is:
/// <summary>
/// Gets a collection of <see cref="IContent"/> objects, which has an expiration date less than or equal to today.
/// </summary>
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
public IEnumerable<IContent> GetContentForExpiration()
{
using (var uow = UowProvider.GetUnitOfWork(readOnly: true))
{
var repository = RepositoryFactory.CreateContentRepository(uow);
var query = Query<IContent>.Builder.Where(x => x.Published && x.ExpireDate <= DateTime.Now);
return repository.GetByQuery(query);
}
}
it seems that the method GetContentForExpiration returns nodes which expiration date is less than or equal today.
Hi. That's interesting. Could be a bug or maybe they fixed a bug?
There is also the related method called GetContentForRelease() which is supposed to get content with a release date greater than today. Out of interest, does that work?
Hi, Dan,
I didn't try GetContentForRelease() method because my content is Published. I don't have a case where the content should be released at some date. However I made my own request to get the content that expires today:
Handle Automatically Unpublish Event
Hi, I have nodes which has expire date. When this date comes I want to send an email notification to some people. I was thinking of handling the Umbraco.Core.Services.ContentService.UnPublished method, but this method is not called when the unpublish is done automatically.
Can you give me idea how I can achieve my requirements?
Regards Mila
You can get a list of content pages that are going to expire (unpublish) using the Content Service ie.
So you could maybe use that?
Hi, Dan, I created Umbraco scheduled task and call
but specialsToExpire is always null.
According to the documentation that should give you all content that has an expire date greater than today's date. You do have some content scheduled to unpublish, don't you?
Hi, Dan, I checked the code of Umbraco 7.7.9 and 7.12.3 and it seems that there is discrepancies: Here is what the IContentService definition is:
and the ContentService implementation is:
it seems that the method GetContentForExpiration returns nodes which expiration date is less than or equal today.
Regards Mila
Hi. That's interesting. Could be a bug or maybe they fixed a bug?
There is also the related method called
GetContentForRelease()
which is supposed to get content with a release date greater than today. Out of interest, does that work?Hi, Dan, I didn't try GetContentForRelease() method because my content is Published. I don't have a case where the content should be released at some date. However I made my own request to get the content that expires today:
I hope this approach is not taking too many server and db resources.
Regarding the method GetContentForExpiration() I think there is a bug, because of this query:
If a node has expiration date <= now, then the item would not have status Published. This query will always return empty list:
Thanks Mila
is working on a reply...