adopt more of the migrations conventions
This commit is contained in:
parent
9b29487934
commit
412b139796
|
@ -678,11 +678,11 @@ namespace Oqtane.Infrastructure
|
||||||
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
|
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
|
||||||
foreach (Assembly assembly in assemblies)
|
foreach (Assembly assembly in assemblies)
|
||||||
{
|
{
|
||||||
foreach (var type in assembly.GetTypes(typeof(ISiteUpgrade)))
|
foreach (var type in assembly.GetTypes(typeof(ISiteMigration)))
|
||||||
{
|
{
|
||||||
if (Attribute.IsDefined(type, typeof(SiteUpgradeAttribute)))
|
if (Attribute.IsDefined(type, typeof(SiteMigrationAttribute)))
|
||||||
{
|
{
|
||||||
var attribute = (SiteUpgradeAttribute)Attribute.GetCustomAttribute(type, typeof(SiteUpgradeAttribute));
|
var attribute = (SiteMigrationAttribute)Attribute.GetCustomAttribute(type, typeof(SiteMigrationAttribute));
|
||||||
siteupgrades.Add(attribute.AliasName + " " + attribute.Version, type);
|
siteupgrades.Add(attribute.AliasName + " " + attribute.Version, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -715,21 +715,18 @@ namespace Oqtane.Infrastructure
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var obj = Activator.CreateInstance(upgrade.Value) as ISiteUpgrade;
|
var obj = Activator.CreateInstance(upgrade.Value) as ISiteMigration;
|
||||||
if (obj.Upgrade(site, alias))
|
if (obj != null)
|
||||||
{
|
{
|
||||||
|
obj.Up(site, alias);
|
||||||
site.Version = version;
|
site.Version = version;
|
||||||
sites.UpdateSite(site);
|
sites.UpdateSite(site);
|
||||||
logger.Log(alias.SiteId, Shared.LogLevel.Information, "Site Upgrade", LogFunction.Other, "Site Upgraded Successfully To Version {version} For {Alias}", version, alias.Name);
|
logger.Log(alias.SiteId, Shared.LogLevel.Information, "Site Migration", LogFunction.Other, "Site Migrated Successfully To Version {version} For {Alias}", version, alias.Name);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.Log(alias.SiteId, Shared.LogLevel.Error, "Site Upgrade", LogFunction.Other, "Site Could Not Be Upgraded Using IUpgradeable Interface {Type} For {Alias} And Version {Version}", upgrade.Value, alias.Name, version);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.Log(alias.SiteId, Shared.LogLevel.Error, "Site Upgrade", LogFunction.Other, "An Error Occurred Executing IUpgradeable Interface {Type} For {Alias} And Version {Version} {Error}", upgrade.Value, alias.Name, version, ex.Message);
|
logger.Log(alias.SiteId, Shared.LogLevel.Error, "Site Migration", LogFunction.Other, "An Error Occurred Executing Site Migration {Type} For {Alias} And Version {Version} {Error}", upgrade.Value, alias.Name, version, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
Oqtane.Server/Infrastructure/Interfaces/ISiteMigration.cs
Normal file
10
Oqtane.Server/Infrastructure/Interfaces/ISiteMigration.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
|
namespace Oqtane.Infrastructure
|
||||||
|
{
|
||||||
|
public interface ISiteMigration
|
||||||
|
{
|
||||||
|
void Up(Site site, Alias alias);
|
||||||
|
void Down(Site site, Alias alias); // for future use (if necessary)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +0,0 @@
|
||||||
using Oqtane.Models;
|
|
||||||
|
|
||||||
namespace Oqtane.Infrastructure
|
|
||||||
{
|
|
||||||
public interface ISiteUpgrade
|
|
||||||
{
|
|
||||||
bool Upgrade(Site site, Alias alias);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,12 +3,12 @@ using System;
|
||||||
namespace Oqtane.Infrastructure
|
namespace Oqtane.Infrastructure
|
||||||
{
|
{
|
||||||
[AttributeUsage(AttributeTargets.Class)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
public class SiteUpgradeAttribute : Attribute
|
public class SiteMigrationAttribute : Attribute
|
||||||
{
|
{
|
||||||
private string aliasname;
|
private string aliasname;
|
||||||
private string version;
|
private string version;
|
||||||
|
|
||||||
public SiteUpgradeAttribute(string AliasName, string Version)
|
public SiteMigrationAttribute(string AliasName, string Version)
|
||||||
{
|
{
|
||||||
aliasname = AliasName;
|
aliasname = AliasName;
|
||||||
version = Version;
|
version = Version;
|
|
@ -0,0 +1,18 @@
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
|
namespace Oqtane.Infrastructure
|
||||||
|
{
|
||||||
|
[SiteMigration("localhost:44357", "01.00.00")]
|
||||||
|
public class ExampleSiteMigration : ISiteMigration
|
||||||
|
{
|
||||||
|
void ISiteMigration.Up(Site site, Alias alias)
|
||||||
|
{
|
||||||
|
// execute some version-specific upgrade logic for the site here such as adding pages, modules, content, etc...
|
||||||
|
}
|
||||||
|
|
||||||
|
void ISiteMigration.Down(Site site, Alias alias)
|
||||||
|
{
|
||||||
|
// not implemented
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +0,0 @@
|
||||||
using Oqtane.Models;
|
|
||||||
|
|
||||||
namespace Oqtane.Infrastructure
|
|
||||||
{
|
|
||||||
[SiteUpgrade("localhost:44357", "01.00.00")]
|
|
||||||
public class ExampleUpgrade : ISiteUpgrade
|
|
||||||
{
|
|
||||||
bool ISiteUpgrade.Upgrade(Site site, Alias alias)
|
|
||||||
{
|
|
||||||
// execute some version-specific upgrade logic for the site here such as adding pages, modules, content, etc...
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user