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 };
// find upgrade type
Type upgradetype = null;
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
foreach (Assembly assembly in assemblies)
using (var scope = _serviceScopeFactory.CreateScope())
{
var types = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IUpgradeable)));
if (types.Any())
{
upgradetype = types.First();
break;
}
}
var aliases = scope.ServiceProvider.GetRequiredService<IAliasRepository>();
var tenantManager = scope.ServiceProvider.GetRequiredService<ITenantManager>();
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
// execute upgrade
if (upgradetype != null)
{
var obj = Activator.CreateInstance(upgradetype) as IUpgradeable;
if (obj != null)
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
foreach (Assembly assembly in assemblies)
{
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 tenantManager = scope.ServiceProvider.GetRequiredService<ITenantManager>();
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
foreach (var alias in aliases.GetAliases().ToList().Where(item => item.IsDefault))
var obj = Activator.CreateInstance(type) as IUpgradeable;
if (obj != null)
{
var versions = obj.GetVersions(alias);
if (!string.IsNullOrEmpty(versions))
foreach (var alias in aliases.GetAliases().ToList().Where(item => item.IsDefault))
{
tenantManager.SetTenant(alias.TenantId);
var site = sites.GetSites().FirstOrDefault(item => item.SiteId == alias.SiteId);
if (site != null)
var versions = obj.GetVersions(alias);
if (!string.IsNullOrEmpty(versions))
{
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;
sites.UpdateSite(site);
}
else
{
result.Message = "An Error Occurred Executing IUpgradeable Interface For " + alias.Name + " For Version " + 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;
}
}
}
}

View File

@ -12,7 +12,7 @@ namespace Oqtane.Infrastructure
switch (alias.Name)
{
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";
break;
}
@ -25,6 +25,7 @@ namespace Oqtane.Infrastructure
switch (alias.Name)
{
case "localhost:44357":
// the version cases should match the list of versions returned above
switch (version)
{
case "1.0.0":