AB#6233 - Install in .NET Core
This commit is contained in:
78
src/Umbraco.Web.Common/Install/InstallController.cs
Normal file
78
src/Umbraco.Web.Common/Install/InstallController.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.WebAssets;
|
||||
using Umbraco.Web.Install;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Web.Common.Install
|
||||
{
|
||||
/// <summary>
|
||||
/// The MVC Installation controller
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// NOTE: All views must have their full paths as we do not have a custom view engine for the installation views!
|
||||
/// </remarks>
|
||||
[InstallAuthorize]
|
||||
public class InstallController : Controller
|
||||
{
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly InstallHelper _installHelper;
|
||||
private readonly IRuntimeState _runtime;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IRuntimeMinifier _runtimeMinifier;
|
||||
|
||||
public InstallController(
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
InstallHelper installHelper,
|
||||
IRuntimeState runtime,
|
||||
IGlobalSettings globalSettings,
|
||||
IRuntimeMinifier runtimeMinifier,
|
||||
IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_installHelper = installHelper;
|
||||
_runtime = runtime;
|
||||
_globalSettings = globalSettings;
|
||||
_runtimeMinifier = runtimeMinifier;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
// [StatusCodeResult(System.Net.HttpStatusCode.ServiceUnavailable)] //TODO reintroduce
|
||||
public ActionResult Index()
|
||||
{
|
||||
if (_runtime.Level == RuntimeLevel.Run)
|
||||
return Redirect(_globalSettings.UmbracoPath.EnsureEndsWith('/'));
|
||||
|
||||
if (_runtime.Level == RuntimeLevel.Upgrade)
|
||||
{
|
||||
// Update ClientDependency version and delete its temp directories to make sure we get fresh caches
|
||||
_runtimeMinifier.Reset();
|
||||
|
||||
var result = _umbracoContextAccessor.UmbracoContext.Security.ValidateCurrentUser(false);
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case ValidateRequestAttempt.FailedNoPrivileges:
|
||||
case ValidateRequestAttempt.FailedNoContextId:
|
||||
return Redirect(_globalSettings.UmbracoPath + "/AuthorizeUpgrade?redir=" + Request.GetEncodedUrl());
|
||||
}
|
||||
}
|
||||
|
||||
// gen the install base url
|
||||
ViewData.SetInstallApiBaseUrl(Url.GetUmbracoApiService("GetSetup", "InstallApi", "UmbracoInstall").TrimEnd("GetSetup"));
|
||||
|
||||
// get the base umbraco folder
|
||||
ViewData.SetUmbracoBaseFolder(_hostingEnvironment.ToAbsolute(_globalSettings.UmbracoPath));
|
||||
|
||||
_installHelper.InstallStatus(false, "");
|
||||
|
||||
// always ensure full path (see NOTE in the class remarks)
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user