Merge pull request #6022 from sbwalker/dev

improvements to ISynchronizable
This commit is contained in:
Shaun Walker
2026-02-11 08:59:27 -05:00
committed by GitHub
4 changed files with 59 additions and 65 deletions

View File

@@ -16,9 +16,8 @@ namespace Oqtane.Infrastructure
// JobType = "Oqtane.Infrastructure.SynchronizationJob, Oqtane.Server" // JobType = "Oqtane.Infrastructure.SynchronizationJob, Oqtane.Server"
// synchronization only supports sites in the same tenant (database) // synchronization only supports sites in the same tenant (database)
// module title is used as a key to identify module instances on a page (ie. using "-" as a module title is problematic ie. content as configuration) // module title is used as a key to identify module instances on a page
// relies on Module.ModifiedOn to be set if the module content changes (for efficiency) // modules must implement ISynchronizable interface
// modules must implement ISynchronizable interface (new interface as IPortable was generally only implemented in an additive manner)
// define settings that should not be synchronized (should be extensible in the future) // define settings that should not be synchronized (should be extensible in the future)
List<Setting> excludedSettings = new List<Setting>() { List<Setting> excludedSettings = new List<Setting>() {
@@ -580,8 +579,6 @@ namespace Oqtane.Infrastructure
secondaryPageModule.Module.AllPages = false; secondaryPageModule.Module.AllPages = false;
secondaryPageModule.Module.IsDeleted = false; secondaryPageModule.Module.IsDeleted = false;
var updateContent = false;
if (pageModule == null) if (pageModule == null)
{ {
// check if module exists // check if module exists
@@ -592,7 +589,6 @@ namespace Oqtane.Infrastructure
if (siteGroupMember.SiteGroup.Type == SiteGroupTypes.Synchronization) if (siteGroupMember.SiteGroup.Type == SiteGroupTypes.Synchronization)
{ {
module = moduleRepository.AddModule(secondaryPageModule.Module); module = moduleRepository.AddModule(secondaryPageModule.Module);
updateContent = true;
} }
log += Log(siteGroupMember, $"Module Added: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + "/" + secondaryPage.Path)}"); log += Log(siteGroupMember, $"Module Added: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + "/" + secondaryPage.Path)}");
} }
@@ -617,7 +613,6 @@ namespace Oqtane.Infrastructure
{ {
moduleRepository.UpdateModule(secondaryPageModule.Module); moduleRepository.UpdateModule(secondaryPageModule.Module);
} }
updateContent = true;
log += Log(siteGroupMember, $"Module Updated: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + "/" + secondaryPage.Path)}"); log += Log(siteGroupMember, $"Module Updated: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + "/" + secondaryPage.Path)}");
} }
if (primaryPageModule.ModifiedOn > siteGroupMember.SynchronizedOn) if (primaryPageModule.ModifiedOn > siteGroupMember.SynchronizedOn)
@@ -629,9 +624,10 @@ namespace Oqtane.Infrastructure
log += Log(siteGroupMember, $"Module Instance Updated: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + "/" + secondaryPage.Path)}"); log += Log(siteGroupMember, $"Module Instance Updated: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + "/" + secondaryPage.Path)}");
} }
} }
}
// module content // module content
if (updateContent && primaryPageModule.Module.ModuleDefinition.ServerManagerType != "") if (primaryPageModule.Module.ModuleDefinition.ServerManagerType != "")
{ {
Type moduleType = Type.GetType(primaryPageModule.Module.ModuleDefinition.ServerManagerType); Type moduleType = Type.GetType(primaryPageModule.Module.ModuleDefinition.ServerManagerType);
if (moduleType != null && moduleType.GetInterface(nameof(ISynchronizable)) != null) if (moduleType != null && moduleType.GetInterface(nameof(ISynchronizable)) != null)
@@ -639,13 +635,12 @@ namespace Oqtane.Infrastructure
try try
{ {
var moduleObject = ActivatorUtilities.CreateInstance(provider, moduleType); var moduleObject = ActivatorUtilities.CreateInstance(provider, moduleType);
var primaryModuleContent = ((ISynchronizable)moduleObject).ExtractModule(primaryPageModule.Module); var moduleContent = ((ISynchronizable)moduleObject).ExtractModule(primaryPageModule.Module, siteGroupMember.SynchronizedOn.Value);
var secondaryModuleContent = ((ISynchronizable)moduleObject).ExtractModule(secondaryPageModule.Module); if (!string.IsNullOrEmpty(moduleContent))
if (primaryModuleContent != secondaryModuleContent)
{ {
if (siteGroupMember.SiteGroup.Type == SiteGroupTypes.Synchronization) if (siteGroupMember.SiteGroup.Type == SiteGroupTypes.Synchronization)
{ {
((ISynchronizable)moduleObject).LoadModule(secondaryPageModule.Module, primaryModuleContent, primaryPageModule.Module.ModuleDefinition.Version); ((ISynchronizable)moduleObject).LoadModule(secondaryPageModule.Module, moduleContent);
} }
log += Log(siteGroupMember, $"Module Content Updated: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + "/" + secondaryPage.Path)}"); log += Log(siteGroupMember, $"Module Content Updated: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + "/" + secondaryPage.Path)}");
} }
@@ -656,7 +651,6 @@ namespace Oqtane.Infrastructure
} }
} }
} }
}
if (pageModule != null) if (pageModule != null)
{ {

View File

@@ -59,39 +59,50 @@ namespace Oqtane.Modules.HtmlText.Manager
// IPortable implementation // IPortable implementation
public string ExportModule(Module module) public string ExportModule(Module module)
{
return GetModuleContent(module);
}
public void ImportModule(Module module, string content, string version)
{
SaveModuleContent(module, content, version);
}
// ISynchronizable implementation
public string ExtractModule(Module module)
{
return GetModuleContent(module);
}
public void LoadModule(Module module, string content, string version)
{
SaveModuleContent(module, content, version);
}
private string GetModuleContent(Module module)
{ {
string content = ""; string content = "";
var htmltexts = _htmlText.GetHtmlTexts(module.ModuleId); var htmltext = GetModuleContent(module.ModuleId);
if (htmltexts != null && htmltexts.Any()) if (htmltext != null)
{ {
var htmltext = htmltexts.OrderByDescending(item => item.CreatedOn).First();
content = WebUtility.HtmlEncode(htmltext.Content); content = WebUtility.HtmlEncode(htmltext.Content);
} }
return content; return content;
} }
private void SaveModuleContent(Module module, string content, string version) public void ImportModule(Module module, string content, string version)
{
SaveModuleContent(module, content);
}
// ISynchronizable implementation
public string ExtractModule(Module module, DateTime lastSynchronizedOn)
{
string content = "";
var htmltext = GetModuleContent(module.ModuleId);
if (htmltext != null && htmltext.CreatedOn > lastSynchronizedOn)
{
content = WebUtility.HtmlEncode(htmltext.Content);
}
return content;
}
public void LoadModule(Module module, string content)
{
SaveModuleContent(module, content);
}
private Models.HtmlText GetModuleContent(int moduleId)
{
// get the most recent htmltext record for the module
var htmltexts = _htmlText.GetHtmlTexts(moduleId);
if (htmltexts != null && htmltexts.Any())
{
return htmltexts.OrderByDescending(item => item.CreatedOn).First();
}
return null;
}
private void SaveModuleContent(Module module, string content)
{ {
content = WebUtility.HtmlDecode(content); content = WebUtility.HtmlDecode(content);
var htmlText = new Models.HtmlText(); var htmlText = new Models.HtmlText();

View File

@@ -2,7 +2,6 @@ using System.Linq;
using Oqtane.Documentation; using Oqtane.Documentation;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Oqtane.Repository;
namespace Oqtane.Modules.HtmlText.Repository namespace Oqtane.Modules.HtmlText.Repository
{ {
@@ -19,12 +18,10 @@ namespace Oqtane.Modules.HtmlText.Repository
public class HtmlTextRepository : IHtmlTextRepository, ITransientService public class HtmlTextRepository : IHtmlTextRepository, ITransientService
{ {
private readonly IDbContextFactory<HtmlTextContext> _factory; private readonly IDbContextFactory<HtmlTextContext> _factory;
private readonly IModuleRepository _moduleRepository;
public HtmlTextRepository(IDbContextFactory<HtmlTextContext> factory, IModuleRepository moduleRepository) public HtmlTextRepository(IDbContextFactory<HtmlTextContext> factory)
{ {
_factory = factory; _factory = factory;
_moduleRepository = moduleRepository;
} }
public IEnumerable<Models.HtmlText> GetHtmlTexts(int moduleId) public IEnumerable<Models.HtmlText> GetHtmlTexts(int moduleId)
@@ -44,11 +41,6 @@ namespace Oqtane.Modules.HtmlText.Repository
using var db = _factory.CreateDbContext(); using var db = _factory.CreateDbContext();
db.HtmlText.Add(htmlText); db.HtmlText.Add(htmlText);
db.SaveChanges(); db.SaveChanges();
// update module ModifiedOn date
var module = _moduleRepository.GetModule(htmlText.ModuleId);
_moduleRepository.UpdateModule(module);
return htmlText; return htmlText;
} }
@@ -60,10 +52,6 @@ namespace Oqtane.Modules.HtmlText.Repository
{ {
db.HtmlText.Remove(htmlText); db.HtmlText.Remove(htmlText);
db.SaveChanges(); db.SaveChanges();
// update module ModifiedOn date
var module = _moduleRepository.GetModule(htmlText.ModuleId);
_moduleRepository.UpdateModule(module);
} }
} }
} }

View File

@@ -1,3 +1,4 @@
using System;
using Oqtane.Models; using Oqtane.Models;
namespace Oqtane.Modules namespace Oqtane.Modules
@@ -6,8 +7,8 @@ namespace Oqtane.Modules
{ {
// You Must Set The "ServerManagerType" In Your IModule Interface // You Must Set The "ServerManagerType" In Your IModule Interface
string ExtractModule(Module module); string ExtractModule(Module module, DateTime lastSynchronizedOn);
void LoadModule(Module module, string content, string version); void LoadModule(Module module, string content);
} }
} }