Fix unable to authorize upgrade from versions < 9.3.0 (#12494)

This commit is contained in:
Paul Johnson
2022-06-01 16:26:27 +01:00
committed by GitHub
parent 57babbe441
commit 406576ddfa

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
@@ -126,12 +127,28 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
public async Task<IEnumerable<ITwoFactorLogin>> GetByUserOrMemberKeyAsync(Guid userOrMemberKey)
{
var sql = Sql()
.Select<TwoFactorLoginDto>()
.From<TwoFactorLoginDto>()
.Where<TwoFactorLoginDto>(x => x.UserOrMemberKey == userOrMemberKey);
var dtos = await Database.FetchAsync<TwoFactorLoginDto>(sql);
return dtos.WhereNotNull().Select(Map);
try
{
var sql = Sql()
.Select<TwoFactorLoginDto>()
.From<TwoFactorLoginDto>()
.Where<TwoFactorLoginDto>(x => x.UserOrMemberKey == userOrMemberKey);
var dtos = await Database.FetchAsync<TwoFactorLoginDto>(sql);
return dtos.WhereNotNull().Select(Map);
}
// TODO (v11): Remove these as the table should always exist when upgrading from 10.x
// SQL Server - table doesn't exist, likely upgrading from < 9.3.0.
catch (SqlException ex) when (ex.Number == 208 && ex.Message.Contains(TwoFactorLoginDto.TableName))
{
return Enumerable.Empty<ITwoFactorLogin>();
}
// SQL CE - table doesn't exist, likely upgrading from < 9.3.0.
catch (Exception ex) when (ex.Message.StartsWith("The specified table does not exist"))
{
return Enumerable.Empty<ITwoFactorLogin>();
}
}
}
}