Fixed issue with wrong installId in cookie. + Refactored to not use Newtonsoft.Json + Minor renames

This commit is contained in:
Bjarke Berg
2020-02-19 08:32:47 +01:00
parent a058703004
commit 9ed94f753d
9 changed files with 197 additions and 288 deletions

View File

@@ -6,6 +6,6 @@ namespace Umbraco.Core.Persistence.Repositories
{
public interface IInstallationRepository
{
Task SaveInstall(InstallLog installLog);
Task SaveInstallLogAsync(InstallLog installLog);
}
}

View File

@@ -6,6 +6,6 @@ namespace Umbraco.Core.Persistence.Repositories
{
public interface IUpgradeCheckRepository
{
Task<UpgradeResult> CheckUpgrade(SemVersion version);
Task<UpgradeResult> CheckUpgradeAsync(SemVersion version);
}
}

View File

@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Umbraco.Core.Models;
namespace Umbraco.Core.Persistence.Repositories.Implement
@@ -15,16 +11,14 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
private const string RestApiInstallUrl = "https://our.umbraco.com/umbraco/api/Installation/Install";
public async Task SaveInstall(InstallLog installLog)
public async Task SaveInstallLogAsync(InstallLog installLog)
{
try
{
if (_httpClient == null)
_httpClient = new HttpClient();
var jsonObj = JsonConvert.SerializeObject(installLog);
var content = new StringContent(jsonObj, Encoding.UTF8, "application/json");
await _httpClient.PostAsync(RestApiInstallUrl, content);
await _httpClient.PostAsync(RestApiInstallUrl, installLog, new JsonMediaTypeFormatter());
}
// this occurs if the server for Our is down or cannot be reached
catch (HttpRequestException)

View File

@@ -1,7 +1,6 @@
using System.Net.Http;
using System.Text;
using System.Net.Http.Formatting;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Semver;
using Umbraco.Core.Models;
@@ -13,20 +12,15 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
private const string RestApiUpgradeChecklUrl = "https://our.umbraco.com/umbraco/api/UpgradeCheck/CheckUpgrade";
public async Task<UpgradeResult> CheckUpgrade(SemVersion version)
public async Task<UpgradeResult> CheckUpgradeAsync(SemVersion version)
{
try
{
if (_httpClient == null)
_httpClient = new HttpClient();
var jsonObj = new { VersionMajor = version.Major, VersionMinor = version.Minor, VersionPatch = version.Patch, VersionComment = version.Prerelease };
var json = JsonConvert.SerializeObject(jsonObj);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var task = await _httpClient.PostAsync(RestApiUpgradeChecklUrl, content);
var jsonResponse = await task.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<UpgradeResult>(jsonResponse);
var task = await _httpClient.PostAsync(RestApiUpgradeChecklUrl, new CheckUpgradeDto(version), new JsonMediaTypeFormatter());
var result = await task.Content.ReadAsAsync<UpgradeResult>();
return result ?? new UpgradeResult("None", "", "");
}
@@ -36,5 +30,20 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
return new UpgradeResult("None", "", "");
}
}
private class CheckUpgradeDto
{
public CheckUpgradeDto(SemVersion version)
{
VersionMajor = version.Major;
VersionMinor = version.Minor;
VersionPatch = version.Patch;
VersionComment = version.Prerelease;
}
public int VersionMajor { get; }
public int VersionMinor { get; }
public int VersionPatch { get; }
public string VersionComment { get; }
}
}
}

View File

@@ -5,6 +5,6 @@ namespace Umbraco.Core.Services
{
public interface IInstallationService
{
Task Install(InstallLog installLog);
Task LogInstall(InstallLog installLog);
}
}

View File

@@ -13,9 +13,9 @@ namespace Umbraco.Core.Services.Implement
_installationRepository = installationRepository;
}
public async Task Install(InstallLog installLog)
public async Task LogInstall(InstallLog installLog)
{
await _installationRepository.SaveInstall(installLog);
await _installationRepository.SaveInstallLogAsync(installLog);
}
}
}

View File

@@ -17,7 +17,7 @@ namespace Umbraco.Core
public async Task<UpgradeResult> CheckUpgrade(SemVersion version)
{
return await _upgradeCheckRepository.CheckUpgrade(version);
return await _upgradeCheckRepository.CheckUpgradeAsync(version);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -64,8 +64,12 @@ namespace Umbraco.Web.Install
if (installId == Guid.Empty)
installId = Guid.NewGuid();
}
else
{
installId = Guid.NewGuid(); // Guid.TryParse will have reset installId to Guid.Empty
}
}
_httpContext.Response.Cookies.Set(new HttpCookie(Constants.Web.InstallerCookieName, "1"));
_httpContext.Response.Cookies.Set(new HttpCookie(Constants.Web.InstallerCookieName, installId.ToString()));
var dbProvider = string.Empty;
if (IsBrandNewInstall == false)
@@ -81,7 +85,7 @@ namespace Umbraco.Web.Install
versionComment: UmbracoVersion.Comment, error: errorMsg, userAgent: userAgent,
dbProvider: dbProvider);
await _installationService.Install(installLog);
await _installationService.LogInstall(installLog);
}
catch (Exception ex)
{