Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7412: Verified and added several Cloning overrides in many drivers #7592

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,9 @@ protected override void Importing(ContainablePart part, ImportContentContext con
protected override void Exporting(ContainablePart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Position", part.Position);
}

protected override void Cloning(ContainablePart originalPart, ContainablePart clonePart, CloneContentContext context) {
clonePart.Position = originalPart.Position;
}
}
}
12 changes: 12 additions & 0 deletions src/Orchard.Web/Core/Containers/Drivers/ContainerPartDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,17 @@ protected override void Exporting(ContainerPart part, ExportContentContext conte
context.Element(part.PartDefinition.Name).SetAttributeValue("AdminMenuImageSet", part.AdminMenuImageSet);
context.Element(part.PartDefinition.Name).SetAttributeValue("ItemCount", part.ItemCount);
}

protected override void Cloning(ContainerPart originalPart, ContainerPart clonePart, CloneContentContext context) {
clonePart.ItemContentTypes = originalPart.ItemContentTypes;
clonePart.ItemsShown = originalPart.ItemsShown;
clonePart.Paginated = originalPart.Paginated;
clonePart.PageSize = originalPart.PageSize;
clonePart.ShowOnAdminMenu = originalPart.ShowOnAdminMenu;
clonePart.AdminMenuText = originalPart.AdminMenuText;
clonePart.AdminMenuPosition = originalPart.AdminMenuPosition;
clonePart.AdminMenuImageSet = originalPart.AdminMenuImageSet;
clonePart.ItemCount = originalPart.ItemCount;
}
}
}
11 changes: 8 additions & 3 deletions src/Orchard.Web/Core/Contents/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private ActionResult EditPOST(int id, string returnUrl, Func<ContentItem, bool>
}

[HttpPost]
public ActionResult Clone(int id) {
public ActionResult Clone(int id, string returnUrl) {
var originalContentItem = _contentManager.GetLatest(id);

if (!Services.Authorizer.Authorize(Permissions.ViewContent, originalContentItem, T("You do not have permission to view existing content.")))
Expand All @@ -425,8 +425,13 @@ public ActionResult Clone(int id) {
? T("The content has been cloned as a draft.")
: T("The {0} has been cloned as a draft.", originalContentItem.TypeDefinition.DisplayName));

var adminRouteValues = _contentManager.GetItemMetadata(cloneContentItem).AdminRouteValues;
return RedirectToRoute(adminRouteValues);
if (string.IsNullOrWhiteSpace(returnUrl)) {
var adminRouteValues = _contentManager.GetItemMetadata(cloneContentItem).AdminRouteValues;
return RedirectToRoute(adminRouteValues);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After you merge from dev, please adjust Core/Contents/Views/Parts.Contents.Clone.SummaryAdmin.cshtml and Parts.Contents.Publish.SummaryAdmin.cshtml (line 29) not to include the ReturnUrl parameter.

}
else {
return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));
}
}

[HttpPost]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Navigation.Models;
using Orchard.Core.Navigation.Settings;
using Orchard.Localization;
Expand Down Expand Up @@ -94,5 +95,11 @@ protected override void Exporting(AdminMenuPart part, ContentManagement.Handlers
context.Element(part.PartDefinition.Name).SetAttributeValue("AdminMenuPosition", part.AdminMenuPosition);
context.Element(part.PartDefinition.Name).SetAttributeValue("OnAdminMenu", part.OnAdminMenu);
}

protected override void Cloning(AdminMenuPart originalPart, AdminMenuPart clonePart, CloneContentContext context) {
clonePart.AdminMenuText = originalPart.AdminMenuText;
clonePart.AdminMenuPosition = originalPart.AdminMenuPosition;
clonePart.OnAdminMenu = originalPart.OnAdminMenu;
}
}
}
5 changes: 5 additions & 0 deletions src/Orchard.Web/Core/Navigation/Drivers/MenuItemPartDriver.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Navigation.Models;
using Orchard.Security;

