Adding more tests to cover the ContentService and refactoring.

This commit is contained in:
sitereactor
2012-10-31 15:15:02 -01:00
parent b86bfdd87b
commit 4e2bcee35b
10 changed files with 322 additions and 45 deletions

View File

@@ -55,19 +55,19 @@ namespace Umbraco.Core.Persistence.Factories
var result = service.ToStream(property.Value);
dto.Text = result.ResultStream.ToJsonString();
}*/
if (property.DataTypeDatabaseType == DataTypeDatabaseType.Integer)
if (property.DataTypeDatabaseType == DataTypeDatabaseType.Integer && property.Value != null)
{
dto.Integer = int.Parse(property.Value.ToString());
}
else if (property.DataTypeDatabaseType == DataTypeDatabaseType.Date)
else if (property.DataTypeDatabaseType == DataTypeDatabaseType.Date && property.Value != null)
{
dto.Date = DateTime.Parse(property.Value.ToString());
}
else if (property.DataTypeDatabaseType == DataTypeDatabaseType.Ntext)
else if (property.DataTypeDatabaseType == DataTypeDatabaseType.Ntext && property.Value != null)
{
dto.Text = property.Value.ToString();
}
else if (property.DataTypeDatabaseType == DataTypeDatabaseType.Nvarchar)
else if (property.DataTypeDatabaseType == DataTypeDatabaseType.Nvarchar && property.Value != null)
{
dto.VarChar = property.Value.ToString();
}

View File

@@ -35,6 +35,7 @@ namespace Umbraco.Core.Persistence
var foreignSql = SyntaxConfig.SqlSyntaxProvider.ToCreateForeignKeyStatements(tableDefinition);
var indexSql = SyntaxConfig.SqlSyntaxProvider.ToCreateIndexStatements(tableDefinition);
/*
#if DEBUG
Console.WriteLine(createSql);
Console.WriteLine(createPrimaryKeySql);
@@ -47,6 +48,7 @@ namespace Umbraco.Core.Persistence
Console.WriteLine(sql);
}
#endif
*/
var tableExist = db.TableExist(tableName);
if (overwrite && tableExist)

View File

@@ -479,6 +479,9 @@ namespace Umbraco.Core.Persistence.Querying
if (fieldType == typeof(decimal))
return ((decimal)value).ToString(CultureInfo.InvariantCulture);
if(fieldType == typeof(DateTime))
return "'" + EscapeParam(((DateTime)value).ToString(CultureInfo.InvariantCulture)) + "'";
return ShouldQuoteValue(fieldType)
? "'" + EscapeParam(value) + "'"
: value.ToString();

View File

