Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues when importing SiteTemplates #4286

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Oqtane.Server/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
var visitorCookieName = Constants.VisitorCookiePrefix + SiteId.ToString();
var visitorCookieValue = Context.Request.Cookies[visitorCookieName];
DateTime expiry = DateTime.MinValue;
if (visitorCookieValue.Contains("|"))
if (visitorCookieValue != null && visitorCookieValue.Contains("|"))
{
var values = visitorCookieValue.Split('|');
int.TryParse(values[0], out _visitorId);
Expand Down
52 changes: 35 additions & 17 deletions Oqtane.Server/Repository/SiteRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,23 @@ public void InitializeSite(Alias alias)
if (!serverstate.IsInitialized)
{
var site = GetSite(alias.SiteId);
if (site != null)
{
// initialize theme Assemblies
site.Themes = _themeRepository.GetThemes().ToList();

// initialize theme Assemblies
site.Themes = _themeRepository.GetThemes().ToList();

// initialize module Assemblies
var moduleDefinitions = _moduleDefinitionRepository.GetModuleDefinitions(alias.SiteId);
// initialize module Assemblies
var moduleDefinitions = _moduleDefinitionRepository.GetModuleDefinitions(alias.SiteId);

// execute migrations
var version = ProcessSiteMigrations(alias, site);
version = ProcessPageTemplates(alias, site, moduleDefinitions, version);
if (site.Version != version)
{
site.Version = version;
UpdateSite(site);
// execute migrations
var version = ProcessSiteMigrations(alias, site);
version = ProcessPageTemplates(alias, site, moduleDefinitions, version);
if (site.Version != version)
{
site.Version = version;
UpdateSite(site);
}
}

serverstate.IsInitialized = true;
}
}
Expand Down Expand Up @@ -411,7 +412,7 @@ public void CreatePages(Site site, List<PageTemplate> pageTemplates, Alias alias
}
else
{
parent = pages.FirstOrDefault(item => item.Path.ToLower() == pageTemplate.Parent.ToLower());
parent = pages.FirstOrDefault(item => item.Path.ToLower() == ((pageTemplate.Parent == "/") ? "" : pageTemplate.Parent.ToLower()));
}
page.ParentId = (parent != null) ? parent.PageId : null;
page.Path = page.Path.ToLower();
Expand Down Expand Up @@ -487,7 +488,21 @@ public void CreatePages(Site site, List<PageTemplate> pageTemplates, Alias alias
pageModule.Order = (pageTemplateModule.Order == 0) ? 1 : pageTemplateModule.Order;
pageModule.ContainerType = pageTemplateModule.ContainerType;
pageModule.IsDeleted = pageTemplateModule.IsDeleted;
pageModule.Module.PermissionList = pageTemplateModule.PermissionList;
pageModule.Module.PermissionList = new List<Permission>();
foreach (var permission in pageTemplateModule.PermissionList)
{
pageModule.Module.PermissionList.Add(new Permission
{
SiteId = permission.SiteId,
EntityName = permission.EntityName,
EntityId = permission.EntityId,
PermissionName = permission.PermissionName,
RoleName = permission.RoleName,
UserId = permission.UserId,
IsAuthorized = permission.IsAuthorized
});
}
//pageModule.Module.PermissionList = pageTemplateModule.PermissionList;
pageModule.Module.AllPages = false;
pageModule.Module.IsDeleted = false;
try
Expand Down Expand Up @@ -539,8 +554,11 @@ public void CreatePages(Site site, List<PageTemplate> pageTemplates, Alias alias
try
{
var module = _moduleRepository.GetModule(pageModule.ModuleId);
var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
((IPortable)moduleobject).ImportModule(module, pageTemplateModule.Content, moduleDefinition.Version);
if (module != null)
{
var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
((IPortable)moduleobject).ImportModule(module, pageTemplateModule.Content, moduleDefinition.Version);
}
}
catch (Exception ex)
{
Expand Down