Skip to content

Commit

Permalink
Merge pull request #2944 from sbwalker/dev
Browse files Browse the repository at this point in the history
fix #2938 - path not updated correctly when parent page changed
  • Loading branch information
sbwalker authored Jun 28, 2023
2 parents ea4b85a + e1a8d3d commit 536af96
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
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

0 comments on commit 536af96

Please sign in to comment.