@@ -83,7 +83,7 @@ namespace Umbraco.Core.Persistence.Repositories
//NOTE: This doesn't allow properties to be part of the query
var dtos = Database.Fetch<DocumentDto, ContentVersionDto, ContentDto, NodeDto>(sql);
foreach (var dto in dtos)
foreach (var dto in dtos.DistinctBy(x => x.NodeId))
{
yield return Get(dto.NodeId);
}
@@ -259,7 +259,8 @@ namespace Umbraco.Core.Persistence.Repositories
public IEnumerable<IContent> GetAllVersions(int id)
{
var contentSql = GetBaseQuery(false);
contentSql.Append(GetBaseWhereClause(id));
//contentSql.Append(GetBaseWhereClause(id));
contentSql.Where("[umbracoNode].[id] = @Id", new { Id = id });
contentSql.OrderBy("[cmsContentVersion].[VersionDate] DESC");
var documentDtos = Database.Fetch<DocumentDto, ContentVersionDto, ContentDto, NodeDto>(contentSql);
@@ -272,7 +273,8 @@ namespace Umbraco.Core.Persistence.Repositories
public IContent GetByVersion(int id, Guid versionId)
{
var contentSql = GetBaseQuery(false);
contentSql.Append(GetBaseWhereClause(id));
//contentSql.Append(GetBaseWhereClause(id));
contentSql.Where("[umbracoNode].[id] = @Id", new { Id = id });
contentSql.Where("[cmsContentVersion].[VersionId] = @VersionId", new { VersionId = versionId });
contentSql.OrderBy("[cmsContentVersion].[VersionDate] DESC");

View File

@@ -57,14 +57,14 @@
<umbraco>
<infrastructure>
<repositories>
<repository interfaceShortTypeName="IContentRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.ContentRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.RuntimeCacheProvider, Umbraco.Core"/>
<repository interfaceShortTypeName="IContentTypeRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.ContentTypeRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.InMemoryCacheProvider, Umbraco.Core"/>
<repository interfaceShortTypeName="IContentRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.ContentRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.NullCacheProvider, Umbraco.Core"/><!-- RuntimeCacheProvider -->
<repository interfaceShortTypeName="IContentTypeRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.ContentTypeRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.NullCacheProvider, Umbraco.Core"/><!-- InMemoryCacheProvider -->
<repository interfaceShortTypeName="IDataTypeDefinitionRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.DataTypeDefinitionRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.NullCacheProvider, Umbraco.Core"/>
<repository interfaceShortTypeName="IDictionaryRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.DictionaryRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.InMemoryCacheProvider, Umbraco.Core"/>
<repository interfaceShortTypeName="ILanguageRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.LanguageRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.InMemoryCacheProvider, Umbraco.Core"/>
<repository interfaceShortTypeName="IMacroRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.MacroRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.InMemoryCacheProvider, Umbraco.Core"/>
<repository interfaceShortTypeName="IMediaRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.MediaRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.RuntimeCacheProvider, Umbraco.Core"/>
<repository interfaceShortTypeName="IMediaTypeRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.MediaTypeRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.InMemoryCacheProvider, Umbraco.Core"/>
<repository interfaceShortTypeName="IDictionaryRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.DictionaryRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.NullCacheProvider, Umbraco.Core"/><!-- InMemoryCacheProvider -->
<repository interfaceShortTypeName="ILanguageRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.LanguageRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.NullCacheProvider, Umbraco.Core"/><!-- InMemoryCacheProvider -->
<repository interfaceShortTypeName="IMacroRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.MacroRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.NullCacheProvider, Umbraco.Core"/><!-- InMemoryCacheProvider -->
<repository interfaceShortTypeName="IMediaRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.MediaRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.NullCacheProvider, Umbraco.Core"/><!-- RuntimeCacheProvider -->
<repository interfaceShortTypeName="IMediaTypeRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.MediaTypeRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.NullCacheProvider, Umbraco.Core"/><!-- InMemoryCacheProvider -->
<repository interfaceShortTypeName="IRelationRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.RelationRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.NullCacheProvider, Umbraco.Core"/>
<repository interfaceShortTypeName="IRelationTypeRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.RelationTypeRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.NullCacheProvider, Umbraco.Core"/>
<repository interfaceShortTypeName="IScriptRepository" repositoryFullTypeName="Umbraco.Core.Persistence.Repositories.ScriptRepository, Umbraco.Core" cacheProviderFullTypeName="Umbraco.Core.Persistence.Caching.NullCacheProvider, Umbraco.Core"/>

View File

@@ -8,6 +8,11 @@ using Umbraco.Tests.TestHelpers.Entities;
namespace Umbraco.Tests.Services
{
/// <summary>
/// Tests covering all methods in the ContentService class.
/// This is more of an integration test as it involves multiple layers
/// as well as configuration.
/// </summary>
[TestFixture]
public class ContentServiceTests : BaseDatabaseFactoryTest
{
@@ -25,7 +30,7 @@ namespace Umbraco.Tests.Services
var contentService = ServiceContext.ContentService;
// Act
IContent content = contentService.CreateContent(-1, "umbTextpage");
var content = contentService.CreateContent(-1, "umbTextpage");
// Assert
Assert.That(content, Is.Not.Null);
@@ -86,59 +91,270 @@ namespace Umbraco.Tests.Services
Assert.That(contents.Count(), Is.GreaterThanOrEqualTo(2));
}
[Test]
public void Can_Get_All_Versions_Of_Content()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
var subpage2 = contentService.GetById(1048);
subpage2.Name = "Text Page 2 Updated";
subpage2.SetValue("author", "Jane Doe");
contentService.Save(subpage2, 0);
// Act
var versions = contentService.GetVersions(1048);
// Assert
Assert.That(versions.Any(), Is.True);
Assert.That(versions.Count(), Is.GreaterThanOrEqualTo(2));
}
[Test]
public void Can_Get_Root_Content()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
// Act
var contents = contentService.GetRootContent();
// Assert
Assert.That(contents, Is.Not.Null);
Assert.That(contents.Any(), Is.True);
Assert.That(contents.Count(), Is.EqualTo(1));
}
[Test]
public void Can_Get_Content_For_Expiration()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
// Act
var contents = contentService.GetContentForExpiration();
// Assert
Assert.That(DateTime.UtcNow.AddMinutes(-5) <= DateTime.UtcNow);
Assert.That(contents, Is.Not.Null);
Assert.That(contents.Any(), Is.True);
Assert.That(contents.Count(), Is.EqualTo(1));
}
[Test]
public void Can_Get_Content_For_Release()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
// Act
var contents = contentService.GetContentForRelease();
// Assert
Assert.That(DateTime.UtcNow.AddMinutes(-5) <= DateTime.UtcNow);
Assert.That(contents, Is.Not.Null);
Assert.That(contents.Any(), Is.True);
Assert.That(contents.Count(), Is.EqualTo(1));
}
[Test]
public void Can_Get_Content_In_RecycleBin()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
// Act
var contents = contentService.GetContentInRecycleBin();
// Assert
Assert.That(contents, Is.Not.Null);
Assert.That(contents.Any(), Is.True);
Assert.That(contents.Count(), Is.EqualTo(1));
}
[Test]
public void Can_RePublish_All_Content()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
var contentTypeService = ServiceContext.ContentTypeService;
var contentType = contentTypeService.GetContentType("umbTextpage");
// Act
contentService.RePublishAll(0);
var contents = contentService.GetContentOfContentType(contentType.Id);
// Assert
Assert.That(contents.First(x => x.Id == 1046).Published, Is.True);//No restrictions, so should be published
Assert.That(contents.First(x => x.Id == 1047).Published, Is.True);//Released 5 mins ago, so should be published
Assert.That(contents.First(x => x.Id == 1048).Published, Is.False);//Expired 5 mins ago, so shouldn't be published
Assert.That(contents.First(x => x.Id == 1049).Published, Is.False);//Trashed content, so shouldn't be published
}
public void Can_Publish_Content()
{ }
public void Can_Publish_Only_Valid_Content()
{ }
public void Can_Publish_Content_Children()
{ }
public void Can_Save_And_Publish_Content()
{ }
[Test]
public void Can_Save_Content()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
var content = contentService.CreateContent(-1, "umbTextpage");
content.Name = "Home US";
content.SetValue("author", "Barack Obama");
// Act
contentService.Save(content, 0);
// Assert
Assert.That(content.HasIdentity, Is.True);
}
[Test]
public void Can_Bulk_Save_Content()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
var contentTypeService = ServiceContext.ContentTypeService;
var contentType = contentTypeService.GetContentType("umbTextpage");
Content subpage = MockedContent.CreateTextpageContent(contentType, "Text Subpage 1", 1047);
Content subpage2 = MockedContent.CreateTextpageContent(contentType, "Text Subpage 2", 1047);
var list = new List<IContent> {subpage, subpage2};
// Act
contentService.Save(list, 0);
// Assert
Assert.That(list.Any(x => !x.HasIdentity), Is.False);
}
[Test]
public void Can_Delete_Content_Of_Specific_ContentType()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
var contentTypeService = ServiceContext.ContentTypeService;
var contentType = contentTypeService.GetContentType("umbTextpage");
// Act
contentService.DeleteContentOfType(contentType.Id);
var rootContent = contentService.GetRootContent();
var contents = contentService.GetContentOfContentType(contentType.Id);
// Assert
Assert.That(rootContent.Any(), Is.False);
Assert.That(contents.Any(x => !x.Trashed), Is.False);
}
[Test]
public void Can_Delete_Content()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
var content = contentService.GetById(1049);
// Act
contentService.Delete(content, 0);
var deleted = contentService.GetById(1049);
// Assert
Assert.That(deleted, Is.Null);
}
[Test]
public void Can_Move_Content_To_RecycleBin()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
var content = contentService.GetById(1048);
// Act
contentService.MoveToRecycleBin(content, 0);
// Assert
Assert.That(content.ParentId, Is.EqualTo(-20));
Assert.That(content.Trashed, Is.True);
}
[Test]
public void Can_Empty_RecycleBin()
{
// Arrange
var contentService = ServiceContext.ContentService;
// Act
contentService.EmptyRecycleBin();
var contents = contentService.GetContentInRecycleBin();
// Assert
Assert.That(contents.Any(), Is.False);
}
[Test]
public void Can_Move_Content()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
var content = contentService.GetById(1049);
// Act - moving out of recycle bin
contentService.Move(content, 1046, 0);
// Assert
Assert.That(content.ParentId, Is.EqualTo(1046));
Assert.That(content.Trashed, Is.False);
Assert.That(content.Published, Is.False);
}
[Test]
public void Can_Copy_Content()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
var content = contentService.GetById(1048);
// Act
var copy = contentService.Copy(content, content.ParentId, 0);
// Assert
Assert.That(copy, Is.Not.Null);
Assert.That(copy.Id, Is.Not.EqualTo(content.Id));
Assert.AreNotSame(content, copy);
Assert.AreNotEqual(content.Name, copy.Name);
}
public void Can_Send_To_Publication()
{ }
[Test]
public void Can_Rollback_Version_On_Content()
{ }
{
// Arrange
var contentService = ServiceContext.ContentService;
var subpage2 = contentService.GetById(1048);
var version = subpage2.Version;
subpage2.Name = "Text Page 2 Updated";
subpage2.SetValue("author", "Jane Doe");
contentService.Save(subpage2, 0);
// Act
var rollback = contentService.Rollback(1048, version, 0);
// Assert
Assert.That(rollback, Is.Not.Null);
Assert.AreNotEqual(rollback.Version, version);
Assert.That(rollback.GetValue<string>("author"), Is.Not.EqualTo("Jane Doe"));
Assert.AreEqual(subpage2.Name, rollback.Name);
}
public void CreateTestData()
{
@@ -154,11 +370,19 @@ namespace Umbraco.Tests.Services
//Create and Save Content "Text Page 1" based on "umbTextpage" -> 1047
Content subpage = MockedContent.CreateTextpageContent(contentType, "Text Page 1", textpage.Id);
subpage.ReleaseDate = DateTime.UtcNow.AddMinutes(-5);
ServiceContext.ContentService.Save(subpage, 0);
//Create and Save Content "Text Page 1" based on "umbTextpage" -> 1048
Content subpage2 = MockedContent.CreateTextpageContent(contentType, "Text Page 2", textpage.Id);
subpage2.ExpireDate = DateTime.UtcNow.AddMinutes(-5);
subpage2.ChangePublishedState(true);
ServiceContext.ContentService.Save(subpage2, 0);
//Create and Save Content "Text Page Deleted" based on "umbTextpage" -> 1049
Content trashed = MockedContent.CreateTextpageContent(contentType, "Text Page Deleted", -20);
trashed.Trashed = true;
ServiceContext.ContentService.Save(trashed, 0);
}
}
}

