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

Copied child pages don't show up in the pages overview #1964

Closed
hadrian625 opened this issue Nov 25, 2022 · 0 comments
Closed

Copied child pages don't show up in the pages overview #1964

hadrian625 opened this issue Nov 25, 2022 · 0 comments
Assignees
Milestone

Comments

@hadrian625
Copy link

hadrian625 commented Nov 25, 2022

Steps to reproduce

  1. Create in 'Site A' a page 'ParentPage' with child page 'ChildPage 1'
  2. Create 'Site B'
  3. Add a page for 'Site B' by copying 'ChildPage 1'
  4. Copy page for 'ChildPage 1' is creaed with success but it does not show up in the page overview page listing

Expected result
The copied page shows up in page overview

Proposed solution
In Piranha.Core, Piranha.Services.PageService, method CopyAsync, the returned model should have its ParentId property set to null.
Otherwise this ParentId remains set to a page in the source site, which might not exist in the destination site (if the destination site is different then the source site) -> this causes the page to not show up in the page overview
An extra improvement to this proposed fix is to make it in Piranha.Manager.PageService, in methods Copy and CopyRelative
In method Copy just check if the original.SiteId is the same as parameter siteId
Proposed code fix
`
public async Task Copy(Guid sourceId, Guid siteId)
{
var original = await _api.Pages.GetByIdAsync(sourceId);

    if (original != null)
    {
        var page = await _api.Pages.CopyAsync(original);
        page.SiteId = siteId;
        page.SortOrder = (await _api.Sites.GetSitemapAsync(page.SiteId, false)).Count;
        if (original.SiteId != siteId)
        {
            page.ParentId = null;
        }
        // Perform manager init
        await _factory.InitDynamicManagerAsync(page,
            App.PageTypes.GetById(page.TypeId));

        return Transform(page, false);
    }
    return null;
}
public async Task<PageEditModel> CopyRelative(Guid sourceId, Guid pageId, bool after)
{
    var relative = await _api.Pages.GetByIdAsync<PageInfo>(pageId);
    if (relative != null)
    {
        var original = await _api.Pages.GetByIdAsync(sourceId);
        if (original != null)
        {
            var page = await _api.Pages.CopyAsync(original);
            page.SiteId = relative.SiteId;
            page.ParentId = after ? relative.ParentId : relative.Id;
            page.SortOrder = after ? relative.SortOrder + 1 : 0;
            if (original.SiteId != siteId)
            {
                page.ParentId = null;
            }
            // Perform manager init
            await _factory.InitDynamicManagerAsync(page,
                App.PageTypes.GetById(page.TypeId));
            return Transform(page, false);
        }
    }
    return null;
}`
@tidyui tidyui added this to the Version 10.3 milestone Dec 9, 2022
@tidyui tidyui modified the milestones: Version 10.3, Version 10.4 Jan 19, 2023
@tidyui tidyui closed this as completed in 657c092 Jun 6, 2023
@tidyui tidyui self-assigned this Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants