Skip to content

Commit

Permalink
Merge branch '4.30-bug-fixes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
skoshelev committed May 29, 2020
2 parents 5c6b03d + 65b7388 commit 9f6002d
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 36 deletions.
5 changes: 5 additions & 0 deletions src/Libraries/Nop.Core/Domain/Common/CommonSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,10 @@ public CommonSettings()
/// The length of time, in milliseconds, before the running schedule task times out. Set null to use default value
/// </summary>
public int? ScheduleTaskRunTimeout { get; set; }

/// <summary>
/// Gets or sets the timeout (in milliseconds) before restarting the application; set null to use default value
/// </summary>
public int? RestartTimeout { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Libraries/Nop.Data/Nop.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageReference Include="FluentMigrator.Runner" Version="3.2.6" />
<PackageReference Include="linq2db" Version="2.9.8" />
<PackageReference Include="MySql.Data" Version="8.0.20" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/Libraries/Nop.Services/Common/NopCommonDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public static partial class NopCommonDefaults

#region Maintenance

/// <summary>
/// Gets a default timeout (in milliseconds) before restarting the application
/// </summary>
public static int RestartTimeout => 3000;

/// <summary>
/// Gets a path to the database backup files
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5048,7 +5048,7 @@ protected virtual void InstallOrders()
var fourthCustomerBillingAddress = InsertInstallationData(_addressService.CloneAddress(_addressRepository.ToCachedGetById(fourthCustomer.BillingAddressId)));
var fourthCustomerShippingAddress = InsertInstallationData(_addressService.CloneAddress(_addressRepository.ToCachedGetById(fourthCustomer.ShippingAddressId)));
var fourthCustomerPickupAddress = InsertInstallationData(_addressService.CloneAddress(_addressRepository.ToCachedGetById(fourthCustomer.ShippingAddressId)));

var fourthOrder = new Order
{
StoreId = defaultStore.Id,
Expand Down Expand Up @@ -6127,7 +6127,8 @@ protected virtual void InstallSettings()
EnableHtmlMinification = true,
//we disable bundling out of the box because it requires a lot of server resources
EnableJsBundling = false,
EnableCssBundling = false
EnableCssBundling = false,
RestartTimeout = NopCommonDefaults.RestartTimeout
});

settingService.SaveSetting(new SeoSettings
Expand Down Expand Up @@ -6808,8 +6809,8 @@ protected virtual void InstallSettings()

settingService.SaveSetting(new CookieSettings
{
CompareProductsCookieExpires = 24 *10,
RecentlyViewedProductsCookieExpires = 24 *10,
CompareProductsCookieExpires = 24 * 10,
RecentlyViewedProductsCookieExpires = 24 * 10,
CustomerCookieExpires = 24 * 365
});

Expand Down Expand Up @@ -12613,4 +12614,4 @@ public virtual void InstallSampleData(string defaultUserEmail)

#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,7 @@
<LocaleResource Name="Tooltip2">
<Value>To complete this wizard, you must know some information regarding your database server ("connection string"). Please contact your ISP if necessary. If you're installing on a local machine or server, you might need information from your System Admin.</Value>
</LocaleResource>
<LocaleResource Name="RestartProgress">
<Value>Restarting...</Value>
</LocaleResource>
</Language>
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,29 @@ public virtual IActionResult RestartApplication(string returnUrl = "")
if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
return AccessDeniedView();

//restart application
_webHelper.RestartAppDomain();

//home page
if (string.IsNullOrEmpty(returnUrl))
return RedirectToAction("Index", "Home", new { area = AreaNames.Admin });
returnUrl = Url.Action("Index", "Home", new { area = AreaNames.Admin });

//prevent open redirection attack
if (!Url.IsLocalUrl(returnUrl))
return RedirectToAction("Index", "Home", new { area = AreaNames.Admin });
returnUrl = Url.Action("Index", "Home", new { area = AreaNames.Admin });

return Redirect(returnUrl);
return View("RestartApplication", returnUrl);
}

