mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Core - Add migration to also migrate profile activation conditions
This commit is contained in:
1 parent
2e600e76b0
commit
5203e95141
5 files changed
+95
-12
No files matched your search
@@ -5,5 +5,5 @@ namespace Artemis.Storage.Migrations;
|
||||
public interface IProfileMigration
|
||||
{
|
||||
int Version { get; }
|
||||
void Migrate(JObject profileJson);
|
||||
void Migrate(JObject configurationJson, JObject profileJson);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ internal class M0001NodeProviders : IProfileMigration
|
||||
public int Version => 1;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Migrate(JObject profileJson)
|
||||
public void Migrate(JObject configurationJson, JObject profileJson)
|
||||
{
|
||||
JArray? folders = (JArray?) profileJson["Folders"]?["$values"];
|
||||
JArray? layers = (JArray?) profileJson["Layers"]?["$values"];
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Artemis.Storage.Migrations.Profile;
|
||||
|
||||
/// <summary>
|
||||
/// Migrates nodes to be provider-based on profile configurations as well..
|
||||
/// This requires giving them a ProviderId and updating the their namespaces to match the namespace of the new plugin.
|
||||
/// </summary>
|
||||
internal class M0002NodeProvidersProfileConfig : IProfileMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public int Version => 2;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Migrate(JObject configurationJson, JObject profileJson)
|
||||
{
|
||||
MigrateNodeScript(configurationJson["ActivationCondition"]);
|
||||
}
|
||||
|
||||
private void MigrateNodeScript(JToken? nodeScript)
|
||||
{
|
||||
if (nodeScript == null || !nodeScript.HasValues)
|
||||
return;
|
||||
|
||||
JArray? nodes = (JArray?) nodeScript["Nodes"]?["$values"];
|
||||
if (nodes == null)
|
||||
return;
|
||||
|
||||
foreach (JToken node in nodes)
|
||||
{
|
||||
node["Type"] = node["Type"]?.Value<string>()?.Replace("Artemis.VisualScripting.Nodes", "Artemis.Plugins.Nodes.General.Nodes");
|
||||
node["ProviderId"] = "Artemis.Plugins.Nodes.General.GeneralNodesProvider-d9e1ee78";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations.Storage;
|
||||
|
||||
public class M0025NodeProvidersProfileConfig : IStorageMigration
|
||||
{
|
||||
public int UserVersion => 25;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
ILiteCollection<BsonDocument> categoryCollection = repository.Database.GetCollection("ProfileCategoryEntity");
|
||||
foreach (BsonDocument profileCategoryBson in categoryCollection.FindAll())
|
||||
{
|
||||
BsonArray? profiles = profileCategoryBson["ProfileConfigurations"]?.AsArray;
|
||||
if (profiles != null)
|
||||
{
|
||||
foreach (BsonValue profile in profiles)
|
||||
{
|
||||
profile["Version"] = 2;
|
||||
MigrateNodeScript(profile["ActivationCondition"]?.AsDocument);
|
||||
}
|
||||
}
|
||||
categoryCollection.Update(profileCategoryBson);
|
||||
}
|
||||
}
|
||||
|
||||
private void MigrateNodeScript(BsonDocument? nodeScript)
|
||||
{
|
||||
if (nodeScript == null || nodeScript.Keys.Count == 0)
|
||||
return;
|
||||
|
||||
BsonArray? nodes = nodeScript["Nodes"]?.AsArray;
|
||||
if (nodes == null)
|
||||
return;
|
||||
|
||||
foreach (BsonValue node in nodes)
|
||||
{
|
||||
node.AsDocument["Type"] = node.AsDocument["Type"]?.AsString?.Replace("Artemis.VisualScripting.Nodes", "Artemis.Plugins.Nodes.General.Nodes");
|
||||
node.AsDocument["ProviderId"] = "Artemis.Plugins.Nodes.General.GeneralNodesProvider-d9e1ee78";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user