Merge pull request #2102 from sbwalker/dev

allow for multiple upgrade classes
This commit is contained in:
Shaun Walker 2022-04-01 18:07:13 -04:00 committed by GitHub
commit 5380b12294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 37 deletions

View File

@ -673,52 +673,42 @@ namespace Oqtane.Infrastructure
{ {
var result = new Installation { Success = false, Message = string.Empty }; var result = new Installation { Success = false, Message = string.Empty };
// find upgrade type using (var scope = _serviceScopeFactory.CreateScope())
Type upgradetype = null;
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
foreach (Assembly assembly in assemblies)
{ {
var types = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IUpgradeable))); var aliases = scope.ServiceProvider.GetRequiredService<IAliasRepository>();
if (types.Any()) var tenantManager = scope.ServiceProvider.GetRequiredService<ITenantManager>();
{ var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
upgradetype = types.First();
break;
}
}
// execute upgrade var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
if (upgradetype != null) foreach (Assembly assembly in assemblies)
{
var obj = Activator.CreateInstance(upgradetype) as IUpgradeable;
if (obj != null)
{ {
using (var scope = _serviceScopeFactory.CreateScope()) foreach (var type in assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IUpgradeable))))
{ {
var aliases = scope.ServiceProvider.GetRequiredService<IAliasRepository>(); var obj = Activator.CreateInstance(type) as IUpgradeable;
var tenantManager = scope.ServiceProvider.GetRequiredService<ITenantManager>(); if (obj != null)
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
foreach (var alias in aliases.GetAliases().ToList().Where(item => item.IsDefault))
{ {
var versions = obj.GetVersions(alias); foreach (var alias in aliases.GetAliases().ToList().Where(item => item.IsDefault))
if (!string.IsNullOrEmpty(versions))
{ {
tenantManager.SetTenant(alias.TenantId); var versions = obj.GetVersions(alias);
var site = sites.GetSites().FirstOrDefault(item => item.SiteId == alias.SiteId); if (!string.IsNullOrEmpty(versions))
if (site != null)
{ {
foreach (var version in versions.Split(',', StringSplitOptions.RemoveEmptyEntries)) tenantManager.SetTenant(alias.TenantId);
var site = sites.GetSites().FirstOrDefault(item => item.SiteId == alias.SiteId);
if (site != null)
{ {
if (string.IsNullOrEmpty(site.Version) || Version.Parse(version) > Version.Parse(site.Version)) foreach (var version in versions.Split(',', StringSplitOptions.RemoveEmptyEntries))
{ {
if (obj.Upgrade(alias, version)) if (string.IsNullOrEmpty(site.Version) || Version.Parse(version) > Version.Parse(site.Version))
{ {
site.Version = version; if (obj.Upgrade(alias, version))
sites.UpdateSite(site); {
} site.Version = version;
else sites.UpdateSite(site);
{ }
result.Message = "An Error Occurred Executing IUpgradeable Interface For " + alias.Name + " For Version " + version; else
{
result.Message = "An Error Occurred Executing IUpgradeable Interface For " + alias.Name + " For Version " + version;
}
} }
} }
} }

View File

@ -12,7 +12,7 @@ namespace Oqtane.Infrastructure
switch (alias.Name) switch (alias.Name)
{ {
case "localhost:44357": case "localhost:44357":
// return the list of official release versions for the specific site // return the comma delimited list of official release versions for the specific site
versions = "1.0.0"; versions = "1.0.0";
break; break;
} }
@ -25,6 +25,7 @@ namespace Oqtane.Infrastructure
switch (alias.Name) switch (alias.Name)
{ {
case "localhost:44357": case "localhost:44357":
// the version cases should match the list of versions returned above
switch (version) switch (version)
{ {
case "1.0.0": case "1.0.0":