mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
#17850: Include and enable Orchard.Warmup by default
Also update blog and default recipe to set the site base url during setup using the current request information. Work Item: 17850 --HG-- branch : 1.x
This commit is contained in:
@@ -200,6 +200,7 @@
|
||||
<Compile Include="Scheduling\Services\ScheduledTaskManager.cs" />
|
||||
<Compile Include="Scheduling\Services\ScheduledTaskExecutor.cs" />
|
||||
<Compile Include="Scheduling\Models\Task.cs" />
|
||||
<Compile Include="Settings\Commands\SiteSettingsCommands.cs" />
|
||||
<Compile Include="Settings\Models\SiteSettings2Part.cs" />
|
||||
<Compile Include="Settings\Models\SiteSettings2PartRecord.cs" />
|
||||
<Compile Include="Settings\ResourceManifest.cs" />
|
||||
|
@@ -0,0 +1,53 @@
|
||||
using Orchard.Commands;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Settings.Models;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Core.Settings.Commands {
|
||||
public class SiteSettingsCommands : DefaultOrchardCommandHandler {
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly ISiteService _siteService;
|
||||
|
||||
public SiteSettingsCommands(IHttpContextAccessor httpContextAccessor, ISiteService siteService) {
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_siteService = siteService;
|
||||
}
|
||||
|
||||
[OrchardSwitch]
|
||||
public string BaseUrl { get; set; }
|
||||
|
||||
[OrchardSwitch]
|
||||
public bool Force { get; set; }
|
||||
|
||||
[CommandName("site setting set baseurl")]
|
||||
[CommandHelp("site setting set baseurl [/BaseUrl:baseUrl] [/Force:true]\r\n\tSet the 'BaseUrl' site settings. If no base url is provided, " +
|
||||
"use the current request context heuristic to discover the base url. " +
|
||||
"If 'Force' is true, set the site base url even if it is already set. " +
|
||||
"The default behavior is to not override the setting.")]
|
||||
[OrchardSwitches("BaseUrl")]
|
||||
public string SetBaseUrl() {
|
||||
// Don't do anything if set and not forcing
|
||||
if (Force == false && string.IsNullOrEmpty(_siteService.GetSiteSettings().BaseUrl)) {
|
||||
Context.Output.WriteLine(T("'BaseUrl' site setting is already set. Use the 'Force' flag to override."));
|
||||
return null;
|
||||
}
|
||||
|
||||
// Retrieve request URL if BaseUrl not provided as a switch value
|
||||
if (string.IsNullOrEmpty(BaseUrl)) {
|
||||
if (_httpContextAccessor.Current() == null) {
|
||||
Context.Output.WriteLine(T("No HTTP request available to determine the base url of the site"));
|
||||
return null;
|
||||
}
|
||||
var request = _httpContextAccessor.Current().Request;
|
||||
BaseUrl = request.ToApplicationRootUrlString();
|
||||
}
|
||||
|
||||
// Update base url
|
||||
_siteService.GetSiteSettings().As<SiteSettingsPart>().BaseUrl = BaseUrl;
|
||||
Context.Output.WriteLine(T("'BaseUrl' site setting set to '{0}'", BaseUrl));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user