Merge pull request #1221 from sbwalker/dev
added globally unique identifier for Site ( used string data type to ensure compatibility with multiple database engines )
This commit is contained in:
commit
d990a9fc30
@ -1,6 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Oqtane.Extensions;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Repository;
|
using Oqtane.Repository;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
@ -25,80 +24,94 @@ namespace Oqtane.Infrastructure
|
|||||||
|
|
||||||
public void Upgrade(Tenant tenant, string version)
|
public void Upgrade(Tenant tenant, string version)
|
||||||
{
|
{
|
||||||
// core framework upgrade logic - note that you can check if current tenant is Master if you only want to execute the logic once
|
// core framework upgrade logic - executed for every tenant
|
||||||
switch (version)
|
using (var scope = _serviceScopeFactory.CreateScope())
|
||||||
{
|
{
|
||||||
case "0.9.0":
|
// set SiteState based on tenant
|
||||||
// this code is commented out on purpose - it provides an example of how to programmatically add a page to all existing sites on upgrade
|
var siteState = scope.ServiceProvider.GetRequiredService<SiteState>();
|
||||||
var pageTemplates = new List<PageTemplate>();
|
siteState.Alias = new Alias { TenantId = tenant.TenantId };
|
||||||
//pageTemplates.Add(new PageTemplate
|
|
||||||
//{
|
switch (version)
|
||||||
// Name = "Test",
|
{
|
||||||
// Parent = "",
|
case "1.0.0":
|
||||||
// Path = "test",
|
Upgrade_1_0_0(tenant, scope);
|
||||||
// Icon = Icons.Badge,
|
break;
|
||||||
// IsNavigation = true,
|
case "2.0.2":
|
||||||
// IsPersonalizable = false,
|
Upgrade_2_0_2(tenant, scope);
|
||||||
// EditMode = false,
|
break;
|
||||||
// PagePermissions = new List<Permission>
|
}
|
||||||
// {
|
|
||||||
// new Permission(PermissionNames.View, RoleNames.Admin, true),
|
|
||||||
// new Permission(PermissionNames.View, RoleNames.Everyone, true),
|
|
||||||
// new Permission(PermissionNames.Edit, RoleNames.Admin, true)
|
|
||||||
// }.EncodePermissions(),
|
|
||||||
// PageTemplateModules = new List<PageTemplateModule>
|
|
||||||
// {
|
|
||||||
// new PageTemplateModule
|
|
||||||
// {
|
|
||||||
// ModuleDefinitionName = typeof(Oqtane.Modules.Admin.Login.Index).ToModuleDefinitionName(), Title = "Test", Pane = "Content",
|
|
||||||
// ModulePermissions = new List<Permission>
|
|
||||||
// {
|
|
||||||
// new Permission(PermissionNames.View, RoleNames.Admin, true),
|
|
||||||
// new Permission(PermissionNames.View, RoleNames.Everyone, true),
|
|
||||||
// new Permission(PermissionNames.Edit, RoleNames.Admin, true)
|
|
||||||
// }.EncodePermissions(),
|
|
||||||
// Content = ""
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//});
|
|
||||||
CreateSitePages(tenant, pageTemplates);
|
|
||||||
break;
|
|
||||||
case "2.0.2":
|
|
||||||
if (tenant.Name == TenantNames.Master)
|
|
||||||
{
|
|
||||||
// remove Internal module template files as they are no longer supported
|
|
||||||
var internalTemplatePath = Utilities.PathCombine(_environment.WebRootPath, "Modules", "Templates", "Internal", Path.DirectorySeparatorChar.ToString());
|
|
||||||
if (Directory.Exists(internalTemplatePath))
|
|
||||||
{
|
|
||||||
Directory.Delete(internalTemplatePath, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateSitePages(Tenant tenant, List<PageTemplate> pageTemplates)
|
private void Upgrade_1_0_0(Tenant tenant, IServiceScope scope)
|
||||||
|
{
|
||||||
|
var pageTemplates = new List<PageTemplate>();
|
||||||
|
|
||||||
|
// **Note: this code is commented out on purpose - it provides an example of how to programmatically add a page to all existing sites on upgrade
|
||||||
|
|
||||||
|
//pageTemplates.Add(new PageTemplate
|
||||||
|
//{
|
||||||
|
// Name = "Test",
|
||||||
|
// Parent = "",
|
||||||
|
// Path = "test",
|
||||||
|
// Icon = Icons.Badge,
|
||||||
|
// IsNavigation = true,
|
||||||
|
// IsPersonalizable = false,
|
||||||
|
// EditMode = false,
|
||||||
|
// PagePermissions = new List<Permission>
|
||||||
|
// {
|
||||||
|
// new Permission(PermissionNames.View, RoleNames.Admin, true),
|
||||||
|
// new Permission(PermissionNames.View, RoleNames.Everyone, true),
|
||||||
|
// new Permission(PermissionNames.Edit, RoleNames.Admin, true)
|
||||||
|
// }.EncodePermissions(),
|
||||||
|
// PageTemplateModules = new List<PageTemplateModule>
|
||||||
|
// {
|
||||||
|
// new PageTemplateModule
|
||||||
|
// {
|
||||||
|
// ModuleDefinitionName = typeof(Oqtane.Modules.Admin.Login.Index).ToModuleDefinitionName(), Title = "Test", Pane = "Content",
|
||||||
|
// ModulePermissions = new List<Permission>
|
||||||
|
// {
|
||||||
|
// new Permission(PermissionNames.View, RoleNames.Admin, true),
|
||||||
|
// new Permission(PermissionNames.View, RoleNames.Everyone, true),
|
||||||
|
// new Permission(PermissionNames.Edit, RoleNames.Admin, true)
|
||||||
|
// }.EncodePermissions(),
|
||||||
|
// Content = ""
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//});
|
||||||
|
|
||||||
|
CreateSitePages(scope, pageTemplates);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Upgrade_2_0_2(Tenant tenant, IServiceScope scope)
|
||||||
|
{
|
||||||
|
if (tenant.Name == TenantNames.Master)
|
||||||
|
{
|
||||||
|
// remove Internal module template files as they are no longer supported
|
||||||
|
var internalTemplatePath = Utilities.PathCombine(_environment.WebRootPath, "Modules", "Templates", "Internal", Path.DirectorySeparatorChar.ToString());
|
||||||
|
if (Directory.Exists(internalTemplatePath))
|
||||||
|
{
|
||||||
|
Directory.Delete(internalTemplatePath, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// initialize SiteGuid
|
||||||
|
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
|
||||||
|
foreach (Site site in sites.GetSites().ToList())
|
||||||
|
{
|
||||||
|
site.SiteGuid = System.Guid.NewGuid().ToString();
|
||||||
|
sites.UpdateSite(site);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateSitePages(IServiceScope scope, List<PageTemplate> pageTemplates)
|
||||||
{
|
{
|
||||||
if (pageTemplates.Count != 0)
|
if (pageTemplates.Count != 0)
|
||||||
{
|
{
|
||||||
var processed = new List<Site>();
|
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
|
||||||
foreach (Alias alias in _aliases.GetAliases().Where(item => item.TenantId == tenant.TenantId))
|
foreach (Site site in sites.GetSites().ToList())
|
||||||
{
|
{
|
||||||
if (!processed.Exists(item => item.SiteId == alias.SiteId))
|
sites.CreatePages(site, pageTemplates);
|
||||||
{
|
|
||||||
using (var scope = _serviceScopeFactory.CreateScope())
|
|
||||||
{
|
|
||||||
var siteState = scope.ServiceProvider.GetRequiredService<SiteState>();
|
|
||||||
siteState.Alias = alias;
|
|
||||||
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
|
|
||||||
var site = sites.GetSite(alias.SiteId);
|
|
||||||
if (site != null)
|
|
||||||
{
|
|
||||||
sites.CreatePages(site, pageTemplates);
|
|
||||||
}
|
|
||||||
processed.Add(site);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
<EmbeddedResource Include="Scripts\Tenant.02.00.01.01.sql" />
|
<EmbeddedResource Include="Scripts\Tenant.02.00.01.01.sql" />
|
||||||
<EmbeddedResource Include="Scripts\Tenant.02.00.01.02.sql" />
|
<EmbeddedResource Include="Scripts\Tenant.02.00.01.02.sql" />
|
||||||
<EmbeddedResource Include="Scripts\Tenant.02.00.01.03.sql" />
|
<EmbeddedResource Include="Scripts\Tenant.02.00.01.03.sql" />
|
||||||
|
<EmbeddedResource Include="Scripts\Tenant.02.00.02.01.sql" />
|
||||||
<EmbeddedResource Include="Modules\HtmlText\Scripts\HtmlText.1.0.0.sql" />
|
<EmbeddedResource Include="Modules\HtmlText\Scripts\HtmlText.1.0.0.sql" />
|
||||||
<EmbeddedResource Include="Modules\HtmlText\Scripts\HtmlText.Uninstall.sql" />
|
<EmbeddedResource Include="Modules\HtmlText\Scripts\HtmlText.Uninstall.sql" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -605,7 +605,7 @@ namespace Oqtane.Repository
|
|||||||
|
|
||||||
public Site AddSite(Site site)
|
public Site AddSite(Site site)
|
||||||
{
|
{
|
||||||
|
site.SiteGuid = System.Guid.NewGuid().ToString();
|
||||||
_db.Site.Add(site);
|
_db.Site.Add(site);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
CreateSite(site);
|
CreateSite(site);
|
||||||
|
10
Oqtane.Server/Scripts/Tenant.02.00.02.01.sql
Normal file
10
Oqtane.Server/Scripts/Tenant.02.00.02.01.sql
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Version 2.0.2 Tenant migration script
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
ALTER TABLE [dbo].[Site] ADD
|
||||||
|
[SiteGuid] [char](36) NULL
|
||||||
|
GO
|
||||||
|
|
@ -18,6 +18,7 @@ namespace Oqtane.Models
|
|||||||
public int? PwaAppIconFileId { get; set; }
|
public int? PwaAppIconFileId { get; set; }
|
||||||
public int? PwaSplashIconFileId { get; set; }
|
public int? PwaSplashIconFileId { get; set; }
|
||||||
public bool AllowRegistration { get; set; }
|
public bool AllowRegistration { get; set; }
|
||||||
|
public string SiteGuid { get; set; }
|
||||||
|
|
||||||
public string CreatedBy { get; set; }
|
public string CreatedBy { get; set; }
|
||||||
public DateTime CreatedOn { get; set; }
|
public DateTime CreatedOn { get; set; }
|
||||||
|
Reference in New Issue
Block a user