diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs
index adc172b413..f53bc2b43c 100644
--- a/src/Umbraco.Core/Models/Content.cs
+++ b/src/Umbraco.Core/Models/Content.cs
@@ -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)
diff --git a/src/Umbraco.Core/Models/ContentExtensions.cs b/src/Umbraco.Core/Models/ContentExtensions.cs
index dda7c98c58..46debeed07 100644
--- a/src/Umbraco.Core/Models/ContentExtensions.cs
+++ b/src/Umbraco.Core/Models/ContentExtensions.cs
@@ -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);
}
+
+ ///
+ /// Creates the xml representation for the object
+ ///
+ /// to generate xml for
+ /// Xml representation of the passed in
+ 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;
+ }
+
+ ///
+ /// Creates the xml representation for the object
+ ///
+ /// to generate xml for
+ /// Boolean indicating whether the xml should be generated for preview
+ /// Xml representation of the passed in
+ 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();
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Models/PropertyExtensions.cs b/src/Umbraco.Core/Models/PropertyExtensions.cs
index 51967c9c69..cea46bb927 100644
--- a/src/Umbraco.Core/Models/PropertyExtensions.cs
+++ b/src/Umbraco.Core/Models/PropertyExtensions.cs
@@ -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;
diff --git a/src/Umbraco.Core/Persistence/Factories/ContentFactory.cs b/src/Umbraco.Core/Persistence/Factories/ContentFactory.cs
index 83ba2cf3e3..c3545f8be1 100644
--- a/src/Umbraco.Core/Persistence/Factories/ContentFactory.cs
+++ b/src/Umbraco.Core/Persistence/Factories/ContentFactory.cs
@@ -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;
}
diff --git a/src/Umbraco.Core/Persistence/Mappers/ModelDtoMapper.cs b/src/Umbraco.Core/Persistence/Mappers/ModelDtoMapper.cs
index c44512a6fb..8410a6dfb3 100644
--- a/src/Umbraco.Core/Persistence/Mappers/ModelDtoMapper.cs
+++ b/src/Umbraco.Core/Persistence/Mappers/ModelDtoMapper.cs
@@ -155,6 +155,19 @@ namespace Umbraco.Core.Persistence.Mappers
public Func 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;
}
}
diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
index ff927c6d72..fc90f71a6a 100644
--- a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
@@ -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("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;
diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs
index 6a3e670fab..a66a2f7c05 100644
--- a/src/Umbraco.Core/Services/ContentService.cs
+++ b/src/Umbraco.Core/Services/ContentService.cs
@@ -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
///
/// Optional Id of the User issueing the publishing
+ /// Optional boolean to avoid having the cache refreshed when calling this RePublish method. By default this method will update the cache.
/// True if publishing succeeded, otherwise False
- 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();
@@ -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
///
/// The to publish
/// Optional Id of the User issueing the publishing
+ /// Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.
/// True if publishing succeeded, otherwise False
- 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);
}
///
@@ -386,10 +400,10 @@ namespace Umbraco.Core.Services
///
/// The to publish along with its children
/// Optional Id of the User issueing the publishing
+ /// Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.
/// True if publishing succeeded, otherwise False
- 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("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
///
/// The to publish
/// Optional Id of the User issueing the publishing
+ /// Optional boolean to avoid having the cache refreshed when calling this Unpublish method. By default this method will update the cache.
/// True if unpublishing succeeded, otherwise False
- 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("WHERE nodeId = @Id", new {Id = content.Id});
+ if (hasChildren)
+ {
+ foreach (var child in children)
+ {
+ DatabaseContext.Current.Database.Delete("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
///
/// The to save and publish
/// Optional Id of the User issueing the publishing
+ /// Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.
/// True if publishing succeeded, otherwise False
- 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(
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("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)
diff --git a/src/Umbraco.Core/Services/IContentService.cs b/src/Umbraco.Core/Services/IContentService.cs
index d3fc54aea7..1e194e1a45 100644
--- a/src/Umbraco.Core/Services/IContentService.cs
+++ b/src/Umbraco.Core/Services/IContentService.cs
@@ -19,11 +19,6 @@ namespace Umbraco.Core.Services
///
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
-
///
/// Gets an object by Id
///
@@ -94,40 +89,45 @@ namespace Umbraco.Core.Services
/// Re-Publishes all Content
///
/// Optional Id of the User issueing the publishing
+ /// Optional boolean to avoid having the cache refreshed when calling this RePublish method. By default this method will update the cache.
/// True if publishing succeeded, otherwise False
- bool RePublishAll(int userId = -1);
+ bool RePublishAll(int userId = -1, bool omitCacheRefresh = false);
///
/// Publishes a single object
///
/// The to publish
/// Optional Id of the User issueing the publishing
+ /// Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.
/// True if publishing succeeded, otherwise False
- bool Publish(IContent content, int userId = -1);
+ bool Publish(IContent content, int userId = -1, bool omitCacheRefresh = false);
///
/// Publishes a object and all its children
///
/// The to publish along with its children
/// Optional Id of the User issueing the publishing
+ /// Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.
/// True if publishing succeeded, otherwise False
- bool PublishWithChildren(IContent content, int userId = -1);
+ bool PublishWithChildren(IContent content, int userId = -1, bool omitCacheRefresh = false);
///
/// UnPublishes a single object
///
/// The to publish
/// Optional Id of the User issueing the publishing
+ /// Optional boolean to avoid having the cache refreshed when calling this Unpublish method. By default this method will update the cache.
/// True if unpublishing succeeded, otherwise False
- bool UnPublish(IContent content, int userId = -1);
+ bool UnPublish(IContent content, int userId = -1, bool omitCacheRefresh = false);
///
/// Saves and Publishes a single object
///
/// The to save and publish
/// Optional Id of the User issueing the publishing
+ /// Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.
/// True if publishing succeeded, otherwise False
- bool SaveAndPublish(IContent content, int userId = -1);
+ bool SaveAndPublish(IContent content, int userId = -1, bool omitCacheRefresh = false);
///
/// Saves a single object
diff --git a/src/Umbraco.Tests/Models/ContentXmlTest.cs b/src/Umbraco.Tests/Models/ContentXmlTest.cs
index 0512a94116..a564eaaac0 100644
--- a/src/Umbraco.Tests/Models/ContentXmlTest.cs
+++ b/src/Umbraco.Tests/Models/ContentXmlTest.cs
@@ -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));
}
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/ContentExtensions.cs b/src/Umbraco.Web/ContentExtensions.cs
deleted file mode 100644
index e135dcf24e..0000000000
--- a/src/Umbraco.Web/ContentExtensions.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-using System.Xml.Linq;
-using Umbraco.Core;
-using Umbraco.Core.Models;
-
-namespace Umbraco.Web
-{
- public static class ContentExtensions
- {
- ///
- /// Creates the xml representation for the object
- ///
- /// to generate xml for
- /// Xml representation of the passed in
- 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;
- }
-
- ///
- /// Creates the xml representation for the object
- ///
- /// to generate xml for
- /// Boolean indicating whether the xml should be generated for preview
- /// Xml representation of the passed in
- 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();
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index 399a2e15bc..863b0a8901 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -247,7 +247,6 @@
-
diff --git a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs
index 8eaa3760f7..cdd321858d 100644
--- a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs
+++ b/src/umbraco.cms/businesslogic/datatype/DefaultData.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; }
+ }
+
///
/// Initializes a new instance of the class.
///
diff --git a/src/umbraco.cms/businesslogic/web/Document.cs b/src/umbraco.cms/businesslogic/web/Document.cs
index faf507923e..25555c2848 100644
--- a/src/umbraco.cms/businesslogic/web/Document.cs
+++ b/src/umbraco.cms/businesslogic/web/Document.cs
@@ -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.
///
/// The usercontext under which the action are performed
+ [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("select Count(published) as tmp from cmsDocument where published = 1 And nodeId =" + Id) > 0);
+ return _content.HasPublishedVersion();
+ //return (SqlHelper.ExecuteScalar("select Count(published) as tmp from cmsDocument where published = 1 And nodeId =" + Id) > 0);
}
///
@@ -1076,8 +1084,9 @@ where '" + Path + ",' like " + SqlHelper.Concat("node.path", "',%'"));
///
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;
}
///