public virtual IActionResult RestartApplication()
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance) &&
!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
{
return AccessDeniedView();
}

//restart application
_webHelper.RestartAppDomain();

return new EmptyResult();
}

public virtual IActionResult SeNames()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ public virtual IActionResult UploadPluginsAndThemes(IFormFile archivefile)
try
{
if (archivefile == null || archivefile.Length == 0)
{
_notificationService.ErrorNotification(_localizationService.GetResource("Admin.Common.UploadFile"));
return RedirectToAction("List");
}
throw new NopException(_localizationService.GetResource("Admin.Common.UploadFile"));

var descriptors = _uploadService.UploadPluginsAndThemes(archivefile);
var pluginDescriptors = descriptors.OfType<PluginDescriptor>().ToList();
Expand Down Expand Up @@ -190,8 +187,7 @@ public virtual IActionResult UploadPluginsAndThemes(IFormFile archivefile)
var message = string.Format(_localizationService.GetResource("Admin.Configuration.Plugins.Uploaded"), pluginDescriptors.Count, themeDescriptors.Count);
_notificationService.SuccessNotification(message);

//restart application
_webHelper.RestartAppDomain();
return View("RestartApplication", Url.Action("List", "Plugin"));
}
catch (Exception exc)
{
Expand Down Expand Up @@ -316,10 +312,7 @@ public virtual IActionResult ReloadList()
_pluginService.UninstallPlugins();
_pluginService.DeletePlugins();

//restart application
_webHelper.RestartAppDomain();

return RedirectToAction("List");
return View("RestartApplication", Url.Action("List", "Plugin"));
}

[HttpPost, ActionName("List")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@model string

@using Nop.Services.Common
@inject CommonSettings commonSettings

<script>
$(document).ready(function () {
showThrobber('@Html.Raw(JavaScriptEncoder.Default.Encode(T("Admin.Header.RestartApplication.Progress").Text))');
$.ajax({
type: "GET",
url: "@Url.Action("RestartApplication", "Common")",
complete: function() {
window.setTimeout(function () {
window.location.replace('@(!string.IsNullOrEmpty(Model) ? Model : Url.Action("Index", "Home", new { area = AreaNames.Admin }))');
}, @(commonSettings.RestartTimeout ?? NopCommonDefaults.RestartTimeout));
}
});
});
</script>
28 changes: 16 additions & 12 deletions src/Presentation/Nop.Web/Controllers/InstallController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ public virtual IActionResult Index()
ConnectionStringRaw = false,
DataProvider = DataProviderType.SqlServer
};

