mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Saving restored version as Draft instead of Published, depending on ContentTypeSettings,Draftable.
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
using Orchard.AuditTrail.Helpers;
|
using Orchard.AuditTrail.Helpers;
|
||||||
using Orchard.AuditTrail.Models;
|
using Orchard.AuditTrail.Models;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
|
using Orchard.Core.Contents.Settings;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
using Orchard.UI.Admin;
|
using Orchard.UI.Admin;
|
||||||
@@ -13,11 +15,13 @@ namespace Orchard.AuditTrail.Controllers {
|
|||||||
private readonly IAuthorizer _authorizer;
|
private readonly IAuthorizer _authorizer;
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
private readonly INotifier _notifier;
|
private readonly INotifier _notifier;
|
||||||
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
|
|
||||||
public ContentController(IAuthorizer authorizer, IContentManager contentManager, INotifier notifier) {
|
public ContentController(IAuthorizer authorizer, IContentManager contentManager, INotifier notifier, IContentDefinitionManager contentDefinitionManager) {
|
||||||
_authorizer = authorizer;
|
_authorizer = authorizer;
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
_notifier = notifier;
|
_notifier = notifier;
|
||||||
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,11 +48,11 @@ namespace Orchard.AuditTrail.Controllers {
|
|||||||
if (!_authorizer.Authorize(Core.Contents.Permissions.PublishContent, contentItem))
|
if (!_authorizer.Authorize(Core.Contents.Permissions.PublishContent, contentItem))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var title = _contentManager.GetItemMetadata(contentItem).DisplayText;
|
var contentType = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType);
|
||||||
var currentVersion = contentItem.Version;
|
var draftable = contentType.Settings.GetModel<ContentTypeSettings>().Draftable;
|
||||||
var newContentItem = _contentManager.Rollback(contentItem, VersionOptions.Rollback(version, publish: true));
|
_contentManager.Rollback(contentItem, VersionOptions.Rollback(version, publish: !draftable));
|
||||||
|
|
||||||
_notifier.Information(T("{0} has been rolled back from version {1} to version {2} as version {3}.", title, currentVersion, version, newContentItem.Version));
|
_notifier.Information(T("Version {0} has been restored.", version));
|
||||||
|
|
||||||
returnUrl = Url.IsLocalUrl(returnUrl)
|
returnUrl = Url.IsLocalUrl(returnUrl)
|
||||||
? returnUrl
|
? returnUrl
|
||||||
|
@@ -572,9 +572,6 @@ namespace Orchard.ContentManagement {
|
|||||||
// Get the latest version.
|
// Get the latest version.
|
||||||
var latestVersionRecord = contentItem.Record.Versions.Single(x => x.Latest);
|
var latestVersionRecord = contentItem.Record.Versions.Single(x => x.Latest);
|
||||||
|
|
||||||
// Unpublish the latest version.
|
|
||||||
latestVersionRecord.Published = false;
|
|
||||||
|
|
||||||
// Get the specified version.
|
// Get the specified version.
|
||||||
var specifiedVersionContentItem =
|
var specifiedVersionContentItem =
|
||||||
contentItem.VersionRecord.Number == options.VersionNumber || contentItem.VersionRecord.Id == options.VersionRecordId
|
contentItem.VersionRecord.Number == options.VersionNumber || contentItem.VersionRecord.Id == options.VersionRecordId
|
||||||
@@ -589,6 +586,9 @@ namespace Orchard.ContentManagement {
|
|||||||
Handlers.Invoke(handler => handler.RolledBack(new RollbackContentContext(rolledBackContentItem, options)), Logger);
|
Handlers.Invoke(handler => handler.RolledBack(new RollbackContentContext(rolledBackContentItem, options)), Logger);
|
||||||
|
|
||||||
if (options.IsPublished) {
|
if (options.IsPublished) {
|
||||||
|
// Unpublish the latest version.
|
||||||
|
latestVersionRecord.Published = false;
|
||||||
|
|
||||||
var publishContext = new PublishContentContext(rolledBackContentItem, previousItemVersionRecord: latestVersionRecord);
|
var publishContext = new PublishContentContext(rolledBackContentItem, previousItemVersionRecord: latestVersionRecord);
|
||||||
|
|
||||||
Handlers.Invoke(handler => handler.Publishing(publishContext), Logger);
|
Handlers.Invoke(handler => handler.Publishing(publishContext), Logger);
|
||||||
|
Reference in New Issue
Block a user