Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Infrastructure.Install;
using Umbraco.Cms.Api.Management.ViewModels.Installer;
Expand All @@ -12,16 +13,23 @@ namespace Umbraco.Cms.Api.Management.Controllers.Install;
[ApiVersion("1.0")]
public class SettingsInstallController : InstallControllerBase
{
private readonly InstallHelper _installHelper;
private readonly IInstallSettingsFactory _installSettingsFactory;
private readonly IUmbracoMapper _mapper;

[Obsolete("Please use the constructor without the InstallHelper parameter. Scheduled for removal in Umbraco 19.")]
public SettingsInstallController(
InstallHelper installHelper,
IInstallSettingsFactory installSettingsFactory,
IUmbracoMapper mapper)
: this(installSettingsFactory, mapper)
{
}

[ActivatorUtilitiesConstructor]
public SettingsInstallController(
IInstallSettingsFactory installSettingsFactory,
IUmbracoMapper mapper)
{
_installHelper = installHelper;
_installSettingsFactory = installSettingsFactory;
_mapper = mapper;
}
Expand All @@ -32,9 +40,6 @@ public SettingsInstallController(
[ProducesResponseType(typeof(InstallSettingsResponseModel), StatusCodes.Status200OK)]
public async Task<IActionResult> Settings(CancellationToken cancellationToken)
{
// Register that the install has started
await _installHelper.SetInstallStatusAsync(false, string.Empty);

InstallSettingsModel installSettings = _installSettingsFactory.GetInstallSettings();
InstallSettingsResponseModel responseModel = _mapper.Map<InstallSettingsResponseModel>(installSettings)!;

Expand Down
1 change: 1 addition & 0 deletions src/Umbraco.Core/Constants-Web.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static class Web
/// </summary>
public const string AcceptPreviewCookieName = "UMB-WEBSITE-PREVIEW-ACCEPT";

[Obsolete("InstallerCookieName is no longer used and will be removed in Umbraco 19.")]
public const string InstallerCookieName = "umb_installId";

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace Umbraco.Cms.Core.Persistence.Repositories;

[Obsolete("Installation logging is no longer supported and this interface will be removed in Umbraco 19.")]
public interface IInstallationRepository
{
[Obsolete("This method no longer has any function and will be removed in Umbraco 19.")]
Task SaveInstallLogAsync(InstallLog installLog);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,15 @@

namespace Umbraco.Cms.Core.Persistence.Repositories;

[Obsolete("Installation logging is no longer supported and this class will be removed in Umbraco 19.")]
public class InstallationRepository : IInstallationRepository
{
private const string RestApiInstallUrl = "https://our.umbraco.com/umbraco/api/Installation/Install";
private static HttpClient? _httpClient;
private readonly IJsonSerializer _jsonSerializer;

public InstallationRepository(IJsonSerializer jsonSerializer) => _jsonSerializer = jsonSerializer;

public async Task SaveInstallLogAsync(InstallLog installLog)
public InstallationRepository(IJsonSerializer jsonSerializer)
{
try
{
if (_httpClient == null)
{
_httpClient = new HttpClient();
}

using var content = new StringContent(_jsonSerializer.Serialize(installLog), Encoding.UTF8, "application/json");

await _httpClient.PostAsync(RestApiInstallUrl, content);
}

// this occurs if the server for Our is down or cannot be reached
catch (HttpRequestException)
{
}
}

[Obsolete("This method no longer has any function and will be removed in Umbraco 19.")]
public Task SaveInstallLogAsync(InstallLog installLog) => Task.CompletedTask;
}
81 changes: 4 additions & 77 deletions src/Umbraco.Infrastructure/Install/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Infrastructure.Migrations.Install;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Extensions;
using Constants = Umbraco.Cms.Core.Constants;

namespace Umbraco.Cms.Infrastructure.Install
{
[Obsolete("InstallHelper is no longer used internally and will be removed in Umbraco 19.")]
public sealed class InstallHelper
{
private readonly DatabaseBuilder _databaseBuilder;
private readonly ILogger<InstallHelper> _logger;
private readonly IUmbracoVersion _umbracoVersion;
private readonly IOptionsMonitor<ConnectionStrings> _connectionStrings;
private readonly IInstallationService _installationService;
private readonly ICookieManager _cookieManager;
private readonly IUserAgentProvider _userAgentProvider;
private readonly IUmbracoDatabaseFactory _umbracoDatabaseFactory;
private readonly IFireAndForgetRunner _fireAndForgetRunner;
private readonly IEnumerable<IDatabaseProviderMetadata> _databaseProviderMetadata;

public InstallHelper(
DatabaseBuilder databaseBuilder,
Expand All @@ -38,74 +27,12 @@ public InstallHelper(
IFireAndForgetRunner fireAndForgetRunner,
IEnumerable<IDatabaseProviderMetadata> databaseProviderMetadata)
{
_logger = logger;
_umbracoVersion = umbracoVersion;
_databaseBuilder = databaseBuilder;
_connectionStrings = connectionStrings;
_installationService = installationService;
_cookieManager = cookieManager;
_userAgentProvider = userAgentProvider;
_umbracoDatabaseFactory = umbracoDatabaseFactory;
_fireAndForgetRunner = fireAndForgetRunner;
_databaseProviderMetadata = databaseProviderMetadata;
}

public Task SetInstallStatusAsync(bool isCompleted, string errorMsg)
{
try
{
var userAgent = _userAgentProvider.GetUserAgent();

// Check for current install ID
var installCookie = _cookieManager.GetCookieValue(Constants.Web.InstallerCookieName);
if (!Guid.TryParse(installCookie, out Guid installId))
{
installId = Guid.NewGuid();

_cookieManager.SetCookieValue(Constants.Web.InstallerCookieName, installId.ToString(), false, false, "Unspecified");
}

var dbProvider = string.Empty;
if (IsBrandNewInstall == false)
{
// we don't have DatabaseProvider anymore... doing it differently
//dbProvider = ApplicationContext.Current.DatabaseContext.DatabaseProvider.ToString();
dbProvider = _umbracoDatabaseFactory.SqlContext.SqlSyntax.DbProvider;
}

var installLog = new InstallLog(
installId: installId,
isUpgrade: IsBrandNewInstall == false,
installCompleted: isCompleted,
timestamp: DateTime.Now,
versionMajor: _umbracoVersion.Version.Major,
versionMinor: _umbracoVersion.Version.Minor,
versionPatch: _umbracoVersion.Version.Build,
versionComment: _umbracoVersion.Comment,
error: errorMsg,
userAgent: userAgent,
dbProvider: dbProvider);

_fireAndForgetRunner.RunFireAndForget(() => _installationService.LogInstall(installLog));
}
catch (Exception ex)
{
_logger.LogError(ex, "An error occurred in InstallStatus trying to check upgrades");
}

return Task.CompletedTask;
}

/// <summary>
/// Checks if this is a brand new install, meaning that there is no configured database connection or the database is empty.
/// This method used to send installer telemetry to Our.Umbraco.com but no longer does anything and will be removed in Umbraco 19.
/// </summary>
/// <value>
/// <c>true</c> if this is a brand new install; otherwise, <c>false</c>.
/// </value>
private bool IsBrandNewInstall =>
_connectionStrings.CurrentValue.IsConnectionStringConfigured() == false ||
_databaseBuilder.IsDatabaseConfigured == false ||
(_databaseBuilder.CanConnectToDatabase == false && _databaseProviderMetadata.CanForceCreateDatabase(_umbracoDatabaseFactory)) ||
_databaseBuilder.IsUmbracoInstalled() == false;
[Obsolete("SetInstallStatusAsync no longer has any function and will be removed in Umbraco 19.")]
public Task SetInstallStatusAsync(bool isCompleted, string errorMsg) => Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ namespace Umbraco.Cms.Infrastructure.Installer.Steps;

public class RegisterInstallCompleteStep : StepBase, IInstallStep, IUpgradeStep
{
private readonly InstallHelper _installHelper;
[Obsolete("Please use the constructor without parameters. Scheduled for removal in Umbraco 19.")]
public RegisterInstallCompleteStep(InstallHelper installHelper)
: this()
{
}

public RegisterInstallCompleteStep(InstallHelper installHelper) => _installHelper = installHelper;
public RegisterInstallCompleteStep()
{
}

public Task<Attempt<InstallationResult>> ExecuteAsync(InstallData _) => Execute();

public Task<Attempt<InstallationResult>> ExecuteAsync() => Execute();

private async Task<Attempt<InstallationResult>> Execute()
{
await _installHelper.SetInstallStatusAsync(true, string.Empty);
return Success();
}
private Task<Attempt<InstallationResult>> Execute() => Task.FromResult(Success());

public Task<bool> RequiresExecutionAsync(InstallData _) => ShouldExecute();

Expand Down
Loading