model.AvailableDataProviders.AddRange(
_locService.GetAvailableProviderTypes()
.OrderBy(v => v.Value)
.Select(pt => new SelectListItem {
.Select(pt => new SelectListItem
{
Value = pt.Key.ToString(),
Text = pt.Value
}));
Expand Down Expand Up @@ -103,7 +104,8 @@ public virtual async Task<IActionResult> Index(InstallModel model)
model.AvailableDataProviders.AddRange(
_locService.GetAvailableProviderTypes()
.OrderBy(v => v.Value)
.Select(pt => new SelectListItem {
.Select(pt => new SelectListItem
{
Value = pt.Key.ToString(),
Text = pt.Value
}));
Expand Down Expand Up @@ -219,11 +221,7 @@ public virtual async Task<IActionResult> Index(InstallModel model)
}
catch { }

//restart application
webHelper.RestartAppDomain();

//Redirect to home page
return RedirectToRoute("Homepage");
return View(new InstallModel { RestartUrl = Url.RouteUrl("Homepage") });

}
catch (Exception exception)
Expand Down Expand Up @@ -257,16 +255,22 @@ public virtual IActionResult ChangeLanguage(string language)
[HttpPost]
[IgnoreAntiforgeryToken]
public virtual IActionResult RestartInstall()
{
if (DataSettingsManager.DatabaseIsInstalled)
return RedirectToRoute("Homepage");

return View("Index", new InstallModel { RestartUrl = Url.Action("Index", "Install") });
}

public virtual IActionResult RestartApplication()
{
if (DataSettingsManager.DatabaseIsInstalled)
return RedirectToRoute("Homepage");

//restart application
var webHelper = EngineContext.Current.Resolve<IWebHelper>();
webHelper.RestartAppDomain();
EngineContext.Current.Resolve<IWebHelper>().RestartAppDomain();

//Redirect to home page
return RedirectToRoute("Homepage");
return new EmptyResult();
}

#endregion
Expand Down
2 changes: 2 additions & 0 deletions src/Presentation/Nop.Web/Models/Install/InstallModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ public InstallModel()

public List<SelectListItem> AvailableDataProviders { get; set; }
public IDictionary<string, string> RawDataSettings => new Dictionary<string, string>();

public string RestartUrl { get; set; }
}
}
24 changes: 21 additions & 3 deletions src/Presentation/Nop.Web/Views/Install/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
$(document).ready(function () {
$('#restart-form').submit(function () {
$("html, body").animate({ scrollTop: 0 }, 400);
showThrobber('@Html.Raw(JavaScriptEncoder.Default.Encode("Restarting..."))');
showThrobber('@Html.Raw(JavaScriptEncoder.Default.Encode(ILS.GetResource("RestartProgress")))');
$('input[type=submit]', this).attr('disabled', 'disabled');
});
});
Expand All @@ -92,7 +92,7 @@
if(!integratedSecurityProviders.includes($(this).val())) {
$('#@Html.IdFor(x => x.IntegratedSecurity)').prop('checked', false);
$('#@Html.IdFor(x => x.IntegratedSecurity)').prop('disabled', true)
toggleSqlAuthenticationType();
} else {
$('#@Html.IdFor(x => x.IntegratedSecurity)').prop('disabled', false)
Expand All @@ -112,7 +112,7 @@
}
function toggleCollation() {
var connectionStringRaw = $("#@Html.IdFor(x => x.UseCustomCollation)").is(':checked');
var collationInput = $("#@Html.IdFor(x => x.Collation)")
if (connectionStringRaw) {
Expand All @@ -121,6 +121,24 @@
collationInput.hide();
}
}
@if (!string.IsNullOrEmpty(Model.RestartUrl))
{
<text>
$(document).ready(function () {
showThrobber('@Html.Raw(JavaScriptEncoder.Default.Encode(ILS.GetResource("RestartProgress")))');
$.ajax({
type: "GET",
url: "@Url.Action("RestartApplication", "Install")",
complete: function() {
window.setTimeout(function () {
window.location.replace('@Model.RestartUrl');
}, @NopCommonDefaults.RestartTimeout);
}
});
});
</text>
}
</script>

<div class="form-horizontal">
Expand Down
1 change: 1 addition & 0 deletions src/Presentation/Nop.Web/Views/Install/_ViewImports.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
@inject IInstallationLocalizationService ILS

@using Nop.Data
@using Nop.Services.Common
@using Nop.Web.Models.Install
@using Nop.Web.Infrastructure.Installation
8 changes: 8 additions & 0 deletions upgradescripts/4.20-4.30 (under development)/upgrade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3299,4 +3299,12 @@ BEGIN
INSERT [Setting] ([Name], [Value], [StoreId])
VALUES (N'avalarataxsettings.enablelogging', N'True', 0)
END
GO

--new setting
IF NOT EXISTS (SELECT 1 FROM [Setting] WHERE [Name] = N'commonsettings.restarttimeout')
BEGIN
INSERT [Setting] ([Name], [Value], [StoreId])
VALUES (N'commonsettings.restarttimeout', N'3000', 0)
END
GO

0 comments on commit 9f6002d

Please sign in to comment.