Try your search with a different keyword or use * as a wildcard.
using FluentMigrator;
using LinqToDB;
using Nop.Core.Domain.Logging;
using Nop.Core.Domain.Messages;
namespace Nop.Data.Migrations.UpgradeTo490;
[NopUpdateMigration("2024-12-25 00:00:00", "4.90", UpdateMigrationType.Data)]
public class DataMigration : Migration
{
private readonly INopDataProvider _dataProvider;
public DataMigration(INopDataProvider dataProvider)
{
_dataProvider = dataProvider;
}
///
/// Collect the UP migration expressions
///
public override void Up()
{
//#3425
if (!_dataProvider.GetTable().Any(st => string.Compare(st.Name, MessageTemplateSystemNames.ORDER_COMPLETED_STORE_OWNER_NOTIFICATION, StringComparison.InvariantCultureIgnoreCase) == 0))
{
var eaGeneral = _dataProvider.GetTable().FirstOrDefault() ?? throw new Exception("Default email account cannot be loaded");
_dataProvider.InsertEntity(new MessageTemplate()
{
Name = MessageTemplateSystemNames.ORDER_COMPLETED_STORE_OWNER_NOTIFICATION,
Subject = "%Store.Name%. Order #%Order.OrderNumber% completed",
Body = $"{Environment.NewLine}%Store.Name%{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}%Order.CustomerFullName% has just completed an order. Below is the summary of the order.{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}Order Number: %Order.OrderNumber%{Environment.NewLine}
{Environment.NewLine}Date Ordered: %Order.CreatedOn%{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}Billing Address{Environment.NewLine}
{Environment.NewLine}%Order.BillingFirstName% %Order.BillingLastName%{Environment.NewLine}
{Environment.NewLine}%Order.BillingAddress1%{Environment.NewLine}
{Environment.NewLine}%Order.BillingAddress2%{Environment.NewLine}
{Environment.NewLine}%Order.BillingCity% %Order.BillingZipPostalCode%{Environment.NewLine}
{Environment.NewLine}%Order.BillingStateProvince% %Order.BillingCountry%{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}%if (%Order.Shippable%) Shipping Address{Environment.NewLine}
{Environment.NewLine}%Order.ShippingFirstName% %Order.ShippingLastName%{Environment.NewLine}
{Environment.NewLine}%Order.ShippingAddress1%{Environment.NewLine}
{Environment.NewLine}%Order.ShippingAddress2%{Environment.NewLine}
{Environment.NewLine}%Order.ShippingCity% %Order.ShippingZipPostalCode%{Environment.NewLine}
{Environment.NewLine}%Order.ShippingStateProvince% %Order.ShippingCountry%{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}Shipping Method: %Order.ShippingMethod%{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine} endif% %Order.Product(s)%{Environment.NewLine}
{Environment.NewLine}",
IsActive = false, //this template is disabled by default
EmailAccountId = eaGeneral.Id
});
}
var activityLogTypeTable = _dataProvider.GetTable();
//#6407
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "PublicStore.PasswordChanged", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "PublicStore.PasswordChanged",
Enabled = true,
Name = "Public store. Change password"
}
);
}
//#6874 Multiple newsletter lists
var newsLetterSubscriptionTypeTable = _dataProvider.GetTable();
if (!newsLetterSubscriptionTypeTable.Any(alt => string.Compare(alt.Name, "Newsletter", StringComparison.InvariantCultureIgnoreCase) == 0))
{
var subscriptionType = _dataProvider.InsertEntity(
new NewsLetterSubscriptionType
{
Name = "Newsletter",
TickedByDefault = true,
DisplayOrder = 0
}
);
_dataProvider.GetTable()
.Set(p => p.TypeId, subscriptionType.Id)
.Update();
}
//alter columns
Alter.Table(nameof(NewsLetterSubscription))
.AlterColumn(nameof(NewsLetterSubscription.TypeId)).AsInt32().NotNullable();
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "AddSubscriptionType", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "AddSubscriptionType",
Enabled = true,
Name = "Add a new subscription type"
}
);
}
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "DeleteSubscriptionType", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "DeleteSubscriptionType",
Enabled = true,
Name = "Delete a subscription type"
}
);
}
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "EditSubscriptionType", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "EditSubscriptionType",
Enabled = true,
Name = "Edit a subscription type"
}
);
}
//#1779
if (activityLogTypeTable.FirstOrDefault(alt => string.Compare(alt.SystemKeyword, "PublicStore.Login", StringComparison.InvariantCultureIgnoreCase) == 0)
is ActivityLogType loginActivity)
{
loginActivity.SystemKeyword = "PublicStore.SuccessfulLogin";
_dataProvider.UpdateEntity(loginActivity);
}
else
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "PublicStore.SuccessfulLogin",
Enabled = false,
Name = "Public store. Successful login"
}
);
}
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "PublicStore.FailedLogin", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "PublicStore.FailedLogin",
Enabled = false,
Name = "Public store. Failed login"
}
);
}
if (!_dataProvider.GetTable().Any(st => string.Compare(st.Name, MessageTemplateSystemNames.CUSTOMER_FAILED_LOGIN_ATTEMPT_NOTIFICATION, StringComparison.InvariantCultureIgnoreCase) == 0))
{
var eaGeneral = _dataProvider.GetTable().FirstOrDefault() ?? throw new Exception("Default email account cannot be loaded");
_dataProvider.InsertEntity(new MessageTemplate()
{
Name = MessageTemplateSystemNames.CUSTOMER_FAILED_LOGIN_ATTEMPT_NOTIFICATION,
Subject = "%Store.Name%. Failed Login Attempt",
Body = $"{Environment.NewLine}You have received this notification because we registered a login attempt with invalid authentication on %Store.Name%.{Environment.NewLine}
{Environment.NewLine}",
IsActive = true,
EmailAccountId = eaGeneral.Id
});
}
//#7411
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "AddNewFilterLevelValue", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "AddNewFilterLevelValue",
Enabled = true,
Name = "Add a new filter level value"
}
);
}
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "EditFilterLevelValue", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "EditFilterLevelValue",
Enabled = true,
Name = "Edit a filter level value"
}
);
}
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "DeleteFilterLevelValue", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "DeleteFilterLevelValue",
Enabled = true,
Name = "Delete a filter level value"
}
);
}
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "ExportFilterLevelValues", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "ExportFilterLevelValues",
Enabled = true,
Name = "Export filter level values"
}
);
}
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "ImportFilterLevelValues", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "ImportFilterLevelValues",
Enabled = true,
Name = "Import filter level values"
}
);
}
//#7390
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "AddNewMenu", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "AddNewMenu",
Enabled = true,
Name = "Add a new menu"
}
);
}
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "DeleteMenu", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "DeleteMenu",
Enabled = true,
Name = "Delete a menu"
}
);
}
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "EditMenu", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "EditMenu",
Enabled = true,
Name = "Edit a menu"
}
);
}
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "AddNewMenuItem", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "AddNewMenuItem",
Enabled = true,
Name = "Add a new menu item"
}
);
}
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "DeleteMenuItem", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "DeleteMenuItem",
Enabled = true,
Name = "Delete a menu item"
}
);
}
if (!activityLogTypeTable.Any(alt => string.Compare(alt.SystemKeyword, "EditMenuItem", StringComparison.InvariantCultureIgnoreCase) == 0))
{
_dataProvider.InsertEntity(
new ActivityLogType
{
SystemKeyword = "EditMenuItem",
Enabled = true,
Name = "Edit a menu item"
}
);
}
//#7384
if (!_dataProvider.GetTable().Any(st => string.Compare(st.Name, MessageTemplateSystemNames.ORDER_CANCELLED_STORE_OWNER_NOTIFICATION, StringComparison.InvariantCultureIgnoreCase) == 0))
{
var eaGeneral = _dataProvider.GetTable().FirstOrDefault() ?? throw new Exception("Default email account cannot be loaded");
_dataProvider.InsertEntity(new MessageTemplate
{
Name = MessageTemplateSystemNames.ORDER_CANCELLED_STORE_OWNER_NOTIFICATION,
Subject = "%Store.Name%. Order #%Order.OrderNumber% cancelled",
Body = $"{Environment.NewLine}%Store.Name%{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}Order #%Order.OrderNumber% has been cancelled by customer.{Environment.NewLine}
{Environment.NewLine}Customer: %Order.CustomerFullName%,{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}Order Number: %Order.OrderNumber%{Environment.NewLine}
{Environment.NewLine}Date Ordered: %Order.CreatedOn%{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}%Order.Product(s)%{Environment.NewLine}
{Environment.NewLine}",
IsActive = true,
EmailAccountId = eaGeneral.Id
});
}
}
public override void Down()
{
//add the downgrade logic if necessary
}
}