November Happy Hour will be moved to Thursday December 5th.

Expired page event

Vote:
 

Hi,

I need to store data about expired pages in the DDS. So I don't have to do a search to get them.

How to determine that the page has expired and at the time of expiration to save data in the DDS?

Maybe an event occurs?

#142853
Jan 04, 2016 12:29
Vote:
 

Do you want to store more information than is displayed in the Report for expired pages?

#142854
Jan 04, 2016 12:45
Vote:
 

I want to store at least the page ID so I can determine what pages expired at any time.

#142864
Jan 04, 2016 14:11
Vote:
 

Maybe I don't understand exactly what you want, but if you only want a list of pages that are expired, you can view that report in the "Report viewer" which lists the follwowing for each expired page: Page Name (with a link to the page), Publication Date, Publication Stopped, Last Changed, Changed By, Language, Page Type.

#142873
Jan 04, 2016 14:55
Vote:
 

Yes, but can I programmatically obtain a list of these pages?

#142875
Edited, Jan 04, 2016 15:08
Vote:
 

You can use the API to go through all pages and compare StopPublish date to todays date OR you can run sql cmd netReportExpiredPages (which is the code used by Report center):

public PageReferenceCollection GetPagesExpired(PageReference rootPage, DateTime startDate, DateTime endDate, string publishedByName, ReportDB.SortColumn sortColumn, SortDirection sortDirection, int pageSize, int pageNumber, int langID, out int totalRows)
{
	PageReferenceCollection pageReferences = new PageReferenceCollection();
	int resultTotalRows = 0;
	base.Database.Execute(delegate
	{
		IDbCommand dbCommand = this.CreateCommand("netReportExpiredPages");
		dbCommand.Parameters.Add(this.CreateParameter("PageID", rootPage.ID));
		dbCommand.Parameters.Add(this.CreateDateParameter("StartDate", startDate));
		dbCommand.Parameters.Add(this.CreateDateParameter("StopDate", endDate));
		dbCommand.Parameters.Add(this.CreateParameter("Language", langID));
		dbCommand.Parameters.Add(this.CreateParameter("PublishedByName", publishedByName));
		dbCommand.Parameters.Add(this.CreateParameter("PageSize", pageSize));
		dbCommand.Parameters.Add(this.CreateParameter("PageNumber", pageNumber));
		dbCommand.Parameters.Add(this.CreateParameter("SortColumn", sortColumn.ToString()));
		dbCommand.Parameters.Add(this.CreateParameter("SortDescending", (sortDirection == SortDirection.Descending) ? 1 : 0));
		using (IDataReader dataReader = dbCommand.ExecuteReader())
		{
			while (dataReader.Read())
			{
				if (resultTotalRows == 0)
				{
					resultTotalRows = Convert.ToInt32(dataReader.GetValue(3));
				}
				if (dataReader.IsDBNull(1))
				{
					pageReferences.Add(new PageReference(dataReader.GetInt32(0)));
				}
				else
				{
					pageReferences.Add(new PageReference(dataReader.GetInt32(0), dataReader.GetInt32(1)));
				}
			}
		}
	});
	totalRows = resultTotalRows;
	return pageReferences;
}

 

#142876
Jan 04, 2016 15:17
Vote:
 

Thank you for the piece of code, but is there an event that is raised when the page has expired?
Something like event EventHandler<ContentEventArgs> PublishedContent that occurs when you published the page.

#142879
Jan 04, 2016 16:11
Vote:
 

There is as far as I know no specific event. Although it is in fact a PublishedContent event. But I don't think the event is triggered by automatic expiring of pages, but I could be wrong.

If it is, you could check for Published Status of your PageData I guess and do whatever you need to do with it.

#142880
Jan 04, 2016 16:41
Vote:
 

There is not a specific event for when a page expires.

#142893
Jan 05, 2016 8:34
Vote:
 

Thank you very much for the answers.

#142894
Edited, Jan 05, 2016 8:46
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.