mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
#17554: Placing content items transactions within transaction scopes.
--HG-- branch : 1.x
This commit is contained in:
@@ -126,44 +126,52 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
[HttpPost, ActionName("List")]
|
||||
[FormValueRequired("submit.BulkEdit")]
|
||||
public ActionResult ListPOST(ContentOptions options, IEnumerable<int> itemIds, string returnUrl) {
|
||||
if (itemIds != null) {
|
||||
switch (options.BulkAction) {
|
||||
case ContentsBulkAction.None:
|
||||
break;
|
||||
case ContentsBulkAction.PublishNow:
|
||||
foreach (var item in itemIds.Select(itemId => _contentManager.GetLatest(itemId))) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.PublishContent, item, T("Couldn't publish selected content.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
try {
|
||||
if (itemIds != null) {
|
||||
switch (options.BulkAction) {
|
||||
case ContentsBulkAction.None:
|
||||
break;
|
||||
case ContentsBulkAction.PublishNow:
|
||||
foreach (var item in itemIds.Select(itemId => _contentManager.GetLatest(itemId))) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.PublishContent, item, T("Couldn't publish selected content."))) {
|
||||
_transactionManager.Cancel();
|
||||
return new HttpUnauthorizedResult();
|
||||
}
|
||||
|
||||
_contentManager.Publish(item);
|
||||
Services.ContentManager.Flush();
|
||||
}
|
||||
Services.Notifier.Information(T("Content successfully published."));
|
||||
break;
|
||||
case ContentsBulkAction.Unpublish:
|
||||
foreach (var item in itemIds.Select(itemId => _contentManager.GetLatest(itemId))) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.PublishContent, item, T("Couldn't unpublish selected content.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_contentManager.Publish(item);
|
||||
}
|
||||
Services.Notifier.Information(T("Content successfully published."));
|
||||
break;
|
||||
case ContentsBulkAction.Unpublish:
|
||||
foreach (var item in itemIds.Select(itemId => _contentManager.GetLatest(itemId))) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.PublishContent, item, T("Couldn't unpublish selected content."))) {
|
||||
_transactionManager.Cancel();
|
||||
return new HttpUnauthorizedResult();
|
||||
}
|
||||
|
||||
_contentManager.Unpublish(item);
|
||||
Services.ContentManager.Flush();
|
||||
}
|
||||
Services.Notifier.Information(T("Content successfully unpublished."));
|
||||
break;
|
||||
case ContentsBulkAction.Remove:
|
||||
foreach (var item in itemIds.Select(itemId => _contentManager.GetLatest(itemId))) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.DeleteContent, item, T("Couldn't remove selected content.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_contentManager.Unpublish(item);
|
||||
}
|
||||
Services.Notifier.Information(T("Content successfully unpublished."));
|
||||
break;
|
||||
case ContentsBulkAction.Remove:
|
||||
foreach (var item in itemIds.Select(itemId => _contentManager.GetLatest(itemId))) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.DeleteContent, item, T("Couldn't remove selected content."))) {
|
||||
_transactionManager.Cancel();
|
||||
return new HttpUnauthorizedResult();
|
||||
}
|
||||
|
||||
_contentManager.Remove(item);
|
||||
Services.ContentManager.Flush();
|
||||
}
|
||||
Services.Notifier.Information(T("Content successfully removed."));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
_contentManager.Remove(item);
|
||||
}
|
||||
Services.Notifier.Information(T("Content successfully removed."));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
_transactionManager.Cancel();
|
||||
}
|
||||
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user