Expand Down Expand Up @@ -50,5 +51,9 @@ protected override void Importing(MenuItemPart part, ContentManagement.Handlers.
protected override void Exporting(MenuItemPart part, ContentManagement.Handlers.ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Url", part.Url);
}

protected override void Cloning(MenuItemPart originalPart, MenuItemPart clonePart, CloneContentContext context) {
clonePart.Url = originalPart.Url;
}
}
}
7 changes: 7 additions & 0 deletions src/Orchard.Web/Core/Navigation/Drivers/MenuPartDriver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Navigation.Models;
using Orchard.Core.Navigation.Services;
using Orchard.Core.Navigation.ViewModels;
Expand Down Expand Up @@ -114,5 +115,11 @@ protected override void Exporting(MenuPart part, ContentManagement.Handlers.Expo
context.Element(part.PartDefinition.Name).SetAttributeValue("MenuText", part.MenuText);
context.Element(part.PartDefinition.Name).SetAttributeValue("MenuPosition", part.MenuPosition);
}

protected override void Cloning(MenuPart originalPart, MenuPart clonePart, CloneContentContext context) {
clonePart.MenuText = originalPart.MenuText;
clonePart.MenuPosition = originalPart.MenuPosition;
clonePart.Menu = context.CloneContentItem;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.CloneContentItem causes the "Show on a menu" to always be checked incorrectly.

Suggested change
clonePart.Menu = context.CloneContentItem;
clonePart.Menu = originalPart.Menu;

}
}
}
10 changes: 10 additions & 0 deletions src/Orchard.Web/Core/Navigation/Drivers/MenuWidgetPartDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,15 @@ protected override void Exporting(MenuWidgetPart part, ExportContentContext cont
context.Element(part.PartDefinition.Name).SetAttributeValue("ShowFullMenu", part.ShowFullMenu);
}

