U4-6811 - fix preview set deletion

This commit is contained in:
Stephan
2017-03-22 12:16:33 +01:00
parent 532b177d2e
commit 94b7c36d62

View File

@@ -99,7 +99,7 @@ namespace umbraco.presentation.preview
//Inject preview xml
parentId = document.Level == 1 ? -1 : document.ParentId;
var previewXml = document.ToPreviewXml(XmlContent);
if (document.ContentEntity.Published == false
if (document.ContentEntity.Published == false
&& ApplicationContext.Current.Services.ContentService.HasPublishedVersion(document.Id))
previewXml.Attributes.Append(XmlContent.CreateAttribute("isDraft"));
XmlContent = content.GetAddOrUpdateXmlNode(XmlContent, document.Id, document.Level, parentId, previewXml);
@@ -187,13 +187,9 @@ namespace umbraco.presentation.preview
private static void CleanPreviewDirectory(int userId, DirectoryInfo dir)
{
foreach (FileInfo file in dir.GetFiles(userId + "_*.config"))
{
DeletePreviewFile(userId, file);
}
// also delete any files accessed more than 10 minutes ago
var now = DateTime.Now;
foreach (FileInfo file in dir.GetFiles("*.config"))
foreach (var file in dir.GetFiles("*.config"))
{
if ((now - file.LastAccessTime).TotalMinutes > 10)
DeletePreviewFile(userId, file);
@@ -208,7 +204,11 @@ namespace umbraco.presentation.preview
}
catch (Exception ex)
{
LogHelper.Error<PreviewContent>(string.Format("Couldn't delete preview set: {0} - User {1}", file.Name, userId), ex);
// for *some* reason deleting the file can fail,
// and it will work later on (long-lasting locks, etc),
// so just ignore the exception
//LogHelper.Error<PreviewContent>(string.Format("Couldn't delete preview set: {0} - User {1}", file.Name, userId), ex);
}
}