View File

@@ -4,7 +4,7 @@ namespace Umbraco.Tests.TestHelpers.Entities
{
public class MockedContent
{
public static Content CreateTextpageContent(ContentType contentType)
public static Content CreateTextpageContent(IContentType contentType)
{
var content = new Content(-1, contentType) {Name = "Home", Language = "en-US", Level = 1, ParentId = -1, SortOrder = 1, Template = "~/masterpages/umbTextPage.master", UserId = 0};
object obj =
@@ -20,7 +20,7 @@ namespace Umbraco.Tests.TestHelpers.Entities
return content;
}
public static Content CreateTextpageContent(ContentType contentType, string name, int parentId)
public static Content CreateTextpageContent(IContentType contentType, string name, int parentId)
{
var content = new Content(parentId, contentType) { Name = name, Language = "en-US", ParentId = parentId, Template = "~/masterpages/umbTextPage.master", UserId = 0 };
object obj =

View File

@@ -108,6 +108,31 @@ namespace Umbraco.Tests.TestHelpers.Entities
return contentType;
}
public static ContentType CreateSimpleContentType(string alias, string name, bool mandatory)
{
var contentType = new ContentType(-1)
{
Alias = alias,
Name = name,
Description = "ContentType used for simple text pages",
Icon = ".sprTreeDoc3",
Thumbnail = "doc2.png",
SortOrder = 1,
UserId = 0,
DefaultTemplate = "~/masterpages/umbSimplePage.master",
Trashed = false
};
var contentCollection = new PropertyTypeCollection();
contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "title", Name = "Title", Description = "", HelpText = "", Mandatory = mandatory, SortOrder = 1, DataTypeId = -88 });
contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "bodyText", Name = "Body Text", Description = "", HelpText = "", Mandatory = mandatory, SortOrder = 2, DataTypeId = -87 });
contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "author", Name = "Author", Description = "Name of the author", HelpText = "", Mandatory = mandatory, SortOrder = 3, DataTypeId = -88 });
contentType.PropertyGroups.Add(new PropertyGroup(contentCollection) { Name = "Content", SortOrder = 1 });
return contentType;
}
public static ContentType CreateSimpleContentType(string alias, string name, PropertyTypeCollection collection)
{
var contentType = new ContentType(-1)

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
@@ -59,7 +60,8 @@ namespace Umbraco.Web.Publishing
if (e.Cancel)
return false;
foreach (var content in children)
//Only update content thats not already been published
foreach (var content in children.Where(x => x.Published == false))
{
FireBeforePublish(content, e);

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.Repositories;
@@ -144,28 +145,28 @@ namespace Umbraco.Web.Services
}
/// <summary>
/// Gets a collection of <see cref="IContent"/> objects, which has an expiration date greater then today
/// 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()
{
var repository = RepositoryResolver.ResolveByType<IContentRepository, IContent, int>(_unitOfWork);
var query = Query<IContent>.Builder.Where(x => x.Published == true && x.ExpireDate != null && x.ExpireDate.Value <= DateTime.Now);
var query = Query<IContent>.Builder.Where(x => x.Published == true && x.ExpireDate <= DateTime.UtcNow);
var contents = repository.GetByQuery(query);
return contents;
}
/// <summary>
/// Gets a collection of <see cref="IContent"/> objects, which has a release date greater then today
/// Gets a collection of <see cref="IContent"/> objects, which has a release date less than or equal to today.
/// </summary>
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
public IEnumerable<IContent> GetContentForRelease()
{
var repository = RepositoryResolver.ResolveByType<IContentRepository, IContent, int>(_unitOfWork);
var query = Query<IContent>.Builder.Where(x => x.Published == true && x.ReleaseDate != null && x.ReleaseDate.Value <= DateTime.Now);
var query = Query<IContent>.Builder.Where(x => x.Published == false && x.ReleaseDate <= DateTime.UtcNow);
var contents = repository.GetByQuery(query);
return contents;
@@ -204,6 +205,7 @@ namespace Umbraco.Web.Services
{
if(content.IsValid())
{
list.Add(content);
list.AddRange(GetChildrenDeep(content.Id));
}
}
@@ -212,7 +214,8 @@ namespace Umbraco.Web.Services
var published = _publishingStrategy.PublishWithChildren(list, userId);
if (published)
{
foreach (var item in list)
//Only loop through content where the Published property has been updated
foreach (var item in list.Where(x => ((ICanBeDirty)x).IsPropertyDirty("Published")))
{
repository.AddOrUpdate(item);
}
@@ -220,7 +223,7 @@ namespace Umbraco.Web.Services
_unitOfWork.Commit();
//TODO Change this so we can avoid a depencency to the horrible library method / umbraco.content (singleton) class.
global::umbraco.library.RefreshContent();
//global::umbraco.library.RefreshContent();
}
return published;
@@ -276,7 +279,8 @@ namespace Umbraco.Web.Services
var published = _publishingStrategy.PublishWithChildren(list, userId);
if (published)
{
foreach (var item in list)
//Only loop through content where the Published property has been updated
foreach (var item in list.Where(x => ((ICanBeDirty)x).IsPropertyDirty("Published")))
{
repository.AddOrUpdate(item);
}
@@ -285,7 +289,7 @@ namespace Umbraco.Web.Services
//TODO Change this so we can avoid a depencency to the horrible library method / umbraco.content (singleton) class.
//TODO Need to investigate if it will also update the cache for children of the Content object
global::umbraco.library.UpdateDocumentCache(content.Id);
//global::umbraco.library.UpdateDocumentCache(content.Id);
}
return published;
@@ -301,6 +305,7 @@ namespace Umbraco.Web.Services
{
var repository = RepositoryResolver.ResolveByType<IContentRepository, IContent, int>(_unitOfWork);
//TODO Look for children and unpublish them if any exists
var unpublished = _publishingStrategy.UnPublish(content, userId);
if (unpublished)
@@ -309,7 +314,7 @@ namespace Umbraco.Web.Services
_unitOfWork.Commit();
//TODO Change this so we can avoid a depencency to the horrible library method / umbraco.content class.
global::umbraco.library.UnPublishSingleNode(content.Id);
//global::umbraco.library.UnPublishSingleNode(content.Id);
}
return unpublished;
@@ -378,7 +383,7 @@ namespace Umbraco.Web.Services
_unitOfWork.Commit();
//TODO Change this so we can avoid a depencency to the horrible library method / umbraco.content (singleton) class.
global::umbraco.library.UpdateDocumentCache(content.Id);
//global::umbraco.library.UpdateDocumentCache(content.Id);
}
return published;
@@ -460,7 +465,7 @@ namespace Umbraco.Web.Services
//TODO If content item has children those should also be moved to the recycle bin
//TODO Unpublish deleted content + children
var repository = RepositoryResolver.ResolveByType<IContentRepository, IContent, int>(_unitOfWork);
((Content)content).ChangeTrashedState(true);
content.ChangeTrashedState(true);
repository.AddOrUpdate(content);
_unitOfWork.Commit();
}
@@ -478,7 +483,17 @@ namespace Umbraco.Web.Services
/// <param name="userId">Id of the User moving the Content</param>
public void Move(IContent content, int parentId, int userId)
{
content.ParentId = parentId;
//If Content is being moved away from Recycle Bin, its state should be un-trashed
if(content.Trashed && parentId != -20)
{
content.ChangeTrashedState(false, parentId);
}
else
{
content.ParentId = parentId;
}
//If Content is published, it should be (re)published from its new location
if(content.Published)
{
SaveAndPublish(content, userId);
@@ -518,6 +533,7 @@ namespace Umbraco.Web.Services
{
var copy = ((Content) content).Clone();
copy.ParentId = parentId;
copy.Name = copy.Name + " (1)";
var repository = RepositoryResolver.ResolveByType<IContentRepository, IContent, int>(_unitOfWork);
@@ -554,13 +570,16 @@ namespace Umbraco.Web.Services
/// Rollback an <see cref="IContent"/> object to a previous version.
/// This will create a new version, which is a copy of all the old data.
/// </summary>
/// <remarks>
/// The way data is stored actually only allows us to rollback on properties
/// and not data like Name and Alias of the Content.
/// </remarks>
/// <param name="id">Id of the <see cref="IContent"/>being rolled back</param>
/// <param name="versionId">Id of the version to rollback to</param>
/// <param name="userId">Id of the User issueing the rollback of the Content</param>
/// <returns>The newly created <see cref="IContent"/> object</returns>
public IContent Rollback(int id, Guid versionId, int userId)
{
//TODO Need to test if this actually works
var repository = RepositoryResolver.ResolveByType<IContentRepository, IContent, int>(_unitOfWork);
var content = repository.GetByVersion(id, versionId);