Merge pull request #6022 from sbwalker/dev
improvements to ISynchronizable
This commit is contained in:
@@ -16,9 +16,8 @@ namespace Oqtane.Infrastructure
|
||||
// JobType = "Oqtane.Infrastructure.SynchronizationJob, Oqtane.Server"
|
||||
|
||||
// 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)
|
||||
// relies on Module.ModifiedOn to be set if the module content changes (for efficiency)
|
||||
// modules must implement ISynchronizable interface (new interface as IPortable was generally only implemented in an additive manner)
|
||||
// module title is used as a key to identify module instances on a page
|
||||
// modules must implement ISynchronizable interface
|
||||
|
||||
// define settings that should not be synchronized (should be extensible in the future)
|
||||
List<Setting> excludedSettings = new List<Setting>() {
|
||||
@@ -580,8 +579,6 @@ namespace Oqtane.Infrastructure
|
||||
secondaryPageModule.Module.AllPages = false;
|
||||
secondaryPageModule.Module.IsDeleted = false;
|
||||
|
||||
var updateContent = false;
|
||||
|
||||
if (pageModule == null)
|
||||
{
|
||||
// check if module exists
|
||||
@@ -592,7 +589,6 @@ namespace Oqtane.Infrastructure
|
||||
if (siteGroupMember.SiteGroup.Type == SiteGroupTypes.Synchronization)
|
||||
{
|
||||
module = moduleRepository.AddModule(secondaryPageModule.Module);
|
||||
updateContent = true;
|
||||
}
|
||||
log += Log(siteGroupMember, $"Module Added: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + "/" + secondaryPage.Path)}");
|
||||
}
|
||||
@@ -617,7 +613,6 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
moduleRepository.UpdateModule(secondaryPageModule.Module);
|
||||
}
|
||||
updateContent = true;
|
||||
log += Log(siteGroupMember, $"Module Updated: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + "/" + secondaryPage.Path)}");
|
||||
}
|
||||
if (primaryPageModule.ModifiedOn > siteGroupMember.SynchronizedOn)
|
||||
@@ -629,31 +624,30 @@ namespace Oqtane.Infrastructure
|
||||
log += Log(siteGroupMember, $"Module Instance Updated: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + "/" + secondaryPage.Path)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// module content
|
||||
if (updateContent && primaryPageModule.Module.ModuleDefinition.ServerManagerType != "")
|
||||
// module content
|
||||
if (primaryPageModule.Module.ModuleDefinition.ServerManagerType != "")
|
||||
{
|
||||
Type moduleType = Type.GetType(primaryPageModule.Module.ModuleDefinition.ServerManagerType);
|
||||
if (moduleType != null && moduleType.GetInterface(nameof(ISynchronizable)) != null)
|
||||
{
|
||||
Type moduleType = Type.GetType(primaryPageModule.Module.ModuleDefinition.ServerManagerType);
|
||||
if (moduleType != null && moduleType.GetInterface(nameof(ISynchronizable)) != null)
|
||||
try
|
||||
{
|
||||
try
|
||||
var moduleObject = ActivatorUtilities.CreateInstance(provider, moduleType);
|
||||
var moduleContent = ((ISynchronizable)moduleObject).ExtractModule(primaryPageModule.Module, siteGroupMember.SynchronizedOn.Value);
|
||||
if (!string.IsNullOrEmpty(moduleContent))
|
||||
{
|
||||
var moduleObject = ActivatorUtilities.CreateInstance(provider, moduleType);
|
||||
var primaryModuleContent = ((ISynchronizable)moduleObject).ExtractModule(primaryPageModule.Module);
|
||||
var secondaryModuleContent = ((ISynchronizable)moduleObject).ExtractModule(secondaryPageModule.Module);
|
||||
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);
|
||||
}
|
||||
log += Log(siteGroupMember, $"Module Content Updated: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + "/" + secondaryPage.Path)}");
|
||||
((ISynchronizable)moduleObject).LoadModule(secondaryPageModule.Module, moduleContent);
|
||||
}
|
||||
log += Log(siteGroupMember, $"Module Content Updated: {secondaryPageModule.Title} - {CreateLink(siteGroupMember.AliasName + "/" + secondaryPage.Path)}");
|
||||
}
|
||||
catch
|
||||
{
|
||||
// error exporting/importing
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// error exporting/importing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,39 +59,50 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||
|
||||
// IPortable implementation
|
||||
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 = "";
|
||||
var htmltexts = _htmlText.GetHtmlTexts(module.ModuleId);
|
||||
if (htmltexts != null && htmltexts.Any())
|
||||
var htmltext = GetModuleContent(module.ModuleId);
|
||||
if (htmltext != null)
|
||||
{
|
||||
var htmltext = htmltexts.OrderByDescending(item => item.CreatedOn).First();
|
||||
content = WebUtility.HtmlEncode(htmltext.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);
|
||||
var htmlText = new Models.HtmlText();
|
||||
|
||||
@@ -2,7 +2,6 @@ using System.Linq;
|
||||
using Oqtane.Documentation;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Modules.HtmlText.Repository
|
||||
{
|
||||
@@ -19,12 +18,10 @@ namespace Oqtane.Modules.HtmlText.Repository
|
||||
public class HtmlTextRepository : IHtmlTextRepository, ITransientService
|
||||
{
|
||||
private readonly IDbContextFactory<HtmlTextContext> _factory;
|
||||
private readonly IModuleRepository _moduleRepository;
|
||||
|
||||
public HtmlTextRepository(IDbContextFactory<HtmlTextContext> factory, IModuleRepository moduleRepository)
|
||||
public HtmlTextRepository(IDbContextFactory<HtmlTextContext> factory)
|
||||
{
|
||||
_factory = factory;
|
||||
_moduleRepository = moduleRepository;
|
||||
}
|
||||
|
||||
public IEnumerable<Models.HtmlText> GetHtmlTexts(int moduleId)
|
||||
@@ -44,11 +41,6 @@ namespace Oqtane.Modules.HtmlText.Repository
|
||||
using var db = _factory.CreateDbContext();
|
||||
db.HtmlText.Add(htmlText);
|
||||
db.SaveChanges();
|
||||
|
||||
// update module ModifiedOn date
|
||||
var module = _moduleRepository.GetModule(htmlText.ModuleId);
|
||||
_moduleRepository.UpdateModule(module);
|
||||
|
||||
return htmlText;
|
||||
}
|
||||
|
||||
@@ -60,10 +52,6 @@ namespace Oqtane.Modules.HtmlText.Repository
|
||||
{
|
||||
db.HtmlText.Remove(htmlText);
|
||||
db.SaveChanges();
|
||||
|
||||
// update module ModifiedOn date
|
||||
var module = _moduleRepository.GetModule(htmlText.ModuleId);
|
||||
_moduleRepository.UpdateModule(module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Modules
|
||||
@@ -6,8 +7,8 @@ namespace Oqtane.Modules
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user