Files
Umbraco-CMS/src/Umbraco.Web.Common/Install/InstallController.cs

87 lines
3.4 KiB
C#
Raw Normal View History

2020-04-20 12:20:47 +02:00
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.Extensions;
2020-04-27 10:09:10 +02:00
using Umbraco.Web.Common.Filters;
2020-04-20 12:20:47 +02:00
using Umbraco.Web.Install;
using Umbraco.Web.Security;
2020-04-20 12:20:47 +02:00
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;
2020-05-05 14:28:01 +02:00
private readonly IUmbracoVersion _umbracoVersion;
private readonly IRuntimeMinifier _runtimeMinifier;
public InstallController(
IUmbracoContextAccessor umbracoContextAccessor,
InstallHelper installHelper,
IRuntimeState runtime,
IGlobalSettings globalSettings,
IRuntimeMinifier runtimeMinifier,
2020-05-05 14:28:01 +02:00
IHostingEnvironment hostingEnvironment,
IUmbracoVersion umbracoVersion)
2017-07-20 11:21:28 +02:00
{
_umbracoContextAccessor = umbracoContextAccessor;
_installHelper = installHelper;
_runtime = runtime;
_globalSettings = globalSettings;
_runtimeMinifier = runtimeMinifier;
_hostingEnvironment = hostingEnvironment;
2020-05-05 14:28:01 +02:00
_umbracoVersion = umbracoVersion;
2017-07-20 11:21:28 +02:00
}
[HttpGet]
2020-04-27 10:09:10 +02:00
[StatusCodeResult(System.Net.HttpStatusCode.ServiceUnavailable)]
[TypeFilter(typeof(StatusCodeResultAttribute), Arguments = new object []{System.Net.HttpStatusCode.ServiceUnavailable})]
public ActionResult Index()
{
if (_runtime.Level == RuntimeLevel.Run)
return Redirect(_globalSettings.UmbracoPath.EnsureEndsWith('/'));
2014-02-27 10:16:30 +01:00
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:
2020-04-20 12:20:47 +02:00
return Redirect(_globalSettings.UmbracoPath + "/AuthorizeUpgrade?redir=" + Request.GetEncodedUrl());
}
}
2020-05-05 14:28:01 +02:00
// gen the install base urlAddUmbracoCore
2019-03-28 12:10:59 +01:00
ViewData.SetInstallApiBaseUrl(Url.GetUmbracoApiService("GetSetup", "InstallApi", "UmbracoInstall").TrimEnd("GetSetup"));
// get the base umbraco folder
ViewData.SetUmbracoBaseFolder(_hostingEnvironment.ToAbsolute(_globalSettings.UmbracoPath));
2020-05-05 14:28:01 +02:00
ViewData.SetUmbracoVersion(_umbracoVersion.SemanticVersion);
_installHelper.InstallStatus(false, "");
// always ensure full path (see NOTE in the class remarks)
2020-04-20 12:20:47 +02:00
return View();
}
}
}