Refactoring the Document class for publishing and unpublishing.

Bumped into an issue with nullable datetime and petapoco, which now has a workaround in our IMapper.
Fix a few issues around the Published state on previous versions.
This commit is contained in:
Morten Christensen
2012-12-13 13:05:23 -01:00
parent fa80356a49
commit 207c651743
13 changed files with 223 additions and 143 deletions
+2 -2
View File
@@ -87,10 +87,10 @@ namespace Umbraco.Core.Models
if(Trashed)
return ContentStatus.Trashed;
if(ExpireDate.HasValue && DateTime.UtcNow > ExpireDate.Value)
if(ExpireDate.HasValue && ExpireDate.Value > DateTime.MinValue && DateTime.UtcNow > ExpireDate.Value)
return ContentStatus.Expired;
if(ReleaseDate.HasValue && ReleaseDate.Value > DateTime.UtcNow)
if(ReleaseDate.HasValue && ReleaseDate.Value > DateTime.MinValue && ReleaseDate.Value > DateTime.UtcNow)
return ContentStatus.AwaitingRelease;
if(Published)
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Xml.Linq;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Repositories;
@@ -78,5 +79,70 @@ namespace Umbraco.Core.Models
new PetaPocoUnitOfWork());
return repository.GetProfileById(content.WriterId);
}
/// <summary>
/// Creates the xml representation for the <see cref="IContent"/> object
/// </summary>
/// <param name="content"><see cref="IContent"/> to generate xml for</param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
public static XElement ToXml(this IContent content)
{
//nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias);
//var nodeName = content.ContentType.Alias.ToUmbracoAlias(StringAliasCaseType.CamelCase, true);
var nodeName = content.ContentType.Alias;
var niceUrl = content.Name.Replace(" ", "-").ToLower();
/* NOTE Not entirely sure if this is needed, but either way the niceUrlProvider is not
* available from here, so it would have to be delegated
*/
/*if (UmbracoContext.Current != null)
{
var niceUrlsProvider = UmbracoContext.Current.NiceUrlProvider;
niceUrl = niceUrlsProvider.GetNiceUrl(content.Id);
}*/
var xml = new XElement(nodeName,
new XAttribute("id", content.Id),
new XAttribute("parentID", content.Level > 1 ? content.ParentId : -1),
new XAttribute("level", content.Level),
new XAttribute("writerID", content.WriterId),
new XAttribute("creatorID", content.CreatorId),
new XAttribute("nodeType", content.ContentType.Id),
new XAttribute("template", content.Template == null ? "0": content.Template.Id.ToString()),
new XAttribute("sortOrder", content.SortOrder),
new XAttribute("createDate", content.CreateDate.ToString("s")),
new XAttribute("updateDate", content.UpdateDate.ToString("s")),
new XAttribute("nodeName", content.Name),
new XAttribute("urlName", niceUrl),//Format Url ?
new XAttribute("writerName", content.GetWriterProfile().Name),
new XAttribute("creatorName", content.GetCreatorProfile().Name),
new XAttribute("path", content.Path));
foreach (var property in content.Properties)
{
if (property == null) continue;
xml.Add(property.ToXml());
//Check for umbracoUrlName convention
if (property.Alias == "umbracoUrlName" && property.Value.ToString().Trim() != string.Empty)
xml.SetAttributeValue("urlName", property.Value);
}
return xml;
}
/// <summary>
/// Creates the xml representation for the <see cref="IContent"/> object
/// </summary>
/// <param name="content"><see cref="IContent"/> to generate xml for</param>
/// <param name="isPreview">Boolean indicating whether the xml should be generated for preview</param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
public static XElement ToXml(this IContent content, bool isPreview)
{
//TODO Do a proper implementation of this
//If current IContent is published we should get latest unpublished version
return content.ToXml();
}
}
}
@@ -18,14 +18,8 @@ namespace Umbraco.Core.Models
var xd = new XmlDocument();
XmlNode xmlNode = xd.CreateNode(XmlNodeType.Element, nodeName, "");
XmlNode child = property.PropertyType.DataTypeDatabaseType == DataTypeDatabaseType.Ntext
? xd.CreateCDataSection(property.Value.ToString()) as XmlNode
: xd.CreateTextNode(property.Value.ToString());
xmlNode.AppendChild(child);
//TODO Revisit this by correcting test setup or refactoring DefaultData class to use PetaPoco instead of SqlHelper.
//This seems to fail during testing
//xmlNode.AppendChild(property.PropertyType.DataType(property.Id).Data.ToXMl(xd));
//NOTE Possibly revisit this by correcting test setup or refactoring DefaultData class to use PetaPoco instead of SqlHelper.
xmlNode.AppendChild(property.PropertyType.DataType(property.Id).Data.ToXMl(xd));
var element = xmlNode.GetXElement();
return element;
@@ -49,8 +49,8 @@ namespace Umbraco.Core.Persistence.Factories
Published = dto.Published,
CreateDate = dto.ContentVersionDto.ContentDto.NodeDto.CreateDate,
UpdateDate = dto.ContentVersionDto.VersionDate,
ExpireDate = dto.ExpiresDate,
ReleaseDate = dto.ReleaseDate,
ExpireDate = dto.ExpiresDate.HasValue ? dto.ExpiresDate.Value : (DateTime?) null,
ReleaseDate = dto.ReleaseDate.HasValue ? dto.ReleaseDate.Value : (DateTime?) null,
Version = dto.ContentVersionDto.VersionId
};
}
@@ -60,17 +60,24 @@ namespace Umbraco.Core.Persistence.Factories
//NOTE Currently doesn't add Alias and templateId (legacy stuff that eventually will go away)
var documentDto = new DocumentDto
{
ExpiresDate = entity.ExpireDate,
Newest = true,
NodeId = entity.Id,
Published = entity.Published,
ReleaseDate = entity.ReleaseDate,
Text = entity.Name,
UpdateDate = entity.UpdateDate,
WriterUserId = entity.WriterId,
VersionId = entity.Version,
ExpiresDate = null,
ReleaseDate = null,
ContentVersionDto = BuildContentVersionDto(entity)
};
if (entity.ExpireDate.HasValue)
documentDto.ExpiresDate = entity.ExpireDate.Value;
if (entity.ReleaseDate.HasValue)
documentDto.ReleaseDate = entity.ReleaseDate.Value;
return documentDto;
}
@@ -155,6 +155,19 @@ namespace Umbraco.Core.Persistence.Mappers
public Func<object, object> GetToDbConverter(Type sourceType)
{
//We need this check to ensure that PetaPoco doesn't try to insert an invalid date from a nullable DateTime property
if (sourceType == typeof (DateTime))
{
return datetimeVal =>
{
var datetime = datetimeVal as DateTime?;
if(datetime.HasValue && datetime.Value > DateTime.MinValue)
return datetime.Value;
return null;
};
}
return null;
}
}
@@ -263,6 +263,18 @@ namespace Umbraco.Core.Persistence.Repositories
Database.Update(docDto);
}
//If Published state has changed previous versions should have their publish state reset
if (((ICanBeDirty) entity).IsPropertyDirty("Published") && entity.Published)
{
var publishedDocs = Database.Fetch<DocumentDto>("WHERE nodeId = @Id AND published = @IsPublished", new { Id = entity.Id, IsPublished = true });
foreach (var doc in publishedDocs)
{
var docDto = doc;
docDto.Published = false;
Database.Update(docDto);
}
}
//Create a new version - cmsContentVersion
//Assumes a new Version guid and Version date (modified date) has been set
var contentVersionDto = dto.ContentVersionDto;
+59 -14
View File
@@ -2,11 +2,13 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using Umbraco.Core.Auditing;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.Repositories;
@@ -325,10 +327,10 @@ namespace Umbraco.Core.Services
/// Re-Publishes all Content
/// </summary>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <param name="omitCacheRefresh">Optional boolean to avoid having the cache refreshed when calling this RePublish method. By default this method will update the cache.</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
public bool RePublishAll(int userId = -1)
public bool RePublishAll(int userId = -1, bool omitCacheRefresh = false)
{
//TODO delete from cmsContentXml or truncate table cmsContentXml before generating and saving xml to db
var repository = _contentRepository;
var list = new List<IContent>();
@@ -361,8 +363,19 @@ namespace Umbraco.Core.Services
_unitOfWork.Commit();
foreach (var c in updated)
{
var xml = c.ToXml();
var poco = new ContentXmlDto { NodeId = c.Id, Xml = xml.ToString(SaveOptions.None) };
var exists = DatabaseContext.Current.Database.IsNew(poco);
int result = exists
? DatabaseContext.Current.Database.Update(poco)
: Convert.ToInt32(DatabaseContext.Current.Database.Insert(poco));
}
//Updating content to published state is finished, so we fire event through PublishingStrategy to have cache updated
_publishingStrategy.PublishingFinalized(updated, true);
if(omitCacheRefresh == false)
_publishingStrategy.PublishingFinalized(updated, true);
Audit.Add(AuditTypes.Publish, "RePublish All performed by user", userId == -1 ? 0 : userId, -1);
}
@@ -375,10 +388,11 @@ namespace Umbraco.Core.Services
/// </summary>
/// <param name="content">The <see cref="IContent"/> to publish</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <param name="omitCacheRefresh">Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
public bool Publish(IContent content, int userId = -1)
public bool Publish(IContent content, int userId = -1, bool omitCacheRefresh = false)
{
return SaveAndPublish(content, userId);
return SaveAndPublish(content, userId, omitCacheRefresh);
}
/// <summary>
@@ -386,10 +400,10 @@ namespace Umbraco.Core.Services
/// </summary>
/// <param name="content">The <see cref="IContent"/> to publish along with its children</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <param name="omitCacheRefresh">Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
public bool PublishWithChildren(IContent content, int userId = -1)
public bool PublishWithChildren(IContent content, int userId = -1, bool omitCacheRefresh = false)
{
//TODO Should Publish generate xml of content and save it in the db?
var repository = _contentRepository;
//Check if parent is published (although not if its a root node) - if parent isn't published this Content cannot be published
@@ -432,8 +446,19 @@ namespace Umbraco.Core.Services
_unitOfWork.Commit();
foreach (var c in updated)
{
var xml = c.ToXml();
var poco = new ContentXmlDto { NodeId = c.Id, Xml = xml.ToString(SaveOptions.None) };
var exists = DatabaseContext.Current.Database.FirstOrDefault<ContentXmlDto>("WHERE nodeId = @Id", new { Id = c.Id }) != null;
int result = exists
? DatabaseContext.Current.Database.Update(poco)
: Convert.ToInt32(DatabaseContext.Current.Database.Insert(poco));
}
//Save xml to db and call following method to fire event:
_publishingStrategy.PublishingFinalized(updated, false);
if(omitCacheRefresh == false)
_publishingStrategy.PublishingFinalized(updated, false);
Audit.Add(AuditTypes.Publish, "Publish with Children performed by user", userId == -1 ? 0 : userId, content.Id);
}
@@ -446,8 +471,9 @@ namespace Umbraco.Core.Services
/// </summary>
/// <param name="content">The <see cref="IContent"/> to publish</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <param name="omitCacheRefresh">Optional boolean to avoid having the cache refreshed when calling this Unpublish method. By default this method will update the cache.</param>
/// <returns>True if unpublishing succeeded, otherwise False</returns>
public bool UnPublish(IContent content, int userId = -1)
public bool UnPublish(IContent content, int userId = -1, bool omitCacheRefresh = false)
{
var repository = _contentRepository;
@@ -477,8 +503,19 @@ namespace Umbraco.Core.Services
_unitOfWork.Commit();
//Remove 'published' xml from the cmsContentXml table for the unpublished content and its (possible) children
DatabaseContext.Current.Database.Delete<ContentXmlDto>("WHERE nodeId = @Id", new {Id = content.Id});
if (hasChildren)
{
foreach (var child in children)
{
DatabaseContext.Current.Database.Delete<ContentXmlDto>("WHERE nodeId = @Id", new { Id = child.Id });
}
}
//Delete xml from db? and call following method to fire event through PublishingStrategy to update cache
_publishingStrategy.UnPublishingFinalized(content);
if(omitCacheRefresh == false)
_publishingStrategy.UnPublishingFinalized(content);
Audit.Add(AuditTypes.Publish, "UnPublish performed by user", userId == -1 ? 0 : userId, content.Id);
}
@@ -517,10 +554,10 @@ namespace Umbraco.Core.Services
/// </summary>
/// <param name="content">The <see cref="IContent"/> to save and publish</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <param name="omitCacheRefresh">Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
public bool SaveAndPublish(IContent content, int userId = -1)
public bool SaveAndPublish(IContent content, int userId = -1, bool omitCacheRefresh = false)
{
//TODO Should Publish generate xml of content and save it in the db?
var e = new SaveEventArgs();
if (Saving != null)
Saving(content, e);
@@ -530,7 +567,7 @@ namespace Umbraco.Core.Services
var repository = _contentRepository;
//Check if parent is published (although not if its a root node) - if parent isn't published this Content cannot be published
if (content.ParentId != -1 && content.ParentId != -20 && GetById(content.ParentId).Published == false)
if (content.ParentId != -1 && content.ParentId != -20 && HasPublishedVersion(content.ParentId) == false)
{
LogHelper.Info<ContentService>(
string.Format(
@@ -557,8 +594,16 @@ namespace Umbraco.Core.Services
repository.AddOrUpdate(content);
_unitOfWork.Commit();
var xml = content.ToXml();
var poco = new ContentXmlDto{NodeId = content.Id, Xml = xml.ToString(SaveOptions.None)};
var exists = DatabaseContext.Current.Database.FirstOrDefault<ContentXmlDto>("WHERE nodeId = @Id", new {Id = content.Id}) != null;
int result = exists
? DatabaseContext.Current.Database.Update(poco)
: Convert.ToInt32(DatabaseContext.Current.Database.Insert(poco));
//Save xml to db and call following method to fire event through PublishingStrategy to update cache
_publishingStrategy.PublishingFinalized(content);
if(omitCacheRefresh == false)
_publishingStrategy.PublishingFinalized(content);
}
if (Saved != null)
+10 -10
View File
@@ -19,11 +19,6 @@ namespace Umbraco.Core.Services
/// <returns><see cref="IContent"/></returns>
IContent CreateContent(int parentId, string contentTypeAlias, int userId = -1);
//TODO Add GetLatestUnpublishedVersions(int id){}
//TODO Add CreateNewVersion method? Its currently used in the Document API when Publishing - latest version is published,
//but then a new version is created so latest version is not published.
//IContent CreateNewVersion(int id); -> should not be necessary as Version number is changed when updating
/// <summary>
/// Gets an <see cref="IContent"/> object by Id
/// </summary>
@@ -94,40 +89,45 @@ namespace Umbraco.Core.Services
/// Re-Publishes all Content
/// </summary>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <param name="omitCacheRefresh">Optional boolean to avoid having the cache refreshed when calling this RePublish method. By default this method will update the cache.</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
bool RePublishAll(int userId = -1);
bool RePublishAll(int userId = -1, bool omitCacheRefresh = false);
/// <summary>
/// Publishes a single <see cref="IContent"/> object
/// </summary>
/// <param name="content">The <see cref="IContent"/> to publish</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <param name="omitCacheRefresh">Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
bool Publish(IContent content, int userId = -1);
bool Publish(IContent content, int userId = -1, bool omitCacheRefresh = false);
/// <summary>
/// Publishes a <see cref="IContent"/> object and all its children
/// </summary>
/// <param name="content">The <see cref="IContent"/> to publish along with its children</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <param name="omitCacheRefresh">Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
bool PublishWithChildren(IContent content, int userId = -1);
bool PublishWithChildren(IContent content, int userId = -1, bool omitCacheRefresh = false);
/// <summary>
/// UnPublishes a single <see cref="IContent"/> object
/// </summary>
/// <param name="content">The <see cref="IContent"/> to publish</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <param name="omitCacheRefresh">Optional boolean to avoid having the cache refreshed when calling this Unpublish method. By default this method will update the cache.</param>
/// <returns>True if unpublishing succeeded, otherwise False</returns>
bool UnPublish(IContent content, int userId = -1);
bool UnPublish(IContent content, int userId = -1, bool omitCacheRefresh = false);
/// <summary>
/// Saves and Publishes a single <see cref="IContent"/> object
/// </summary>
/// <param name="content">The <see cref="IContent"/> to save and publish</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <param name="omitCacheRefresh">Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
bool SaveAndPublish(IContent content, int userId = -1);
bool SaveAndPublish(IContent content, int userId = -1, bool omitCacheRefresh = false);
/// <summary>
/// Saves a single <see cref="IContent"/> object
+2 -6
View File
@@ -29,9 +29,6 @@ namespace Umbraco.Tests.Models
typeof(tinyMCE3dataType).Assembly
};
DataTypesResolver.Current = new DataTypesResolver(
PluginManager.Current.ResolveDataTypes());
base.Initialize();
}
@@ -39,9 +36,6 @@ namespace Umbraco.Tests.Models
public override void TearDown()
{
DatabaseContext.Database.Dispose();
//reset the app context
DataTypesResolver.Reset();
base.TearDown();
}
@@ -63,6 +57,8 @@ namespace Umbraco.Tests.Models
// Assert
Assert.That(element, Is.Not.Null);
Assert.That(element.Name.LocalName, Is.EqualTo(nodeName));
Console.WriteLine(element.ToString(SaveOptions.DisableFormatting));
}
}
}
-70
View File
@@ -1,70 +0,0 @@
using System.Xml.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
namespace Umbraco.Web
{
public static class ContentExtensions
{
/// <summary>
/// Creates the xml representation for the <see cref="IContent"/> object
/// </summary>
/// <param name="content"><see cref="IContent"/> to generate xml for</param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
public static XElement ToXml(this IContent content)
{
//nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias);
var nodeName = content.ContentType.Alias.ToUmbracoAlias(StringAliasCaseType.CamelCase, true);
var niceUrl = content.Name.Replace(" ", "-").ToLower();
if (UmbracoContext.Current != null)
{
var niceUrlsProvider = UmbracoContext.Current.NiceUrlProvider;
niceUrl = niceUrlsProvider.GetNiceUrl(content.Id);
}
var xml = new XElement(nodeName,
new XAttribute("id", content.Id),
new XAttribute("parentID", content.Level > 1 ? content.ParentId : -1),
new XAttribute("level", content.Level),
new XAttribute("writerID", content.WriterId),
new XAttribute("creatorID", content.CreatorId),
new XAttribute("nodeType", content.ContentType.Id),
new XAttribute("template", content.Template == null ? string.Empty : content.Template.Id.ToString()),
new XAttribute("sortOrder", content.SortOrder),
new XAttribute("createDate", content.CreateDate),
new XAttribute("updateDate", content.UpdateDate),
new XAttribute("nodeName", content.Name),
new XAttribute("urlName", niceUrl),//Format Url ?
new XAttribute("writerName", content.GetWriterProfile().Name),
new XAttribute("creatorName", content.GetCreatorProfile().Name),
new XAttribute("path", content.Path));
foreach (var property in content.Properties)
{
if (property == null) continue;
xml.Add(property.ToXml());
//Check for umbracoUrlName convention
if (property.Alias == "umbracoUrlName" && property.Value.ToString().Trim() != string.Empty)
xml.SetAttributeValue("urlName", property.Value);
}
return xml;
}
/// <summary>
/// Creates the xml representation for the <see cref="IContent"/> object
/// </summary>
/// <param name="content"><see cref="IContent"/> to generate xml for</param>
/// <param name="isPreview">Boolean indicating whether the xml should be generated for preview</param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
public static XElement ToXml(this IContent content, bool isPreview)
{
//TODO Do a proper implementation of this
//If current IContent is published we should get latest unpublished version
return content.ToXml();
}
}
}
-1
View File
@@ -247,7 +247,6 @@
<Compile Include="ApplicationContextExtensions.cs" />
<Compile Include="ApplicationEventsResolver.cs" />
<Compile Include="CacheHelperExtensions.cs" />
<Compile Include="ContentExtensions.cs" />
<Compile Include="Dynamics\DynamicExpression.cs" />
<Compile Include="Dynamics\DynamicGrouping.cs" />
<Compile Include="Dynamics\DynamicPublishedContentIdEqualityComparer.cs" />
@@ -1,6 +1,8 @@
using System;
using System.Data;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using umbraco.DataLayer;
using umbraco.BusinessLogic;
using umbraco.interfaces;
@@ -24,6 +26,13 @@ namespace umbraco.cms.businesslogic.datatype
get { return Application.SqlHelper; }
}
//TODO Refactor this class to use the Database object instead of the SqlHelper
//NOTE DatabaseContext.Current.Database should eventually be replaced with that from the Repository-Resolver refactor branch.
internal static Database Database
{
get { return DatabaseContext.Current.Database; }
}
/// <summary>
/// Initializes a new instance of the <see cref="DefaultData"/> class.
/// </summary>
+37 -28
View File
@@ -75,24 +75,30 @@ namespace umbraco.cms.businesslogic.web
: base(id, optimizedMode)
{
this._optimizedMode = optimizedMode;
_content = ServiceContext.Current.ContentService.GetById(id);
bool hasChildren = ServiceContext.Current.ContentService.HasChildren(id);
SetupDocumentForTree(_content.Key, _content.Level, _content.ParentId, _content.CreatorId, _content.WriterId,
_content.Published, _content.Path, _content.Name, _content.CreateDate,
_content.UpdateDate, _content.UpdateDate, _content.ContentType.Icon, hasChildren,
_content.ContentType.Alias, _content.ContentType.Thumbnail,
_content.ContentType.Description, null, _content.ContentType.Id, _content.Template.Id,
_content.ContentType.IsContainer);
if (optimizedMode)
{
_content = ServiceContext.Current.ContentService.GetById(id);
bool hasChildren = ServiceContext.Current.ContentService.HasChildren(id);
int templateId = _content.Template == null ? 0 : _content.Template.Id;
var tmpReleaseDate = _content.ReleaseDate.HasValue ? _content.ReleaseDate.Value : new DateTime();
var tmpExpireDate = _content.ExpireDate.HasValue ? _content.ExpireDate.Value : new DateTime();
var creator = new User(_content.CreatorId, true);
var writer = new User(_content.WriterId, true);
SetupDocumentForTree(_content.Key, _content.Level, _content.ParentId, _content.CreatorId,
_content.WriterId,
_content.Published, _content.Path, _content.Name, _content.CreateDate,
_content.UpdateDate, _content.UpdateDate, _content.ContentType.Icon, hasChildren,
_content.ContentType.Alias, _content.ContentType.Thumbnail,
_content.ContentType.Description, null, _content.ContentType.Id,
templateId, _content.ContentType.IsContainer);
InitializeContent(_content.ContentType.Id, _content.Version, _content.UpdateDate, _content.ContentType.Icon);
InitializeDocument(creator, writer, _content.Name, _content.Template.Id, tmpReleaseDate, tmpExpireDate, _content.UpdateDate, _content.Published);
var tmpReleaseDate = _content.ReleaseDate.HasValue ? _content.ReleaseDate.Value : new DateTime();
var tmpExpireDate = _content.ExpireDate.HasValue ? _content.ExpireDate.Value : new DateTime();
var creator = new User(_content.CreatorId, true);
var writer = new User(_content.WriterId, true);
InitializeContent(_content.ContentType.Id, _content.Version, _content.UpdateDate,
_content.ContentType.Icon);
InitializeDocument(creator, writer, _content.Name, templateId, tmpReleaseDate, tmpExpireDate,
_content.UpdateDate, _content.Published);
}
/*if (optimizedMode)
{
@@ -868,7 +874,7 @@ where '" + Path + ",' like " + SqlHelper.Concat("node.path", "',%'"));
[Obsolete("Deprecated, Use Umbraco.Core.Services.ContentService.Publish()", false)]
public void Publish(User u)
{
ServiceContext.Current.ContentService.Publish(_content, u.Id);
ServiceContext.Current.ContentService.Publish(_content, u.Id, true);
//PublishWithResult(u);
}
@@ -884,12 +890,13 @@ where '" + Path + ",' like " + SqlHelper.Concat("node.path", "',%'"));
[Obsolete("Deprecated, Use Umbraco.Core.Services.ContentService.Publish()", false)]
public bool PublishWithResult(User u)
{
PublishEventArgs e = new PublishEventArgs();
var e = new PublishEventArgs();
FireBeforePublish(e);
if (!e.Cancel)
{
var result = ServiceContext.Current.ContentService.Publish(_content, u.Id);
var result = ServiceContext.Current.ContentService.Publish(_content, u.Id, true);
_published = result;
// make a lookup to see if template is 0 as the template is not initialized in the optimized
// Document.Children method which is used in PublishWithChildrenWithResult methhod
@@ -943,7 +950,7 @@ where '" + Path + ",' like " + SqlHelper.Concat("node.path", "',%'"));
[Obsolete("Deprecated, Use Umbraco.Core.Services.ContentService.PublishWithChildren()", false)]
public bool PublishWithChildrenWithResult(User u)
{
return ServiceContext.Current.ContentService.PublishWithChildren(_content, u.Id);
return ServiceContext.Current.ContentService.PublishWithChildren(_content, u.Id, true);
/*if (PublishWithResult(u))
{
@@ -986,6 +993,7 @@ where '" + Path + ",' like " + SqlHelper.Concat("node.path", "',%'"));
/// Envoking this method will publish the documents and all children recursive.
/// </summary>
/// <param name="u">The usercontext under which the action are performed</param>
[Obsolete("Deprecated, Use Umbraco.Core.Services.ContentService.PublishWithChildren()", false)]
public void PublishWithSubs(User u)
{
PublishEventArgs e = new PublishEventArgs();
@@ -993,7 +1001,9 @@ where '" + Path + ",' like " + SqlHelper.Concat("node.path", "',%'"));
if (!e.Cancel)
{
_published = true;
var published = ServiceContext.Current.ContentService.PublishWithChildren(_content, u.Id, true);
/*_published = true;
string tempVersion = Version.ToString();
DateTime versionDate = DateTime.Now;
Guid newVersion = createNewVersion(versionDate);
@@ -1014,7 +1024,7 @@ where '" + Path + ",' like " + SqlHelper.Concat("node.path", "',%'"));
XmlGenerate(new XmlDocument());
foreach (Document dc in Children.ToList())
dc.PublishWithSubs(u);
dc.PublishWithSubs(u);*/
FireAfterPublish(e);
}
@@ -1032,7 +1042,7 @@ where '" + Path + ",' like " + SqlHelper.Concat("node.path", "',%'"));
//SqlHelper.ExecuteNonQuery(string.Format("update cmsDocument set published = 0 where nodeId = {0}", Id));
//_published = false;
ServiceContext.Current.ContentService.UnPublish(_content);
ServiceContext.Current.ContentService.UnPublish(_content, 0, true);
FireAfterUnPublish(e);
}
@@ -1062,10 +1072,8 @@ where '" + Path + ",' like " + SqlHelper.Concat("node.path", "',%'"));
[Obsolete("Deprecated, Use Umbraco.Core.Services.ContentService.HasPublishedVersion()", false)]
public bool HasPublishedVersion()
{
if (_content != null)
return _content.HasPublishedVersion();
return (SqlHelper.ExecuteScalar<int>("select Count(published) as tmp from cmsDocument where published = 1 And nodeId =" + Id) > 0);
return _content.HasPublishedVersion();
//return (SqlHelper.ExecuteScalar<int>("select Count(published) as tmp from cmsDocument where published = 1 And nodeId =" + Id) > 0);
}
/// <summary>
@@ -1076,8 +1084,9 @@ where '" + Path + ",' like " + SqlHelper.Concat("node.path", "',%'"));
/// <returns></returns>
public bool HasPendingChanges()
{
double timeDiff = new TimeSpan(UpdateDate.Ticks - VersionDate.Ticks).TotalMilliseconds;
return timeDiff > 2000;
return _content.Published == false;
//double timeDiff = new TimeSpan(UpdateDate.Ticks - VersionDate.Ticks).TotalMilliseconds;
//return timeDiff > 2000;
}
/// <summary>