public void InstallOrUpdate() { _persistenceInstaller.InstallOrUpdate(); Database database = _databaseFactory.Get(); int currentVersion = database.ExecuteScalar <int>("SELECT SpecialActionsVersion FROM TeaCommerce_Version"); int newVersion = 5; while (currentVersion < newVersion) { try { #region 2.1.0 if (currentVersion + 1 == 1) { #region Auto set current cart and order number for all stores foreach (Store store in _storeService.GetAll()) { store.CurrentCartNumber = database.ExecuteScalar <long>("SELECT COUNT(Id) FROM TeaCommerce_Order WHERE StoreId=@0", store.Id); store.CurrentOrderNumber = database.ExecuteScalar <long>("SELECT COUNT(Id) FROM TeaCommerce_Order WHERE StoreId=@0 AND DateFinalized IS NOT NULL", store.Id); store.Save(); } #endregion } #endregion #region 2.1.1 if (currentVersion + 1 == 2) { #region Correct wrong order properties for sage pay orders foreach (Store store in _storeService.GetAll()) { List <long> sagePayPaymentMethodIds = _paymentMethodService.GetAll(store.Id).Where(p => p.PaymentProviderAlias == "SagePay").Select(p => p.Id).ToList(); if (sagePayPaymentMethodIds.Any()) { IEnumerable <Order> orders = _orderService.Get(store.Id, database.Fetch <Guid>("SELECT Id FROM TeaCommerce_Order WHERE StoreId=@0 AND PaymentMethodId IN (" + string.Join(",", sagePayPaymentMethodIds) + ")", store.Id)); foreach (Order order in orders) { CustomProperty vendorTxCode = order.Properties.Get("VendorTxCode"); CustomProperty txAuthNo = order.Properties.Get("TxAuthNo"); if (vendorTxCode == null && txAuthNo == null) { continue; } if (vendorTxCode != null) { vendorTxCode.Alias = "vendorTxCode"; } if (txAuthNo != null) { txAuthNo.Alias = "txAuthNo"; } order.Save(); } } } #endregion } #endregion #region 2.2 if (currentVersion + 1 == 3) { //Had to remove the deletion of TeaCommerce.PaymentProviders.dll and TeaCommerce.PaymentProviders.XmlSerializers.dll } #endregion #region 2.3.2 if (currentVersion + 1 == 3) { #region Remove order xml cache because properties was wrongly serialized string teaCommerceAppDataPath = HostingEnvironment.MapPath("~/App_Data/tea-commerce"); if (teaCommerceAppDataPath != null) { DirectoryInfo teaCommerceAppDataFolder = new DirectoryInfo(teaCommerceAppDataPath); if (teaCommerceAppDataFolder.Exists) { foreach (FileInfo orderXmlCache in teaCommerceAppDataFolder.GetFiles("finalized-orders-xml-cache*")) { orderXmlCache.Delete(); } } } #endregion } #endregion #region 3.0.0 if (currentVersion + 1 == 4) { #region Remove old javascript API file string javaScriptApiFile = HostingEnvironment.MapPath("~/scripts/tea-commerce.min.js"); if (javaScriptApiFile != null && File.Exists(javaScriptApiFile)) { File.Delete(javaScriptApiFile); } #endregion #region Remove old Tea Commerce folder in Umbraco plugins string oldTeaCommercePluginPath = HostingEnvironment.MapPath("~/umbraco/plugins/tea-commerce"); if (oldTeaCommercePluginPath != null && Directory.Exists(oldTeaCommercePluginPath)) { Directory.Delete(oldTeaCommercePluginPath, true); } oldTeaCommercePluginPath = HostingEnvironment.MapPath("~/App_Plugins/tea-commerce"); if (oldTeaCommercePluginPath != null && Directory.Exists(oldTeaCommercePluginPath)) { Directory.Delete(oldTeaCommercePluginPath, true); } #endregion #region Create default gift card settings foreach (Store store in _storeService.GetAll()) { store.GiftCardSettings.Length = 10; store.GiftCardSettings.DaysValid = 1095; store.Save(); } #endregion } #endregion currentVersion++; database.Execute("UPDATE TeaCommerce_Version SET SpecialActionsVersion=@0", currentVersion); } catch (Exception exp) { LoggingService.Instance.Log(exp); break; } } }
public void InstallOrUpdate() { _persistenceInstaller.InstallOrUpdate(); Database database = _databaseFactory.Get(); int currentVersion = database.ExecuteScalar <int>("SELECT SpecialActionsVersion FROM TeaCommerce_Version"); int stepTargetVersion = 0; int targetVersion = 5; // Loop from the current version to the target version // one step at a time, performing any upgrade steps. // At each step we also update the SpecialActionsVersion // in the TeaCommerce_Version database table. // If any step fails, we log the failure, but carry on // to the next step. while (currentVersion < targetVersion) { try { stepTargetVersion = currentVersion + 1; #region Initial install if (currentVersion == 0) { foreach (IInstallTask installTask in _installTasks) { installTask.Install(); } } #endregion #region 2.1.0 if (stepTargetVersion == 1) { #region Auto set current cart and order number for all stores foreach (Store store in _storeService.GetAll()) { store.CurrentCartNumber = database.ExecuteScalar <long>("SELECT COUNT(Id) FROM TeaCommerce_Order WHERE StoreId=@0", store.Id); store.CurrentOrderNumber = database.ExecuteScalar <long>("SELECT COUNT(Id) FROM TeaCommerce_Order WHERE StoreId=@0 AND DateFinalized IS NOT NULL", store.Id); store.Save(); } #endregion } #endregion #region 2.1.1 if (stepTargetVersion == 2) { #region Correct wrong order properties for sage pay orders foreach (Store store in _storeService.GetAll()) { List <long> sagePayPaymentMethodIds = _paymentMethodService.GetAll(store.Id).Where(p => p.PaymentProviderAlias == "SagePay").Select(p => p.Id).ToList(); if (sagePayPaymentMethodIds.Any()) { IEnumerable <Order> orders = _orderService.Get(store.Id, database.Fetch <Guid>("SELECT Id FROM TeaCommerce_Order WHERE StoreId=@0 AND PaymentMethodId IN (" + string.Join(",", sagePayPaymentMethodIds) + ")", store.Id)); foreach (Order order in orders) { CustomProperty vendorTxCode = order.Properties.Get("VendorTxCode"); CustomProperty txAuthNo = order.Properties.Get("TxAuthNo"); if (vendorTxCode == null && txAuthNo == null) { continue; } if (vendorTxCode != null) { vendorTxCode.Alias = "vendorTxCode"; } if (txAuthNo != null) { txAuthNo.Alias = "txAuthNo"; } order.Save(); } } } #endregion } #endregion #region 2.2 if (stepTargetVersion == 3) { //Had to remove the deletion of TeaCommerce.PaymentProviders.dll and TeaCommerce.PaymentProviders.XmlSerializers.dll } #endregion #region 2.3.2 if (stepTargetVersion == 3) { #region Remove order xml cache because properties was wrongly serialized string teaCommerceAppDataPath = HostingEnvironment.MapPath("~/App_Data/tea-commerce"); if (teaCommerceAppDataPath != null) { DirectoryInfo teaCommerceAppDataFolder = new DirectoryInfo(teaCommerceAppDataPath); if (teaCommerceAppDataFolder.Exists) { foreach (FileInfo orderXmlCache in teaCommerceAppDataFolder.GetFiles("finalized-orders-xml-cache*")) { orderXmlCache.Delete(); } } } #endregion } #endregion #region 3.0.0 if (stepTargetVersion == 4) { #region Remove old javascript API file string javaScriptApiFile = HostingEnvironment.MapPath("~/scripts/tea-commerce.min.js"); if (javaScriptApiFile != null && File.Exists(javaScriptApiFile)) { File.Delete(javaScriptApiFile); } #endregion #region Remove old Tea Commerce folder in Umbraco plugins string oldTeaCommercePluginPath = HostingEnvironment.MapPath("~/umbraco/plugins/tea-commerce"); if (oldTeaCommercePluginPath != null && Directory.Exists(oldTeaCommercePluginPath)) { Directory.Delete(oldTeaCommercePluginPath, true); } oldTeaCommercePluginPath = HostingEnvironment.MapPath("~/App_Plugins/tea-commerce"); if (oldTeaCommercePluginPath != null && Directory.Exists(oldTeaCommercePluginPath)) { Directory.Delete(oldTeaCommercePluginPath, true); } #endregion #region Create default gift card settings foreach (Store store in _storeService.GetAll()) { store.GiftCardSettings.Length = 10; store.GiftCardSettings.DaysValid = 1095; store.Save(); } #endregion } #endregion #region 3.3.0 // We were going to attempt to delete payment provider 3rd party DLL's // but on second thoughs, we decided to leave them and add nodes in the // changelog as it's not detramental if they remain, but could cause // problems if the app pool recycles mid delete // //if ( stepTargetVersion == 6 ) //{ // #region Remove old payment provider dependencies // // The latest payment provider build merges 3rd party dependencies // // into the core payment providers DLL in order to prevent conflicts // var oldPaymentProvider3rdPartyDlls = new string [] { // "Klarna.Checkout.dll", // "Paynova.Api.Client.dll", // "Stripe.net.dll" // }; // foreach (var dll in oldPaymentProvider3rdPartyDlls) // { // var dllPath = HostingEnvironment.MapPath("~/bin/" + dll); // if (dllPath != null && File.Exists(dllPath)) // { // File.Delete(dllPath); // } // } // #endregion //} #endregion database.Execute("UPDATE TeaCommerce_Version SET SpecialActionsVersion=@0", stepTargetVersion); } catch (Exception exp) { LoggingService.Instance.Error <Installer>($"Tea Commerce upgrade step {stepTargetVersion} failed", exp); break; } finally { // Update current version whether a step succeeds or fails currentVersion = stepTargetVersion; } } //Language files new LanguageFileInstallTask("TeaCommerce.Umbraco.Install.Content.Resources.da.xml", "~/umbraco/config/lang/da.xml").Install(); new LanguageFileInstallTask("TeaCommerce.Umbraco.Install.Content.Resources.en.xml", "~/umbraco/config/lang/en.xml").Install(); new LanguageFileInstallTask("TeaCommerce.Umbraco.Install.Content.Resources.en_us.xml", "~/umbraco/config/lang/en_us.xml").Install(); new LanguageFileInstallTask("TeaCommerce.Umbraco.Install.Content.Resources.se.xml", "~/umbraco/config/lang/se.xml").Install(); new UIFileInstallTask("TeaCommerce.Umbraco.Install.Content.XML.UI.xml", "~/umbraco/config/create/UI.xml").Install(); //Fix package file new RemoveOldPackageInstallTask().Install(); }