diff --git a/src/Umbraco.Core/Persistence/Repositories/RecycleBinRepository.cs b/src/Umbraco.Core/Persistence/Repositories/RecycleBinRepository.cs
index f17a0dd0d2..d63c338542 100644
--- a/src/Umbraco.Core/Persistence/Repositories/RecycleBinRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/RecycleBinRepository.cs
@@ -63,6 +63,7 @@ namespace Umbraco.Core.Persistence.Repositories
FormatDeleteStatement("cmsContentVersion", "ContentId"),
FormatDeleteStatement("cmsContentXml", "nodeId"),
FormatDeleteStatement("cmsContent", "nodeId"),
+ //TODO: Why is this being done? We just delete this exact data in the next line
"UPDATE umbracoNode SET parentID = '" + RecycleBinId + "' WHERE trashed = '1' AND nodeObjectType = @NodeObjectType",
"DELETE FROM umbracoNode WHERE trashed = '1' AND nodeObjectType = @NodeObjectType"
};
@@ -91,14 +92,18 @@ namespace Umbraco.Core.Persistence.Repositories
}
}
+ ///
+ /// A delete statement taht will delete anything in the table specified where it's PK (keyName) is found in the
+ /// list of umbracoNode.id that have trashed flag set
+ ///
+ ///
+ ///
+ ///
private string FormatDeleteStatement(string tableName, string keyName)
{
- //This query works with sql ce and sql server:
- //DELETE FROM umbracoUser2NodeNotify WHERE umbracoUser2NodeNotify.nodeId IN
- //(SELECT nodeId FROM umbracoUser2NodeNotify as TB1 INNER JOIN umbracoNode as TB2 ON TB1.nodeId = TB2.id WHERE TB2.trashed = '1' AND TB2.nodeObjectType = 'C66BA18E-EAF3-4CFF-8A22-41B16D66A972')
return
string.Format(
- "DELETE FROM {0} WHERE {0}.{1} IN (SELECT TB1.{1} FROM {0} as TB1 INNER JOIN umbracoNode as TB2 ON TB1.{1} = TB2.id WHERE TB2.trashed = '1' AND TB2.nodeObjectType = @NodeObjectType)",
+ "DELETE FROM {0} WHERE {0}.{1} IN (SELECT id FROM umbracoNode WHERE trashed = '1' AND nodeObjectType = @NodeObjectType)",
tableName, keyName);
}
diff --git a/src/Umbraco.Tests/Services/ContentServiceTests.cs b/src/Umbraco.Tests/Services/ContentServiceTests.cs
index 0078d3e83e..e89d520f0f 100644
--- a/src/Umbraco.Tests/Services/ContentServiceTests.cs
+++ b/src/Umbraco.Tests/Services/ContentServiceTests.cs
@@ -1339,6 +1339,69 @@ namespace Umbraco.Tests.Services
Assert.That(contents.Any(), Is.False);
}
+ [Test]
+ public void Can_Empty_RecycleBin_With_Content_That_Has_All_Related_Data()
+ {
+ // Arrange
+ //need to:
+ // * add relations
+ // * add permissions
+ // * add notifications
+ // * public access
+ // * tags
+ // * domain
+ // * published & preview data
+ // * multiple versions
+
+ var contentType = MockedContentTypes.CreateAllTypesContentType("test", "test");
+ ServiceContext.ContentTypeService.Save(contentType, 0);
+
+ object obj =
+ new
+ {
+ tags = "Hello,World"
+ };
+ var content1 = MockedContent.CreateBasicContent(contentType);
+ content1.PropertyValues(obj);
+ content1.ResetDirtyProperties(false);
+ ServiceContext.ContentService.Save(content1, 0);
+ Assert.IsTrue(ServiceContext.ContentService.PublishWithStatus(content1, 0).Success);
+ var content2 = MockedContent.CreateBasicContent(contentType);
+ content2.PropertyValues(obj);
+ content2.ResetDirtyProperties(false);
+ ServiceContext.ContentService.Save(content2, 0);
+ Assert.IsTrue(ServiceContext.ContentService.PublishWithStatus(content2, 0).Success);
+
+ ServiceContext.RelationService.Save(new RelationType(Constants.ObjectTypes.DocumentGuid, Constants.ObjectTypes.DocumentGuid, "test"));
+ Assert.IsNotNull(ServiceContext.RelationService.Relate(content1, content2, "test"));
+
+ ServiceContext.PublicAccessService.Save(new PublicAccessEntry(content1, content2, content2, new List
+ {
+ new PublicAccessRule
+ {
+ RuleType = "test",
+ RuleValue = "test"
+ }
+ }));
+ Assert.IsTrue(ServiceContext.PublicAccessService.AddRule(content1, "test2", "test2").Success);
+
+ Assert.IsNotNull(ServiceContext.NotificationService.CreateNotification(ServiceContext.UserService.GetUserById(0), content1, "test"));
+
+ ServiceContext.ContentService.AssignContentPermission(content1, 'A', new[] {0});
+
+ Assert.IsTrue(ServiceContext.DomainService.Save(new UmbracoDomain("www.test.com", "en-AU")
+ {
+ RootContentId = content1.Id
+ }).Success);
+
+ // Act
+ ServiceContext.ContentService.EmptyRecycleBin();
+ var contents = ServiceContext.ContentService.GetContentInRecycleBin();
+
+ // Assert
+ Assert.That(contents.Any(), Is.False);
+ }
+
[Test]
public void Can_Move_Content()
{