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