Skip to content

Commit

Permalink
increased version to 0.9.2 and added upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
reven committed May 18, 2023
1 parent 09fbf4e commit 6f3da12
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Helpers/StartUpHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LiteDB;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace Fenrus.Helpers;

Expand Down Expand Up @@ -66,7 +67,6 @@ private class Fenrus
/// <param name="previousVersion">the previous version number</param>
private static void Upgrade(Version previousVersion)
{
if (previousVersion < new Version(0, 9, 2))
new Upgrades.Upgrade_0_9_2().Execute();
new Upgrades.Upgrade_0_9_2().Execute(previousVersion);
}
}
13 changes: 12 additions & 1 deletion Upgrades/UpgradeScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ public abstract class UpgradeScript
/// <summary>
/// Executes the upgrade
/// </summary>
public void Execute()
/// <param name="previousVersion">the previous version</param>
public void Execute(Version previousVersion)
{
if (ShouldRun(previousVersion) == false)
return;
try
{
Logger.ILog($"Running upgrade {Name}");
Run();
}
catch (Exception ex)
Expand All @@ -20,6 +24,13 @@ public void Execute()
}
}

/// <summary>
/// Checks if an upgrade script should run
/// </summary>
/// <param name="previousVersion">the previous version</param>
/// <returns>true if should run, otherwise false</returns>
protected abstract bool ShouldRun(Version previousVersion);

/// <summary>
/// Gets tne name of the upgrade script
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions Upgrades/Upgrade_0_9_2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ namespace Fenrus.Upgrades;
/// </summary>
public class Upgrade_0_9_2 : UpgradeScript
{
protected override bool ShouldRun(Version previousVersion)
{
#if(DEBUG)
return previousVersion < new Version(0, 9, 2);
#else
return previousVersion < new Version(0, 9, 2, 947);
#endif
}

/// <summary>
/// Gets tne name of the upgrade script
/// </summary>
Expand All @@ -22,15 +31,21 @@ protected override void Run()
var collection = db.GetCollection<SystemSettings>(nameof(SystemSettings));
var firstItem = collection.FindOne(Query.All());
if (firstItem == null)
{
Logger.ILog("System Settings not found, skipping upgrade");
return;
}

firstItem.CloudFeatures = CloudFeature.Apps | CloudFeature.Calendar | CloudFeature.Notes | CloudFeature.Files;
collection.Update(firstItem);
Logger.ILog("Set System Cloud Features to: " + firstItem.CloudFeatures);

var collUsers = db.GetCollection<UserProfile>();
foreach (var p in collUsers.FindAll())
{
p.CloudFeatures = CloudFeature.Calendar | CloudFeature.Notes | CloudFeature.Files;
collUsers.Update(p);
Logger.ILog($"Set Cloud Features for user '{p.Uid}' to: " + p.CloudFeatures);
}
}
}

0 comments on commit 6f3da12

Please sign in to comment.