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

fix #2938 - path not updated correctly when parent page changed #2944

Merged
merged 1 commit into from
Jun 28, 2023
Merged
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
10 changes: 0 additions & 10 deletions Oqtane.Client/Modules/Admin/Pages/Edit.razor
Original file line number Diff line number Diff line change
Expand Up @@ -603,16 +603,6 @@
await PageService.UpdatePageOrderAsync(_page.SiteId, _page.PageId, int.Parse(_currentparentid));
}

// update child paths
if (_parentid != _currentparentid)
{
foreach (Page p in PageState.Pages.Where(item => item.Path.StartsWith(currentPath)))
{
p.Path = p.Path.Replace(currentPath, _page.Path);
await PageService.UpdatePageAsync(p);
}
}

if (_themeSettingsType != null && _themeSettings is ISettingsControl themeSettingsControl)
{
await themeSettingsControl.UpdateSettings();
Expand Down
32 changes: 24 additions & 8 deletions Oqtane.Server/Controllers/PageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Oqtane.Repository;
using Oqtane.Modules.Admin.Users;
using System.IO;
using Oqtane.Services;
using Oqtane.UI;

namespace Oqtane.Controllers
{
Expand Down Expand Up @@ -263,14 +265,18 @@ public Page Put(int id, [FromBody] Page page)
// save url mapping if page path changed
if (currentPage.Path != page.Path)
{
var urlMapping = new UrlMapping();
urlMapping.SiteId = page.SiteId;
urlMapping.Url = currentPage.Path;
urlMapping.MappedUrl = page.Path;
urlMapping.Requests = 0;
urlMapping.CreatedOn = System.DateTime.UtcNow;
urlMapping.RequestedOn = System.DateTime.UtcNow;
_urlMappings.AddUrlMapping(urlMapping);
var urlMapping = _urlMappings.GetUrlMapping(page.SiteId, currentPage.Path);
if (urlMapping == null)
{
urlMapping = new UrlMapping();
urlMapping.SiteId = page.SiteId;
urlMapping.Url = currentPage.Path;
urlMapping.MappedUrl = page.Path;
urlMapping.Requests = 0;
urlMapping.CreatedOn = System.DateTime.UtcNow;
urlMapping.RequestedOn = System.DateTime.UtcNow;
_urlMappings.AddUrlMapping(urlMapping);
}
}

// get differences between current and new page permissions
Expand Down Expand Up @@ -314,6 +320,16 @@ public Page Put(int id, [FromBody] Page page)
}
}

// update child paths
if (page.ParentId != currentPage.ParentId)
{
foreach (Page _page in _pages.GetPages(page.SiteId).Where(item => item.Path.StartsWith(currentPage.Path)).ToList())
{
_page.Path = _page.Path.Replace(currentPage.Path, page.Path);
_pages.UpdatePage(_page);
}
}

_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Page, page.PageId, SyncEventActions.Update);
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, page.SiteId, SyncEventActions.Refresh);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Updated {Page}", page);
Expand Down