protected override void Cloning(MenuWidgetPart originalPart, MenuWidgetPart clonePart, CloneContentContext context) {
clonePart.StartLevel = originalPart.StartLevel;
clonePart.Levels = originalPart.Levels;
clonePart.Breadcrumb = originalPart.Breadcrumb;
clonePart.AddCurrentPage = originalPart.AddCurrentPage;
clonePart.AddHomePage = originalPart.AddHomePage;
clonePart.ShowFullMenu = originalPart.ShowFullMenu;
clonePart.MenuContentItemId = originalPart.MenuContentItemId;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ protected override void Importing(ShapeMenuItemPart part, ImportContentContext c
protected override void Exporting(ShapeMenuItemPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("ShapeType", part.ShapeType);
}

protected override void Cloning(ShapeMenuItemPart originalPart, ShapeMenuItemPart clonePart, CloneContentContext context) {
clonePart.ShapeType = originalPart.ShapeType;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,10 @@ protected override void Importing(SpamFilterPart part, ImportContentContext cont
protected override void Exporting(SpamFilterPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Status", part.Status.ToString());
}

protected override void Cloning(SpamFilterPart originalPart, SpamFilterPart clonePart, CloneContentContext context) {
clonePart.Status = originalPart.Status;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,10 @@ protected override void Exporting(ArchiveLaterPart part, ExportContentContext co
.SetAttributeValue("ScheduledArchiveUtc", XmlConvert.ToString(scheduled.Value, XmlDateTimeSerializationMode.Utc));
}
}

protected override void Cloning(ArchiveLaterPart originalPart, ArchiveLaterPart clonePart, CloneContentContext context) {
clonePart.ScheduledArchiveUtc.Value = originalPart.ScheduledArchiveUtc.Value;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,11 @@ protected override void Exporting(AutoroutePart part, ExportContentContext conte
context.Element(part.PartDefinition.Name).SetAttributeValue("UseCulturePattern", part.Record.UseCulturePattern);
context.Element(part.PartDefinition.Name).SetAttributeValue("PromoteToHomePage", part.PromoteToHomePage);
}

protected override void Cloning(AutoroutePart originalPart, AutoroutePart clonePart, CloneContentContext context) {
clonePart.CustomPattern = originalPart.CustomPattern;
BenedekFarkas marked this conversation as resolved.
Show resolved Hide resolved
clonePart.UseCustomPattern = originalPart.UseCustomPattern;
clonePart.UseCulturePattern = originalPart.UseCulturePattern;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BlogArchivesPartDriver : ContentPartDriver<BlogArchivesPart> {
private readonly IContentManager _contentManager;

public BlogArchivesPartDriver(
IBlogService blogService,
IBlogService blogService,
IBlogPostService blogPostService,
IContentManager contentManager) {
_blogService = blogService;
Expand All @@ -37,7 +37,7 @@ protected override DriverResult Editor(BlogArchivesPart part, dynamic shapeHelpe
var viewModel = new BlogArchivesViewModel {
BlogId = part.BlogId,
Blogs = _blogService.Get().ToList().OrderBy(b => _contentManager.GetItemMetadata(b).DisplayText)
};
};

return ContentShape("Parts_Blogs_BlogArchives_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Blogs.BlogArchives", Model: viewModel, Prefix: Prefix));
Expand Down Expand Up @@ -69,5 +69,8 @@ protected override void Exporting(BlogArchivesPart part, ExportContentContext co
context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity);
}

protected override void Cloning(BlogArchivesPart originalPart, BlogArchivesPart clonePart, CloneContentContext context) {
clonePart.BlogId = originalPart.BlogId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Orchard.Blogs.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;

namespace Orchard.Blogs.Drivers {
public class BlogPartDriver : ContentPartDriver<BlogPart> {
Expand Down Expand Up @@ -66,5 +67,11 @@ protected override void Exporting(BlogPart part, ContentManagement.Handlers.Expo
context.Element(part.PartDefinition.Name).SetAttributeValue("PostCount", part.PostCount);
context.Element(part.PartDefinition.Name).SetAttributeValue("FeedProxyUrl", part.FeedProxyUrl);
}

protected override void Cloning(BlogPart originalPart, BlogPart clonePart, CloneContentContext context) {
clonePart.Description = originalPart.Description;
clonePart.PostCount = originalPart.PostCount;
clonePart.FeedProxyUrl = originalPart.FeedProxyUrl;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,10 @@ protected override void Exporting(RecentBlogPostsPart part, ExportContentContext
context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity);
context.Element(part.PartDefinition.Name).SetAttributeValue("Count", part.Count);
}

protected override void Cloning(RecentBlogPostsPart originalPart, RecentBlogPostsPart clonePart, CloneContentContext context) {
clonePart.BlogId = originalPart.BlogId;
clonePart.Count = originalPart.Count;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Orchard.Localization;
using Orchard.Comments.Services;
using Orchard.UI.Notify;
using Orchard.ContentManagement.Handlers;

namespace Orchard.Comments.Drivers {
public class CommentPartDriver : ContentPartDriver<CommentPart> {
Expand Down Expand Up @@ -227,5 +228,33 @@ protected override void Exporting(CommentPart part, ContentManagement.Handlers.E
}
}
}

protected override void Cloning(CommentPart originalPart, CommentPart clonePart, CloneContentContext context) {
clonePart.Author = originalPart.Author;
clonePart.SiteName = originalPart.SiteName;
clonePart.UserName = originalPart.UserName;
clonePart.Email = originalPart.Email;
clonePart.Position = originalPart.Position;
clonePart.Status = originalPart.Status;
clonePart.CommentDateUtc = originalPart.CommentDateUtc;
clonePart.CommentText = originalPart.CommentText;
var commentedOn = _contentManager.Get(originalPart.CommentedOn);
if (commentedOn != null) {
clonePart.CommentedOn = originalPart.CommentedOn;
}
if (originalPart.RepliedOn.HasValue) {
var repliedOn = _contentManager.Get(originalPart.RepliedOn.Value);
if (repliedOn != null) {
clonePart.RepliedOn = originalPart.RepliedOn;
}
}
else {
clonePart.RepliedOn = null;
}
var commentedOnContainer = _contentManager.Get(originalPart.CommentedOnContainer);
if (commentedOnContainer != null) {
clonePart.CommentedOnContainer = originalPart.CommentedOnContainer;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ protected override void Importing(ContentPermissionsPart part, ImportContentCont
context.ImportAttribute(part.PartDefinition.Name, "PreviewOwnContent", s => part.PreviewOwnContent = s);
}

protected override void Cloning(ContentPermissionsPart originalPart, ContentPermissionsPart clonePart, CloneContentContext context) {
clonePart.Enabled = originalPart.Enabled;
clonePart.ViewContent = originalPart.ViewContent;
clonePart.EditContent = originalPart.EditContent;
clonePart.PublishContent = originalPart.PublishContent;
clonePart.DeleteContent = originalPart.DeleteContent;
clonePart.PreviewContent = originalPart.PreviewContent;
clonePart.ViewOwnContent = originalPart.ViewOwnContent;
clonePart.EditOwnContent = originalPart.EditOwnContent;
clonePart.PublishOwnContent = originalPart.PublishOwnContent;
clonePart.DeleteOwnContent = originalPart.DeleteOwnContent;
clonePart.PreviewOwnContent = originalPart.PreviewOwnContent;
}

private void OverrideDefaultPermissions(ContentPermissionsPart part, List<string> allRoles, ContentPermissionsPartSettings settings) {
// reset permissions the user can't change
if (!_authorizer.Authorize(Core.Contents.Permissions.ViewContent, part.ContentItem)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,9 @@ protected override void Exporting(ContentMenuItemPart part, ExportContentContext
}
}
}

protected override void Cloning(ContentMenuItemPart originalPart, ContentMenuItemPart clonePart, CloneContentContext context) {
clonePart.Content = originalPart.Content;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected override void Importing(AudioPart part, ContentManagement.Handlers.Imp
part.Length = int.Parse(length)
);
}

protected override void Cloning(AudioPart originalPart, AudioPart clonePart, CloneContentContext context) {
clonePart.Length = originalPart.Length;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected override void Importing(DocumentPart part, ContentManagement.Handlers.
part.Length = int.Parse(length)
);
}

protected override void Cloning(DocumentPart originalPart, DocumentPart clonePart, CloneContentContext context) {
clonePart.Length = originalPart.Length;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ protected override void Exporting(MediaPart part, ContentManagement.Handlers.Exp
}

protected override void Cloning(MediaPart originalPart, MediaPart clonePart, CloneContentContext context) {
clonePart.MimeType = originalPart.MimeType;
clonePart.Caption = originalPart.Caption;
clonePart.FileName = originalPart.FileName;
clonePart.AlternateText = originalPart.AlternateText;
clonePart.FolderPath = originalPart.FolderPath;
clonePart.FileName = originalPart.FileName;
clonePart.LogicalType = originalPart.LogicalType;
clonePart.AlternateText = originalPart.AlternateText;
clonePart.MimeType = originalPart.MimeType;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ protected override void Cloning(OEmbedPart originalPart, OEmbedPart clonePart, C
cloneElement.Add(partCloneElement);
partCloneElement.Add(partOriginalElement.Elements());
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,12 @@ protected override void Importing(ImageProfilePart part, ImportContentContext co
part.Record.Filters.Add(result);
}
}

protected override void Cloning(ImageProfilePart originalPart, ImageProfilePart clonePart, CloneContentContext context) {
clonePart.Name = originalPart.Name;
clonePart.ModifiedUtc = originalPart.ModifiedUtc;
clonePart.Record.Filters = originalPart.Filters;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throws YSOD:

Don't change the reference to a collection with cascade="all-delete-orphan"

Filters are records (and thus references), so they should be cloned too.

clonePart.Record.FileNames = originalPart.FileNames;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to clone these? Shouldn't this start empty, since the new profile doesn't have any images generated?

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,14 @@ protected override void Exporting(NavigationQueryPart part, ExportContentContext
}
}
}

protected override void Cloning(NavigationQueryPart originalPart, NavigationQueryPart clonePart, CloneContentContext context) {
clonePart.Items = originalPart.Items;
clonePart.Skip = originalPart.Skip;
}

protected override void Cloned(NavigationQueryPart originalPart, NavigationQueryPart clonePart, CloneContentContext context) {
clonePart.QueryPartRecord = originalPart.QueryPartRecord;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why is this in Cloned and not Cloning?

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,11 @@ private PropertyRecord GetProperty(XElement property) {
ZeroIsEmpty = Convert.ToBoolean(property.Attribute("ZeroIsEmpty").Value),
};
}

protected override void Cloning(QueryPart originalPart, QueryPart clonePart, CloneContentContext context) {
clonePart.Record.SortCriteria = originalPart.SortCriteria;
clonePart.Record.FilterGroups = originalPart.FilterGroups;
clonePart.Record.Layouts = originalPart.Layouts;
Comment on lines +285 to +287
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also throws YSOD.

}
}
}
Loading