Skip to content

Commit

Permalink
Add migration process
Browse files Browse the repository at this point in the history
  • Loading branch information
support committed Sep 30, 2023
1 parent 30b78c2 commit f902675
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Grand.Business.Core.Interfaces.Common.Logging;
using Grand.Business.Core.Utilities.Common.Security;
using Grand.Domain.Admin;
using Grand.Domain.Data;
using Grand.Infrastructure.Migrations;
using Microsoft.Extensions.DependencyInjection;

namespace Grand.Business.System.Services.Migrations._2._2
{
public class MigrationUpdateAdminSiteMap : IMigration
{

public int Priority => 0;
public DbVersion Version => new(2, 2);
public Guid Identity => new("1025D405-FFF3-45E1-A240-2E5F2A92535F");
public string Name => "Update standard admin site map - add admin menu";

/// <summary>
/// Upgrade process
/// </summary>
/// <param name="database"></param>
/// <param name="serviceProvider"></param>
/// <returns></returns>
public bool UpgradeProcess(IDatabaseContext database, IServiceProvider serviceProvider)
{
var repository = serviceProvider.GetRequiredService<IRepository<Domain.Admin.AdminSiteMap>>();
var logService = serviceProvider.GetRequiredService<ILogger>();

try
{
var sitemapSystem = repository.Table.FirstOrDefault(x => x.SystemName == "Configuration");
if (sitemapSystem != null)
{
sitemapSystem.ChildNodes.Add(new AdminSiteMap() {
SystemName = "Admin menu",
ResourceName = "Admin.Configuration.Menu",
PermissionNames = new List<string> { PermissionSystemName.Maintenance },
ControllerName = "Menu",
ActionName = "Index",
DisplayOrder = 7,
IconClass = "fa fa-dot-circle-o"
});
repository.Update(sitemapSystem);
}
}
catch (Exception ex)
{
logService.InsertLog(Domain.Logging.LogLevel.Error, "UpgradeProcess - UpdateAdminSiteMap", ex.Message).GetAwaiter().GetResult();
}
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Grand.Domain.Data;
using Grand.Infrastructure.Migrations;

namespace Grand.Business.System.Services.Migrations._2._2
{
public class MigrationUpdateResourceString : IMigration
{
public int Priority => 0;
public DbVersion Version => new(2, 2);
public Guid Identity => new("40AE285E-247E-4ABA-A892-479F22297580");
public string Name => "Update resource string for english language 2.2";

/// <summary>
/// Upgrade process
/// </summary>
/// <param name="database"></param>
/// <param name="serviceProvider"></param>
/// <returns></returns>
public bool UpgradeProcess(IDatabaseContext database, IServiceProvider serviceProvider)
{
return serviceProvider.ImportLanguageResourcesFromXml("App_Data/Resources/Upgrade/en_220.xml");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Grand.Domain.Common;
using Grand.Domain.Data;
using Grand.Infrastructure;
using Grand.Infrastructure.Migrations;
using Microsoft.Extensions.DependencyInjection;

namespace Grand.Business.System.Services.Migrations._2._2
{
public class MigrationUpgradeDbVersion_22 : IMigration
{

public int Priority => 0;

public DbVersion Version => new(2, 2);

public Guid Identity => new("9B9FD138-7E67-44AA-913B-273F3D5B5DE9");

public string Name => "Upgrade version of the database to 2.2";

/// <summary>
/// Upgrade process
/// </summary>
/// <param name="database"></param>
/// <param name="serviceProvider"></param>
/// <returns></returns>
public bool UpgradeProcess(IDatabaseContext database, IServiceProvider serviceProvider)
{
var repository = serviceProvider.GetRequiredService<IRepository<GrandNodeVersion>>();

var dbversion = repository.Table.ToList().FirstOrDefault();
dbversion.DataBaseVersion = $"{GrandVersion.SupportedDBVersion}";
repository.Update(dbversion);

return true;
}
}
}

0 comments on commit f902675

Please sign in to comment.