include theme resources on server page load, add IUpgradeable interface to provide site-based versioning support

This commit is contained in:
Shaun Walker
2022-04-01 17:57:30 -04:00
parent bbb547efb6
commit fc12903cfd
8 changed files with 193 additions and 8 deletions

View File

@ -190,6 +190,10 @@ namespace Oqtane.Infrastructure
if (result.Success)
{
result = CreateSite(install);
if (result.Success)
{
result = MigrateSites();
}
}
}
}
@ -665,6 +669,78 @@ namespace Oqtane.Infrastructure
return result;
}
private Installation MigrateSites()
{
var result = new Installation { Success = false, Message = string.Empty };
// find upgrade type
Type upgradetype = null;
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
foreach (Assembly assembly in assemblies)
{
var types = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IUpgradeable)));
if (types.Any())
{
upgradetype = types.First();
break;
}
}
// execute upgrade
if (upgradetype != null)
{
var obj = Activator.CreateInstance(upgradetype) as IUpgradeable;
if (obj != null)
{
using (var scope = _serviceScopeFactory.CreateScope())
{
var aliases = scope.ServiceProvider.GetRequiredService<IAliasRepository>();
var tenantManager = scope.ServiceProvider.GetRequiredService<ITenantManager>();
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
foreach (var alias in aliases.GetAliases().ToList().Where(item => item.IsDefault))
{
var versions = obj.GetVersions(alias);
if (!string.IsNullOrEmpty(versions))
{
tenantManager.SetTenant(alias.TenantId);
var site = sites.GetSites().FirstOrDefault(item => item.SiteId == alias.SiteId);
if (site != null)
{
foreach (var version in versions.Split(',', StringSplitOptions.RemoveEmptyEntries))
{
if (string.IsNullOrEmpty(site.Version) || Version.Parse(version) > Version.Parse(site.Version))
{
if (obj.Upgrade(alias, version))
{
site.Version = version;
sites.UpdateSite(site);
}
else
{
result.Message = "An Error Occurred Executing IUpgradeable Interface For " + alias.Name + " For Version " + version;
}
}
}
}
}
}
}
}
}
if (string.IsNullOrEmpty(result.Message))
{
result.Success = true;
}
else
{
_filelogger.LogError(Utilities.LogMessage(this, result.Message));
}
return result;
}
private string DenormalizeConnectionString(string connectionString)
{
var dataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory")?.ToString();