Merge remote-tracking branch 'oqtane/dev' into dev
This commit is contained in:
commit
55cfbb721b
|
@ -52,7 +52,13 @@
|
|||
<input id="sitemap" class="form-control" @bind="@_sitemap" required disabled />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="version" HelpText="The site version (for site content migrations)" ResourceKey="Version">Version: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input id="version" class="form-control" @bind="@_version" required disabled />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<Section Name="Appearance" ResourceKey="Appearance">
|
||||
<div class="container">
|
||||
|
@ -345,6 +351,7 @@
|
|||
private string _homepageid = "-";
|
||||
private string _isdeleted;
|
||||
private string _sitemap = "";
|
||||
private string _version = "";
|
||||
private int _logofileid = -1;
|
||||
private FileManager _logofilemanager;
|
||||
private int _faviconfileid = -1;
|
||||
|
@ -402,6 +409,7 @@
|
|||
}
|
||||
_isdeleted = site.IsDeleted.ToString();
|
||||
_sitemap = PageState.Alias.Protocol + PageState.Alias.Name + "/pages/sitemap.xml";
|
||||
_version = site.Version;
|
||||
|
||||
// appearance
|
||||
if (site.LogoFileId != null)
|
||||
|
|
|
@ -375,4 +375,10 @@
|
|||
<data name="SMTPEnabled.Text" xml:space="preserve">
|
||||
<value>Enabled?</value>
|
||||
</data>
|
||||
<data name="Version.HelpText" xml:space="preserve">
|
||||
<value>The site version (for site content migrations)</value>
|
||||
</data>
|
||||
<data name="Version.Text" xml:space="preserve">
|
||||
<value>Version:</value>
|
||||
</data>
|
||||
</root>
|
|
@ -199,10 +199,6 @@ namespace Oqtane.Infrastructure
|
|||
if (result.Success)
|
||||
{
|
||||
result = CreateSite(install);
|
||||
if (result.Success)
|
||||
{
|
||||
result = MigrateSites();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -685,77 +681,6 @@ namespace Oqtane.Infrastructure
|
|||
return result;
|
||||
}
|
||||
|
||||
private Installation MigrateSites()
|
||||
{
|
||||
var result = new Installation { Success = false, Message = string.Empty };
|
||||
|
||||
// get site upgrades
|
||||
Dictionary<string, Type> siteupgrades = new Dictionary<string, Type>();
|
||||
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
|
||||
foreach (Assembly assembly in assemblies)
|
||||
{
|
||||
foreach (var type in assembly.GetTypes(typeof(ISiteMigration)))
|
||||
{
|
||||
if (Attribute.IsDefined(type, typeof(SiteMigrationAttribute)))
|
||||
{
|
||||
var attribute = (SiteMigrationAttribute)Attribute.GetCustomAttribute(type, typeof(SiteMigrationAttribute));
|
||||
siteupgrades.Add(attribute.AliasName + " " + attribute.Version, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// execute site upgrades
|
||||
if (siteupgrades.Count > 0)
|
||||
{
|
||||
using (var scope = _serviceScopeFactory.CreateScope())
|
||||
{
|
||||
var aliases = scope.ServiceProvider.GetRequiredService<IAliasRepository>();
|
||||
var tenantManager = scope.ServiceProvider.GetRequiredService<ITenantManager>();
|
||||
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
|
||||
var logger = scope.ServiceProvider.GetRequiredService<ILogManager>();
|
||||
|
||||
foreach (var alias in aliases.GetAliases().ToList().Where(item => item.IsDefault))
|
||||
{
|
||||
foreach (var upgrade in siteupgrades)
|
||||
{
|
||||
var aliasname = upgrade.Key.Split(' ').First();
|
||||
// in the future this equality condition could use RegEx to allow for more flexible matching
|
||||
if (string.Equals(alias.Name, aliasname, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
tenantManager.SetTenant(alias.TenantId);
|
||||
var site = sites.GetSites().FirstOrDefault(item => item.SiteId == alias.SiteId);
|
||||
if (site != null)
|
||||
{
|
||||
var version = upgrade.Key.Split(' ').Last();
|
||||
if (string.IsNullOrEmpty(site.Version) || Version.Parse(version) > Version.Parse(site.Version))
|
||||
{
|
||||
try
|
||||
{
|
||||
var obj = ActivatorUtilities.CreateInstance(scope.ServiceProvider, upgrade.Value) as ISiteMigration;
|
||||
if (obj != null)
|
||||
{
|
||||
obj.Up(site, alias);
|
||||
site.Version = version;
|
||||
sites.UpdateSite(site);
|
||||
logger.Log(alias.SiteId, Shared.LogLevel.Information, "Site Migration", LogFunction.Other, "Site Migrated Successfully To Version {version} For {Alias}", version, alias.Name);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Log(alias.SiteId, Shared.LogLevel.Error, "Site Migration", LogFunction.Other, ex, "An Error Occurred Executing Site Migration {Type} For {Alias} And Version {Version}", upgrade.Value, alias.Name, version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.Success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
private string DenormalizeConnectionString(string connectionString)
|
||||
{
|
||||
var dataDirectory = AppDomain.CurrentDomain.GetData(Constants.DataDirectory)?.ToString();
|
||||
|
|
|
@ -8,5 +8,6 @@ namespace Oqtane.Infrastructure
|
|||
public int SiteId { get; set; }
|
||||
public List<string> Assemblies { get; set; } = new List<string>();
|
||||
public List<Resource>Scripts { get; set; } = new List<Resource>();
|
||||
public bool IsMigrated { get; set; } = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ namespace Oqtane.Infrastructure
|
|||
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
|
||||
foreach (Site site in sites.GetSites().ToList())
|
||||
{
|
||||
sites.CreatePages(site, pageTemplates);
|
||||
sites.CreatePages(site, pageTemplates, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ namespace Oqtane.Infrastructure
|
|||
{
|
||||
if (!pages.GetPages(site.SiteId).ToList().Where(item => item.Path == "404").Any())
|
||||
{
|
||||
sites.CreatePages(site, pageTemplates);
|
||||
sites.CreatePages(site, pageTemplates, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ namespace Oqtane.Pages
|
|||
}
|
||||
}
|
||||
|
||||
var site = _sites.GetSite(alias.SiteId);
|
||||
var site = _sites.InitializeSite(alias);
|
||||
if (site != null && !site.IsDeleted && site.Runtime != "Hybrid")
|
||||
{
|
||||
Route route = new Route(url, alias.Path);
|
||||
|
@ -174,7 +174,6 @@ namespace Oqtane.Pages
|
|||
}
|
||||
HeadResources += ParseScripts(site.HeadContent);
|
||||
BodyResources += ParseScripts(site.BodyContent);
|
||||
_sites.InitializeSite(site.SiteId); // populates server state
|
||||
var scripts = _serverState.GetServerState(site.SiteId).Scripts;
|
||||
foreach (var script in scripts)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Oqtane.Repository
|
|||
Site GetSite(int siteId);
|
||||
Site GetSite(int siteId, bool tracking);
|
||||
void DeleteSite(int siteId);
|
||||
void InitializeSite(int siteId);
|
||||
void CreatePages(Site site, List<PageTemplate> pageTemplates);
|
||||
Site InitializeSite(Alias alias);
|
||||
void CreatePages(Site site, List<PageTemplate> pageTemplates, Alias alias);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ using Oqtane.Infrastructure;
|
|||
using Oqtane.Models;
|
||||
using Oqtane.Modules;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.Themes;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
{
|
||||
|
@ -115,7 +114,7 @@ namespace Oqtane.Repository
|
|||
{
|
||||
moduleDefinitions = _cache.GetOrCreate($"moduledefinitions:{_tenants.GetAlias().SiteKey}", entry =>
|
||||
{
|
||||
entry.SlidingExpiration = TimeSpan.FromMinutes(30);
|
||||
entry.Priority = CacheItemPriority.NeverRemove;
|
||||
return ProcessModuleDefinitions(siteId);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Oqtane.Extensions;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Modules;
|
||||
|
@ -27,10 +27,13 @@ namespace Oqtane.Repository
|
|||
private readonly IThemeRepository _themeRepository;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IConfigurationRoot _config;
|
||||
private readonly ServerStateManager _serverState;
|
||||
private readonly ILogManager _logger;
|
||||
private static readonly object _lock = new object();
|
||||
|
||||
public SiteRepository(TenantDBContext context, IRoleRepository roleRepository, IProfileRepository profileRepository, IFolderRepository folderRepository, IPageRepository pageRepository,
|
||||
IModuleRepository moduleRepository, IPageModuleRepository pageModuleRepository, IModuleDefinitionRepository moduleDefinitionRepository, IThemeRepository themeRepository, IServiceProvider serviceProvider,
|
||||
IConfigurationRoot config)
|
||||
IConfigurationRoot config, ServerStateManager serverState, ILogManager logger)
|
||||
{
|
||||
_db = context;
|
||||
_roleRepository = roleRepository;
|
||||
|
@ -43,6 +46,8 @@ namespace Oqtane.Repository
|
|||
_themeRepository = themeRepository;
|
||||
_serviceProvider = serviceProvider;
|
||||
_config = config;
|
||||
_serverState = serverState;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IEnumerable<Site> GetSites()
|
||||
|
@ -90,10 +95,112 @@ namespace Oqtane.Repository
|
|||
_db.SaveChanges();
|
||||
}
|
||||
|
||||
public void InitializeSite(int siteId)
|
||||
public Site InitializeSite(Alias alias)
|
||||
{
|
||||
_moduleDefinitionRepository.GetModuleDefinitions(siteId);
|
||||
var site = GetSite(alias.SiteId);
|
||||
|
||||
_themeRepository.GetThemes();
|
||||
var moduleDefinitions = _moduleDefinitionRepository.GetModuleDefinitions(alias.SiteId);
|
||||
|
||||
// site migrations
|
||||
var serverstate = _serverState.GetServerState(alias.SiteId);
|
||||
if (!serverstate.IsMigrated)
|
||||
{
|
||||
// ensure migrations are only executed once
|
||||
lock (_lock)
|
||||
{
|
||||
if (!serverstate.IsMigrated)
|
||||
{
|
||||
var version = ProcessSiteMigrations(alias, site);
|
||||
version = ProcessPageTemplates(alias, site, moduleDefinitions, version);
|
||||
if (site.Version != version)
|
||||
{
|
||||
site.Version = version;
|
||||
UpdateSite(site);
|
||||
}
|
||||
serverstate.IsMigrated = true;
|
||||
_serverState.SetServerState(alias.SiteId, serverstate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return site;
|
||||
}
|
||||
|
||||
private string ProcessSiteMigrations(Alias alias, Site site)
|
||||
{
|
||||
var version = site.Version;
|
||||
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
|
||||
foreach (Assembly assembly in assemblies)
|
||||
{
|
||||
foreach (var type in assembly.GetTypes(typeof(ISiteMigration)))
|
||||
{
|
||||
if (Attribute.IsDefined(type, typeof(SiteMigrationAttribute)))
|
||||
{
|
||||
var attribute = (SiteMigrationAttribute)Attribute.GetCustomAttribute(type, typeof(SiteMigrationAttribute));
|
||||
if (attribute.AliasName == "*" || attribute.AliasName == alias.Name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(site.Version) || Version.Parse(attribute.Version) > Version.Parse(site.Version))
|
||||
{
|
||||
try
|
||||
{
|
||||
var obj = ActivatorUtilities.CreateInstance(_serviceProvider, type) as ISiteMigration;
|
||||
if (obj != null)
|
||||
{
|
||||
obj.Up(site, alias);
|
||||
_logger.Log(LogLevel.Information, "Site Migration", LogFunction.Other, "Site Migrated Successfully To Version {version} For {Alias}", version, alias.Name);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Log(LogLevel.Error, "Site Migration", LogFunction.Other, ex, "An Error Occurred Executing Site Migration {Type} For {Alias} And Version {Version}", type, alias.Name, version);
|
||||
}
|
||||
if (string.IsNullOrEmpty(version) || Version.Parse(attribute.Version) > Version.Parse(version))
|
||||
{
|
||||
version = attribute.Version;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
private string ProcessPageTemplates(Alias alias, Site site, IEnumerable<ModuleDefinition> moduleDefinitions, string version)
|
||||
{
|
||||
var pageTemplates = new List<PageTemplate>();
|
||||
foreach (var moduleDefinition in moduleDefinitions)
|
||||
{
|
||||
if (moduleDefinition.PageTemplates != null)
|
||||
{
|
||||
foreach (var pageTemplate in moduleDefinition.PageTemplates)
|
||||
{
|
||||
if (pageTemplate.PageTemplateModules.Count == 0)
|
||||
{
|
||||
pageTemplate.PageTemplateModules.Add(new PageTemplateModule());
|
||||
}
|
||||
foreach (var pageTemplateModule in pageTemplate.PageTemplateModules)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pageTemplateModule.ModuleDefinitionName))
|
||||
{
|
||||
pageTemplateModule.ModuleDefinitionName = moduleDefinition.ModuleDefinitionName;
|
||||
}
|
||||
if (string.IsNullOrEmpty(pageTemplateModule.Title))
|
||||
{
|
||||
pageTemplateModule.Title = moduleDefinition.Name;
|
||||
}
|
||||
}
|
||||
pageTemplates.Add(pageTemplate);
|
||||
if (pageTemplate.Version != "*" && (string.IsNullOrEmpty(version) || Version.Parse(pageTemplate.Version) > Version.Parse(version)))
|
||||
{
|
||||
version = pageTemplate.Version;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CreatePages(site, pageTemplates, alias);
|
||||
return version;
|
||||
}
|
||||
|
||||
private void CreateSite(Site site)
|
||||
|
@ -188,90 +295,179 @@ namespace Oqtane.Repository
|
|||
List<PageTemplate> pageTemplates = ((ISiteTemplate) siteTemplateObject).CreateSite(site);
|
||||
if (pageTemplates != null && pageTemplates.Count > 0)
|
||||
{
|
||||
CreatePages(site, pageTemplates);
|
||||
CreatePages(site, pageTemplates, null);
|
||||
}
|
||||
}
|
||||
|
||||
// create admin pages
|
||||
CreatePages(site, CreateAdminPages());
|
||||
CreatePages(site, CreateAdminPages(), null);
|
||||
}
|
||||
|
||||
public void CreatePages(Site site, List<PageTemplate> pageTemplates)
|
||||
public void CreatePages(Site site, List<PageTemplate> pageTemplates, Alias alias)
|
||||
{
|
||||
List<ModuleDefinition> moduledefinitions = _moduleDefinitionRepository.GetModuleDefinitions(site.SiteId).ToList();
|
||||
foreach (PageTemplate pagetemplate in pageTemplates)
|
||||
List<Page> pages = null;
|
||||
List<PageModule> pageModules = null;
|
||||
List<ModuleDefinition> moduleDefinitions = null;
|
||||
|
||||
foreach (PageTemplate pageTemplate in pageTemplates)
|
||||
{
|
||||
int? parentid = null;
|
||||
if (pagetemplate.Parent != "")
|
||||
if (pageTemplate.AliasName == "*" || alias == null || pageTemplate.AliasName == alias.Name)
|
||||
{
|
||||
List<Page> pages = _pageRepository.GetPages(site.SiteId).ToList();
|
||||
Page parent = pages.Where(item => item.Name == pagetemplate.Parent).FirstOrDefault();
|
||||
parentid = parent.PageId;
|
||||
}
|
||||
|
||||
Page page = new Page
|
||||
{
|
||||
SiteId = site.SiteId,
|
||||
ParentId = parentid,
|
||||
Name = pagetemplate.Name,
|
||||
Title = "",
|
||||
Path = pagetemplate.Path,
|
||||
Order = (pagetemplate.Order == 0) ? 1 : pagetemplate.Order,
|
||||
Url = "",
|
||||
IsNavigation = pagetemplate.IsNavigation,
|
||||
ThemeType = "",
|
||||
DefaultContainerType = "",
|
||||
Icon = pagetemplate.Icon,
|
||||
PermissionList = pagetemplate.PermissionList,
|
||||
IsPersonalizable = pagetemplate.IsPersonalizable,
|
||||
UserId = null,
|
||||
IsClickable = true
|
||||
};
|
||||
page = _pageRepository.AddPage(page);
|
||||
|
||||
foreach (PageTemplateModule pagetemplatemodule in pagetemplate.PageTemplateModules)
|
||||
{
|
||||
if (pagetemplatemodule.ModuleDefinitionName != "")
|
||||
if (string.IsNullOrEmpty(site.Version) || pageTemplate.Version == "*" || Version.Parse(pageTemplate.Version) > Version.Parse(site.Version))
|
||||
{
|
||||
ModuleDefinition moduledefinition = moduledefinitions.Where(item => item.ModuleDefinitionName == pagetemplatemodule.ModuleDefinitionName).FirstOrDefault();
|
||||
if (moduledefinition != null)
|
||||
if (pages == null)
|
||||
{
|
||||
Module module = new Module
|
||||
pages = _pageRepository.GetPages(site.SiteId).ToList();
|
||||
}
|
||||
var page = pages.FirstOrDefault(item => item.Path == pageTemplate.Path);
|
||||
if (page == null)
|
||||
{
|
||||
page = new Page();
|
||||
page.SiteId = site.SiteId;
|
||||
page.Path = pageTemplate.Path.ToLower();
|
||||
}
|
||||
page.Name = (string.IsNullOrEmpty(pageTemplate.Name)) ? page.Path : pageTemplate.Name;
|
||||
page.Name = (page.Name.Contains("/")) ? page.Name.Substring(page.Name.LastIndexOf("/") + 1) : page.Name;
|
||||
int? parentid = null;
|
||||
if (!string.IsNullOrEmpty(pageTemplate.Parent))
|
||||
{
|
||||
if (pages.Any(item => item.Path.ToLower() == pageTemplate.Parent.ToLower()))
|
||||
{
|
||||
SiteId = site.SiteId,
|
||||
ModuleDefinitionName = pagetemplatemodule.ModuleDefinitionName,
|
||||
AllPages = false,
|
||||
PermissionList = pagetemplatemodule.PermissionList,
|
||||
};
|
||||
module = _moduleRepository.AddModule(module);
|
||||
|
||||
if (pagetemplatemodule.Content != "" && moduledefinition.ServerManagerType!= "")
|
||||
parentid = pages.FirstOrDefault(item => item.Path.ToLower() == pageTemplate.Parent.ToLower()).PageId;
|
||||
}
|
||||
}
|
||||
page.ParentId = parentid;
|
||||
page.Title = pageTemplate.Title;
|
||||
page.Order = pageTemplate.Order;
|
||||
page.Url = pageTemplate.Url;
|
||||
page.ThemeType = pageTemplate.ThemeType;
|
||||
page.DefaultContainerType = pageTemplate.DefaultContainerType;
|
||||
page.HeadContent = pageTemplate.HeadContent;
|
||||
page.BodyContent = pageTemplate.BodyContent;
|
||||
page.Icon = pageTemplate.Icon;
|
||||
page.IsNavigation = pageTemplate.IsNavigation;
|
||||
page.IsClickable = pageTemplate.IsClickable;
|
||||
page.IsPersonalizable = pageTemplate.IsPersonalizable;
|
||||
page.UserId = null;
|
||||
page.IsDeleted = pageTemplate.IsDeleted;
|
||||
page.PermissionList = pageTemplate.PermissionList;
|
||||
try
|
||||
{
|
||||
if (page.PageId != 0 && pageTemplate.Update)
|
||||
{
|
||||
Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
|
||||
if (moduletype != null && moduletype.GetInterface("IPortable") != null)
|
||||
page = _pageRepository.UpdatePage(page);
|
||||
if (alias != null)
|
||||
{
|
||||
try
|
||||
_logger.Log(LogLevel.Information, "Site Template", LogFunction.Update, "Page Updated {Page}", page);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
page = _pageRepository.AddPage(page);
|
||||
pages.Add(page);
|
||||
if (alias != null)
|
||||
{
|
||||
_logger.Log(LogLevel.Information, "Site Template", LogFunction.Create, "Page Added {Page}", page);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (alias != null)
|
||||
{
|
||||
_logger.Log(LogLevel.Error, "Site Template", LogFunction.Other, ex, "Error Processing Page {Page}", page);
|
||||
}
|
||||
}
|
||||
|
||||
if (pageModules == null)
|
||||
{
|
||||
pageModules = _pageModuleRepository.GetPageModules(site.SiteId).ToList();
|
||||
}
|
||||
if (moduleDefinitions == null)
|
||||
{
|
||||
moduleDefinitions = _moduleDefinitionRepository.GetModuleDefinitions(site.SiteId).ToList();
|
||||
}
|
||||
foreach (PageTemplateModule pageTemplateModule in pageTemplate.PageTemplateModules)
|
||||
{
|
||||
var moduleDefinition = moduleDefinitions.Where(item => item.ModuleDefinitionName == pageTemplateModule.ModuleDefinitionName).FirstOrDefault();
|
||||
if (moduleDefinition != null)
|
||||
{
|
||||
var pageModule = pageModules.FirstOrDefault(item => item.PageId == page.PageId && item.Module.ModuleDefinitionName == pageTemplateModule.ModuleDefinitionName && item.Title == pageTemplateModule.Title);
|
||||
if (pageModule == null)
|
||||
{
|
||||
pageModule = new PageModule();
|
||||
pageModule.PageId = page.PageId;
|
||||
pageModule.Module = new Module();
|
||||
pageModule.Module.SiteId = site.SiteId;
|
||||
pageModule.Module.ModuleDefinitionName = pageTemplateModule.ModuleDefinitionName;
|
||||
}
|
||||
pageModule.Title = pageTemplateModule.Title;
|
||||
pageModule.Pane = pageTemplateModule.Pane;
|
||||
pageModule.ContainerType = pageTemplateModule.ContainerType;
|
||||
pageModule.IsDeleted = pageTemplateModule.IsDeleted;
|
||||
pageModule.Module.PermissionList = pageTemplateModule.PermissionList;
|
||||
pageModule.Module.AllPages = false;
|
||||
pageModule.Module.IsDeleted = false;
|
||||
try
|
||||
{
|
||||
if (pageModule.ModuleId != 0 && pageTemplate.Update)
|
||||
{
|
||||
var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
|
||||
((IPortable)moduleobject).ImportModule(module, pagetemplatemodule.Content, moduledefinition.Version);
|
||||
_moduleRepository.UpdateModule(pageModule.Module);
|
||||
_pageModuleRepository.UpdatePageModule(pageModule);
|
||||
if (alias != null)
|
||||
{
|
||||
_logger.Log(LogLevel.Information, "Site Template", LogFunction.Update, "Page Mopdule Updated {PageModule}", pageModule);
|
||||
}
|
||||
}
|
||||
catch
|
||||
else
|
||||
{
|
||||
// error in IPortable implementation
|
||||
pageModule.Module = _moduleRepository.AddModule(pageModule.Module);
|
||||
pageModule.ModuleId = pageModule.Module.ModuleId;
|
||||
pageModule.Module = null; // remove tracking
|
||||
_pageModuleRepository.AddPageModule(pageModule);
|
||||
if (alias != null)
|
||||
{
|
||||
_logger.Log(LogLevel.Information, "Site Template", LogFunction.Create, "Page Mopdule Added {PageModule}", pageModule);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (alias != null)
|
||||
{
|
||||
_logger.Log(LogLevel.Error, "Site Template", LogFunction.Other, ex, "Error Processing Page Module {PageModule}", pageModule);
|
||||
}
|
||||
}
|
||||
|
||||
if (pageTemplateModule.Content != "" && moduleDefinition.ServerManagerType != "")
|
||||
{
|
||||
Type moduletype = Type.GetType(moduleDefinition.ServerManagerType);
|
||||
if (moduletype != null && moduletype.GetInterface("IPortable") != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var module = _moduleRepository.GetModule(pageModule.ModuleId);
|
||||
var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
|
||||
((IPortable)moduleobject).ImportModule(module, pageTemplateModule.Content, moduleDefinition.Version);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (alias != null)
|
||||
{
|
||||
_logger.Log(LogLevel.Error, "Site Template", LogFunction.Other, ex, "Error Importing Content For {ModuleDefinitionName}", pageTemplateModule.ModuleDefinitionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PageModule pagemodule = new PageModule
|
||||
else
|
||||
{
|
||||
PageId = page.PageId,
|
||||
ModuleId = module.ModuleId,
|
||||
Title = pagetemplatemodule.Title,
|
||||
Pane = pagetemplatemodule.Pane,
|
||||
Order = 1,
|
||||
ContainerType = ""
|
||||
};
|
||||
_pageModuleRepository.AddPageModule(pagemodule);
|
||||
if (alias != null)
|
||||
{
|
||||
_logger.Log(LogLevel.Error, "Site Template", LogFunction.Other, "Module Definition Does Not Exist {ModuleDefinitionName}", pageTemplateModule.ModuleDefinitionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ namespace Oqtane.Repository
|
|||
// get themes
|
||||
List<Theme> themes = _cache.GetOrCreate($"themes:{_tenants.GetAlias().SiteKey}", entry =>
|
||||
{
|
||||
entry.SlidingExpiration = TimeSpan.FromMinutes(30);
|
||||
entry.Priority = CacheItemPriority.NeverRemove;
|
||||
return ProcessThemes(siteId);
|
||||
});
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ namespace Oqtane.Models
|
|||
Runtimes = "";
|
||||
Template = "";
|
||||
Resources = null;
|
||||
IsAutoEnabled = true;
|
||||
PageTemplates = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -111,7 +113,10 @@ namespace Oqtane.Models
|
|||
public List<Resource> Resources { get; set; } // added in 4.0.0
|
||||
|
||||
[NotMapped]
|
||||
public bool IsAutoEnabled { get; set; } = true; // added in 4.0.0
|
||||
public bool IsAutoEnabled { get; set; } // added in 4.0.0
|
||||
|
||||
[NotMapped]
|
||||
public List<PageTemplate> PageTemplates { get; set; } // added in 4.0.0
|
||||
|
||||
// internal properties
|
||||
[NotMapped]
|
||||
|
|
|
@ -21,6 +21,12 @@ namespace Oqtane.Models
|
|||
/// </summary>
|
||||
public int SiteId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Path of the page.
|
||||
/// TODO: todoc relative to what? site root, parent-page, domain?
|
||||
/// </summary>
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the parent <see cref="Page"/> if it has one.
|
||||
/// </summary>
|
||||
|
@ -36,13 +42,7 @@ namespace Oqtane.Models
|
|||
/// Page Title which is shown in the browser tab.
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Path of the page.
|
||||
/// TODO: todoc relative to what? site root, parent-page, domain?
|
||||
/// </summary>
|
||||
public string Path { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sort order in the list of other sibling pages
|
||||
/// </summary>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Models
|
||||
{
|
||||
|
@ -13,16 +13,59 @@ namespace Oqtane.Models
|
|||
|
||||
public class PageTemplate
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Parent { get; set; }
|
||||
public int Order { get; set; }
|
||||
public PageTemplate()
|
||||
{
|
||||
Url = "";
|
||||
Name = "";
|
||||
Parent = "";
|
||||
Title = "";
|
||||
Path = "";
|
||||
Order = 1;
|
||||
ThemeType = "";
|
||||
DefaultContainerType = "";
|
||||
HeadContent = "";
|
||||
BodyContent = "";
|
||||
Icon = "";
|
||||
IsNavigation = true;
|
||||
IsClickable = true;
|
||||
IsPersonalizable = false;
|
||||
IsDeleted = false;
|
||||
PermissionList = new List<Permission>()
|
||||
{
|
||||
new Permission(PermissionNames.View, RoleNames.Admin, true),
|
||||
new Permission(PermissionNames.Edit, RoleNames.Admin, true)
|
||||
};
|
||||
PageTemplateModules = new List<PageTemplateModule>();
|
||||
|
||||
// properties used by IModule
|
||||
AliasName = "*";
|
||||
Version = "*";
|
||||
Update = false;
|
||||
}
|
||||
|
||||
public string Path { get; set; }
|
||||
public string Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Title { get; set; }
|
||||
public int Order { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string ThemeType { get; set; }
|
||||
public string DefaultContainerType { get; set; }
|
||||
public string HeadContent { get; set; }
|
||||
public string BodyContent { get; set; }
|
||||
public string Icon { get; set; }
|
||||
public bool IsNavigation { get; set; }
|
||||
public bool IsClickable { get; set; }
|
||||
public bool IsPersonalizable { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public List<Permission> PermissionList { get; set; }
|
||||
public List<PageTemplateModule> PageTemplateModules { get; set; }
|
||||
|
||||
// properties used by IModule
|
||||
public string AliasName { get; set; }
|
||||
public string Version { get; set; }
|
||||
public bool Update { get; set; }
|
||||
|
||||
[Obsolete("This property is obsolete", false)]
|
||||
public bool EditMode { get; set; }
|
||||
|
||||
|
@ -42,9 +85,28 @@ namespace Oqtane.Models
|
|||
|
||||
public class PageTemplateModule
|
||||
{
|
||||
public PageTemplateModule()
|
||||
{
|
||||
ModuleDefinitionName = "";
|
||||
Title = "";
|
||||
Pane = PaneNames.Default;
|
||||
Order = 1;
|
||||
ContainerType = "";
|
||||
IsDeleted = false;
|
||||
PermissionList = new List<Permission>()
|
||||
{
|
||||
new Permission(PermissionNames.View, RoleNames.Admin, true),
|
||||
new Permission(PermissionNames.Edit, RoleNames.Admin, true)
|
||||
};
|
||||
Content = "";
|
||||
}
|
||||
|
||||
public string ModuleDefinitionName { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Pane { get; set; }
|
||||
public int Order { get; set; }
|
||||
public string ContainerType { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public List<Permission> PermissionList { get; set; }
|
||||
public string Content { get; set; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user