From e1a8d3db548adf6e4dc06ca1bba235d403d7b09e Mon Sep 17 00:00:00 2001 From: sbwalker Date: Wed, 28 Jun 2023 12:17:27 -0400 Subject: [PATCH] fix #2938 - path not updated correctly when parent page changed --- Oqtane.Client/Modules/Admin/Pages/Edit.razor | 10 ------ Oqtane.Server/Controllers/PageController.cs | 32 +++++++++++++++----- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/Pages/Edit.razor b/Oqtane.Client/Modules/Admin/Pages/Edit.razor index f77c39706..50aebf5d1 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Edit.razor @@ -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(); diff --git a/Oqtane.Server/Controllers/PageController.cs b/Oqtane.Server/Controllers/PageController.cs index ce81eec29..c35013454 100644 --- a/Oqtane.Server/Controllers/PageController.cs +++ b/Oqtane.Server/Controllers/PageController.cs @@ -12,6 +12,8 @@ using Oqtane.Repository; using Oqtane.Modules.Admin.Users; using System.IO; +using Oqtane.Services; +using Oqtane.UI; namespace Oqtane.Controllers { @@ -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 @@ -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);