Try your search with a different keyword or use * as a wildcard.
using FluentMigrator;
using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Messages;
using Nop.Core.Domain.Orders;
using Nop.Core.Domain.ScheduleTasks;
using Nop.Core.Domain.Security;
using Nop.Core.Domain.Shipping;
using Nop.Data.Mapping;
namespace Nop.Data.Migrations.UpgradeTo450;
[NopUpdateMigration("2021-04-23 00:00:00", "4.50", UpdateMigrationType.Data)]
public class DataMigration : Migration
{
protected readonly INopDataProvider _dataProvider;
public DataMigration(INopDataProvider dataProvider)
{
_dataProvider = dataProvider;
}
///
/// Collect the UP migration expressions
///
public override void Up()
{
// add column
var shipmentTableName = nameof(Shipment);
var collectedDateUtcColumnName = "ReadyForPickupDateUtc";
if (!Schema.Table(shipmentTableName).Column(collectedDateUtcColumnName).Exists())
{
Alter.Table(shipmentTableName)
.AddColumn(collectedDateUtcColumnName).AsDateTime2().Nullable();
}
// add message template
if (!_dataProvider.GetTable().Any(pr => string.Compare(pr.Name, MessageTemplateSystemNames.SHIPMENT_READY_FOR_PICKUP_CUSTOMER_NOTIFICATION, true) == 0))
{
var messageTemplate = _dataProvider.InsertEntity(
new MessageTemplate
{
Name = MessageTemplateSystemNames.SHIPMENT_READY_FOR_PICKUP_CUSTOMER_NOTIFICATION,
Subject = "Your order from %Store.Name% has been %if (!%Order.IsCompletelyReadyForPickup%) partially endif%ready for pickup.",
Body = $"{Environment.NewLine} %Store.Name%{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}Hello %Order.CustomerFullName%!,{Environment.NewLine}
{Environment.NewLine}Good news! You order has been%if (!%Order.IsCompletelyReadyForPickup%) partially endif%ready for pickup.{Environment.NewLine}
{Environment.NewLine}Order Number: %Order.OrderNumber%{Environment.NewLine}
{Environment.NewLine}Order Details: %Order.OrderURLForCustomer%{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% Products ready for pickup:{Environment.NewLine}
{Environment.NewLine}
{Environment.NewLine}%Shipment.Product(s)%{Environment.NewLine}
{Environment.NewLine}",
IsActive = true,
EmailAccountId = _dataProvider.GetTable().FirstOrDefault()?.Id ?? 0
}
);
}
//#5547
var scheduleTaskTableName = NameCompatibilityManager.GetTableName(typeof(ScheduleTask));
//add column
if (!Schema.Table(scheduleTaskTableName).Column(nameof(ScheduleTask.LastEnabledUtc)).Exists())
{
Alter.Table(scheduleTaskTableName)
.AddColumn(nameof(ScheduleTask.LastEnabledUtc)).AsDateTime2().Nullable();
}
else
{
Alter.Table(scheduleTaskTableName).AlterColumn(nameof(ScheduleTask.LastEnabledUtc)).AsDateTime2().Nullable();
}
//#5939
if (!_dataProvider.GetTable().Any(pr => string.Compare(pr.SystemName, "SalesSummaryReport", StringComparison.InvariantCultureIgnoreCase) == 0))
{
var salesSummaryReportPermission = _dataProvider.InsertEntity(
new PermissionRecord
{
Name = "Admin area. Access sales summary report",
SystemName = "SalesSummaryReport",
Category = "Orders"
}
);
//add it to the Admin role by default
var adminRole = _dataProvider
.GetTable()
.FirstOrDefault(x => x.IsSystemRole && x.SystemName == NopCustomerDefaults.AdministratorsRoleName);
_dataProvider.InsertEntity(
new PermissionRecordCustomerRoleMapping
{
CustomerRoleId = adminRole.Id,
PermissionRecordId = salesSummaryReportPermission.Id
}
);
}
//add column
var returnRequestTableName = NameCompatibilityManager.GetTableName(typeof(ReturnRequest));
var returnedQuantityColumnName = "ReturnedQuantity";
if (!Schema.Table(returnRequestTableName).Column(returnedQuantityColumnName).Exists())
{
Alter.Table(returnRequestTableName)
.AddColumn(returnedQuantityColumnName).AsInt32().NotNullable().SetExistingRowsTo(0);
}
//#6053
if (!_dataProvider.GetTable().Any(pr => string.Compare(pr.SystemName, "ManageAppSettings", StringComparison.InvariantCultureIgnoreCase) == 0))
{
var manageConnectionStringPermission = _dataProvider.InsertEntity(
new PermissionRecord
{
Name = "Admin area. Manage App Settings",
SystemName = "ManageAppSettings",
Category = "Configuration"
}
);
//add it to the Admin role by default
var adminRole = _dataProvider
.GetTable()
.FirstOrDefault(x => x.IsSystemRole && x.SystemName == NopCustomerDefaults.AdministratorsRoleName);
_dataProvider.InsertEntity(
new PermissionRecordCustomerRoleMapping
{
CustomerRoleId = adminRole.Id,
PermissionRecordId = manageConnectionStringPermission.Id
}
);
}
}
public override void Down()
{
//add the downgrade logic if necessary
}
}