Remove rollback service method
This commit is contained in:
@@ -337,7 +337,7 @@ namespace Umbraco.Core.Models
|
||||
if (other.ContentTypeId != ContentTypeId)
|
||||
throw new InvalidOperationException("Cannot copy values from a different content type.");
|
||||
|
||||
var published = VersionId > PublishedVersionId;
|
||||
var published = CopyingFromSelf(other);
|
||||
|
||||
// note: use property.SetValue(), don't assign pvalue.EditValue, else change tracking fails
|
||||
|
||||
@@ -370,7 +370,7 @@ namespace Umbraco.Core.Models
|
||||
if (other.ContentTypeId != ContentTypeId)
|
||||
throw new InvalidOperationException("Cannot copy values from a different content type.");
|
||||
|
||||
var published = VersionId > PublishedVersionId;
|
||||
var published = CopyingFromSelf(other);
|
||||
|
||||
// note: use property.SetValue(), don't assign pvalue.EditValue, else change tracking fails
|
||||
|
||||
|
||||
@@ -1828,74 +1828,6 @@ namespace Umbraco.Core.Services
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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">Optional 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, int versionId, int userId = 0)
|
||||
{
|
||||
using (var uow = UowProvider.CreateUnitOfWork())
|
||||
{
|
||||
uow.WriteLock(Constants.Locks.ContentTree);
|
||||
var repository = uow.CreateRepository<IContentRepository>();
|
||||
|
||||
var currContent = repository.Get(id);
|
||||
var origContent = repository.GetVersion(versionId);
|
||||
|
||||
var rollbackEventArgs = new RollbackEventArgs<IContent>(origContent);
|
||||
if (uow.Events.DispatchCancelable(RollingBack, this, rollbackEventArgs))
|
||||
{
|
||||
uow.Complete();
|
||||
return origContent;
|
||||
}
|
||||
|
||||
// orig content versions
|
||||
// pk < published pk = normal, rollback to an older version
|
||||
// pk = published pk = normal, rollback to currently published version
|
||||
// pk > published pk = special, rollback to current 'edit' version
|
||||
//
|
||||
// in that last case, we want to copy the published values
|
||||
// what-if there's no 'published' version for now?
|
||||
// fixme WE DON'T WANT TO DO THIS HERE!
|
||||
var copyPublished = origContent.VersionId > origContent.PublishedVersionId;
|
||||
//((Content) currContent).CopyAllValues(origContent, copyPublished);
|
||||
((Content) currContent).CopyAllValues(origContent);
|
||||
currContent.WriterId = userId;
|
||||
|
||||
// builtin values
|
||||
if (copyPublished)
|
||||
{
|
||||
currContent.Name = origContent.PublishName;
|
||||
currContent.Template = origContent.PublishTemplate;
|
||||
}
|
||||
else
|
||||
{
|
||||
currContent.Name = origContent.Name;
|
||||
currContent.Template = origContent.Template;
|
||||
}
|
||||
|
||||
// save the values
|
||||
repository.AddOrUpdate(currContent);
|
||||
|
||||
rollbackEventArgs.CanCancel = false;
|
||||
uow.Events.Dispatch(RolledBack, this, rollbackEventArgs);
|
||||
uow.Events.Dispatch(TreeChanged, this, new TreeChange<IContent>(currContent, TreeChangeTypes.RefreshNode).ToEventArgs());
|
||||
Audit(uow, AuditType.RollBack, "Content rollback performed by user", currContent.WriterId, currContent.Id);
|
||||
|
||||
uow.Complete();
|
||||
|
||||
return currContent;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sorts a collection of <see cref="IContent"/> objects by updating the SortOrder according
|
||||
/// to the ordering of items in the passed in <see cref="IEnumerable{T}"/>.
|
||||
|
||||
@@ -373,12 +373,6 @@ namespace Umbraco.Core.Services
|
||||
/// </summary>
|
||||
IEnumerable<PublishResult> PerformScheduledPublish();
|
||||
|
||||
// fixme missing the differnt type of properties - should we do it manually?
|
||||
/// <summary>
|
||||
/// Rolls a document back a previous version.
|
||||
/// </summary>
|
||||
IContent Rollback(int id, int versionId, int userId = 0);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Permissions
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Umbraco.Tests.Services
|
||||
/// This is more of an integration test as it involves multiple layers
|
||||
/// as well as configuration.
|
||||
/// </summary>
|
||||
[TestFixture, RequiresSTA]
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true)]
|
||||
public class ContentServiceTests : TestWithSomeContentBase
|
||||
{
|
||||
@@ -2056,7 +2056,11 @@ namespace Umbraco.Tests.Services
|
||||
// version3, third and current published version
|
||||
|
||||
// rollback all values to version1
|
||||
var rollback = contentService.Rollback(NodeDto.NodeIdSeed + 4, version1);
|
||||
var rollback = contentService.GetById(NodeDto.NodeIdSeed + 4);
|
||||
var rollto = contentService.GetVersion(version1);
|
||||
rollback.CopyValues(rollto);
|
||||
rollback.Name = rollto.Name; // must do it explicitely
|
||||
contentService.Save(rollback);
|
||||
|
||||
Assert.IsNotNull(rollback);
|
||||
Assert.IsTrue(rollback.Published);
|
||||
@@ -2074,7 +2078,11 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
// rollback all values to current version
|
||||
// special because... current has edits... this really is equivalent to rolling back to version2
|
||||
var rollback2 = contentService.Rollback(NodeDto.NodeIdSeed + 4, version3);
|
||||
var rollback2 = contentService.GetById(NodeDto.NodeIdSeed + 4);
|
||||
var rollto2 = contentService.GetVersion(version3);
|
||||
rollback2.CopyValues(rollto2);
|
||||
rollback2.Name = rollto2.PublishName; // must do it explicitely AND must pick the publish one!
|
||||
contentService.Save(rollback2);
|
||||
|
||||
Assert.IsTrue(rollback2.Published);
|
||||
Assert.IsFalse(rollback2.Edited); // all changes cleared!
|
||||
@@ -2093,7 +2101,10 @@ namespace Umbraco.Tests.Services
|
||||
content.SetValue("author", "Bob Doe");
|
||||
contentService.Save(content);
|
||||
Assert.IsTrue(content.Edited);
|
||||
content = contentService.Rollback(content.Id, content.VersionId);
|
||||
rollto = contentService.GetVersion(content.VersionId);
|
||||
content.CopyValues(rollto);
|
||||
content.Name = rollto.PublishName; // must do it explicitely AND must pick the publish one!
|
||||
contentService.Save(content);
|
||||
Assert.IsFalse(content.Edited);
|
||||
Assert.AreEqual("Text Page 2 ReReUpdated", content.Name);
|
||||
Assert.AreEqual("Jane Doe", content.GetValue("author"));
|
||||
|
||||
Reference in New Issue
Block a user