mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 03:14:10 +08:00
Factoring out content item cloning to ContentManager
--HG-- branch : 1.x
This commit is contained in:
@@ -331,7 +331,6 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Clone(int id, string returnUrl) {
|
||||
// Mostly taken from: http://orchard.codeplex.com/discussions/396664
|
||||
var contentItem = _contentManager.GetLatest(id);
|
||||
|
||||
if (contentItem == null)
|
||||
@@ -340,26 +339,14 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.EditContent, contentItem, T("Couldn't clone content")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var importContentSession = new ImportContentSession(_contentManager);
|
||||
|
||||
var element = _contentManager.Export(contentItem);
|
||||
|
||||
// if a handler prevents this element from being exported, it can't be cloned
|
||||
if (element == null) {
|
||||
try {
|
||||
Services.ContentManager.Clone(contentItem);
|
||||
}
|
||||
catch (InvalidOperationException) {
|
||||
Services.Notifier.Warning(T("Could not clone the content item."));
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));
|
||||
}
|
||||
|
||||
var elementId = element.Attribute("Id");
|
||||
var copyId = elementId.Value + "-copy";
|
||||
elementId.SetValue(copyId);
|
||||
var status = element.Attribute("Status");
|
||||
if (status != null) status.SetValue("Draft"); // So the copy is always a draft.
|
||||
|
||||
importContentSession.Set(copyId, element.Name.LocalName);
|
||||
|
||||
_contentManager.Import(element, importContentSession);
|
||||
|
||||
Services.Notifier.Information(T("Successfully cloned. The clone was saved as a draft."));
|
||||
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));
|
||||
|
Reference in New Issue
Block a user