Fix build errors after merge

This commit is contained in:
Nikolaj Geisle
2022-04-05 09:46:47 +02:00
parent a6128bfe8e
commit b6402c4cc8
15 changed files with 66 additions and 50 deletions

View File

@@ -46,7 +46,10 @@ namespace Umbraco.Cms.Core.Cache
{
var payloads = Deserialize(json);
Refresh(payloads);
if (payloads is not null)
{
Refresh(payloads);
}
}
public override void Refresh(JsonPayload[] payloads)
@@ -54,13 +57,15 @@ namespace Umbraco.Cms.Core.Cache
foreach (var payload in payloads)
{
foreach (var alias in GetCacheKeysForAlias(payload.Alias))
{
AppCaches.RuntimeCache.ClearByKey(alias);
}
var macroRepoCache = AppCaches.IsolatedCaches.Get<IMacro>();
Attempt<IAppPolicyCache?> macroRepoCache = AppCaches.IsolatedCaches.Get<IMacro>();
if (macroRepoCache)
{
macroRepoCache.Result.Clear(RepositoryCacheKeys.GetKey<IMacro, int>(payload.Id));
macroRepoCache.Result.Clear(RepositoryCacheKeys.GetKey<IMacro, string>(payload.Alias)); // Repository caching of macro definition by alias
macroRepoCache.Result?.Clear(RepositoryCacheKeys.GetKey<IMacro, int>(payload.Id));
macroRepoCache.Result?.Clear(RepositoryCacheKeys.GetKey<IMacro, string>(payload.Alias)); // Repository caching of macro definition by alias
}
}

View File

@@ -7,8 +7,8 @@ namespace Umbraco.Cms.Core.Persistence.Repositories
[Obsolete("This interface will be merged with IMacroRepository in Umbraco 11")]
public interface IMacroWithAliasRepository : IMacroRepository
{
IMacro GetByAlias(string alias);
IMacro? GetByAlias(string alias);
IEnumerable<IMacro> GetAllByAlias(string[] aliases);
IEnumerable<IMacro>? GetAllByAlias(string[] aliases);
}
}

View File

@@ -29,7 +29,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors
DefaultConfiguration.Add("maxNumber", 0);
}
protected override IDataValueEditor CreateValueEditor() => DataValueEditorFactory.Create<MultipleContentPickerParameterEditor.MultipleContentPickerParamateterValueEditor>(Attribute);
protected override IDataValueEditor CreateValueEditor() => DataValueEditorFactory.Create<MultipleContentPickerParameterEditor.MultipleContentPickerParamateterValueEditor>(Attribute!);
internal class MultipleContentPickerParamateterValueEditor : MultiplePickerParamateterValueEditorBase
{

View File

@@ -31,7 +31,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors
DefaultConfiguration.Add("multiPicker", "1");
}
protected override IDataValueEditor CreateValueEditor() => DataValueEditorFactory.Create<MultipleMediaPickerPropertyValueEditor>(Attribute);
protected override IDataValueEditor CreateValueEditor() => DataValueEditorFactory.Create<MultipleMediaPickerPropertyValueEditor>(Attribute!);
internal class MultipleMediaPickerPropertyValueEditor : MultiplePickerParamateterValueEditorBase
{

View File

@@ -27,7 +27,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors
public abstract string UdiEntityType { get; }
public abstract UmbracoObjectTypes UmbracoObjectType { get; }
public IEnumerable<UmbracoEntityReference> GetReferences(object value)
public IEnumerable<UmbracoEntityReference> GetReferences(object? value)
{
var asString = value is string str ? str : value?.ToString();
@@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors
foreach (var udiStr in asString.Split(','))
{
if (UdiParser.TryParse(udiStr, out Udi udi))
if (UdiParser.TryParse(udiStr, out Udi? udi))
{
yield return new UmbracoEntityReference(udi);
}

View File

@@ -74,7 +74,7 @@ namespace Umbraco.Cms.Core.Services
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
{
return macroWithAliasRepository.GetAllByAlias(aliases);
return macroWithAliasRepository.GetAllByAlias(aliases) ?? Enumerable.Empty<IMacro>();
}
}

View File

@@ -23,7 +23,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
/// </summary>
protected static readonly TimeSpan DefaultDelay = TimeSpan.FromMinutes(3);
private readonly ILogger _logger;
private readonly ILogger? _logger;
private TimeSpan _period;
private readonly TimeSpan _delay;
private Timer? _timer;
@@ -35,7 +35,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
/// <param name="logger">Logger.</param>
/// <param name="period">Timespan representing how often the task should recur.</param>
/// <param name="delay">Timespan representing the initial delay after application start-up before the first run of the task occurs.</param>
protected RecurringHostedServiceBase(ILogger logger, TimeSpan period, TimeSpan delay)
protected RecurringHostedServiceBase(ILogger? logger, TimeSpan period, TimeSpan delay)
{
_logger = logger;
_period = period;

View File

@@ -8,6 +8,7 @@ using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Infrastructure.Migrations.Upgrade;
using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
using Umbraco.Extensions;
@@ -1033,17 +1034,17 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install
alwaysInsert = true;
}
if (!alwaysInsert && installDefaultDataSettings.InstallData == InstallDefaultDataOption.None)
if (!alwaysInsert && installDefaultDataSettings?.InstallData == InstallDefaultDataOption.None)
{
return;
}
if (!alwaysInsert && installDefaultDataSettings.InstallData == InstallDefaultDataOption.Values && !installDefaultDataSettings.Values.InvariantContains(id))
if (!alwaysInsert && installDefaultDataSettings?.InstallData == InstallDefaultDataOption.Values && !installDefaultDataSettings.Values.InvariantContains(id))
{
return;
}
if (!alwaysInsert && installDefaultDataSettings.InstallData == InstallDefaultDataOption.ExceptValues && installDefaultDataSettings.Values.InvariantContains(id))
if (!alwaysInsert && installDefaultDataSettings?.InstallData == InstallDefaultDataOption.ExceptValues && installDefaultDataSettings.Values.InvariantContains(id))
{
return;
}

View File

@@ -108,7 +108,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install
}
public DatabaseSchemaCreator(
IUmbracoDatabase database,
IUmbracoDatabase? database,
ILogger<DatabaseSchemaCreator> logger,
ILoggerFactory loggerFactory,
IUmbracoVersion umbracoVersion,

View File

@@ -70,12 +70,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
return Get(id) != null;
}
public IMacro GetByAlias(string alias)
public IMacro? GetByAlias(string alias)
{
return _macroByAliasCachePolicy.Get(alias, PerformGetByAlias, PerformGetAllByAlias);
}
public IEnumerable<IMacro> GetAllByAlias(string[] aliases)
public IEnumerable<IMacro>? GetAllByAlias(string[] aliases)
{
if (aliases.Any() is false)
{
@@ -85,15 +85,15 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
return _macroByAliasCachePolicy.GetAll(aliases, PerformGetAllByAlias);
}
private IMacro PerformGetByAlias(string alias)
private IMacro? PerformGetByAlias(string? alias)
{
var query = Query<IMacro>().Where(x => x.Alias.Equals(alias));
return PerformGetByQuery(query).FirstOrDefault();
return PerformGetByQuery(query)?.FirstOrDefault();
}
private IEnumerable<IMacro> PerformGetAllByAlias(params string[] aliases)
private IEnumerable<IMacro>? PerformGetAllByAlias(params string[]? aliases)
{
if (aliases.Any() is false)
if (aliases is null || aliases.Any() is false)
{
return base.GetMany();
}

View File

@@ -58,8 +58,8 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
// Ordering is required for paging
sql = sql?.OrderBy<RelationTypeDto>(x => x.Alias);
var pagedResult = _scopeAccessor.AmbientScope.Database.Page<RelationItemDto>(pageIndex + 1, pageSize, sql);
totalRecords = pagedResult.TotalItems;
var pagedResult = _scopeAccessor.AmbientScope?.Database.Page<RelationItemDto>(pageIndex + 1, pageSize, sql);
totalRecords = Convert.ToInt32(pagedResult?.TotalItems);
return pagedResult?.Items.Select(MapDtoToEntity) ?? Enumerable.Empty<RelationItem>();
}

View File

@@ -146,7 +146,7 @@ namespace Umbraco.Cms.Core.PropertyEditors
/// <param name="editorValue"></param>
/// <param name="currentValue"></param>
/// <returns></returns>
public override object FromEditor(ContentPropertyData editorValue, object currentValue)
public override object? FromEditor(ContentPropertyData editorValue, object? currentValue)
{
if (editorValue.Value == null)
return null;
@@ -222,7 +222,7 @@ namespace Umbraco.Cms.Core.PropertyEditors
return grid;
}
private GridValue? DeserializeGridValue(string rawJson, out IEnumerable<GridValue.GridControl>? richTextValues, out IEnumerable<GridValue.GridControl>? mediaValues, out IEnumerable<GridValue.GridControl> macroValues)
private GridValue? DeserializeGridValue(string rawJson, out IEnumerable<GridValue.GridControl>? richTextValues, out IEnumerable<GridValue.GridControl>? mediaValues, out IEnumerable<GridValue.GridControl>? macroValues)
{
var grid = JsonConvert.DeserializeObject<GridValue>(rawJson);
@@ -232,7 +232,7 @@ namespace Umbraco.Cms.Core.PropertyEditors
mediaValues = controls?.Where(x => x.Editor.Alias.ToLowerInvariant() == "media");
// Find all the macros
macroValues = controls.Where(x => x.Editor.Alias.ToLowerInvariant() == "macro");
macroValues = controls?.Where(x => x.Editor.Alias.ToLowerInvariant() == "macro");
return grid;
}
@@ -251,7 +251,7 @@ namespace Umbraco.Cms.Core.PropertyEditors
yield break;
}
DeserializeGridValue(rawJson, out var richTextEditorValues, out var mediaValues, out var macroValues);
DeserializeGridValue(rawJson!, out var richTextEditorValues, out var mediaValues, out var macroValues);
if (richTextEditorValues is not null)
{
@@ -262,12 +262,22 @@ namespace Umbraco.Cms.Core.PropertyEditors
}
}
foreach (var umbracoEntityReference in mediaValues.Where(x => x.Value.HasValues)
.SelectMany(x => _mediaPickerPropertyValueEditor.GetReferences(x.Value["udi"])))
yield return umbracoEntityReference;
if (mediaValues is not null)
{
foreach (var umbracoEntityReference in mediaValues.Where(x => x.Value.HasValues)
.SelectMany(x => _mediaPickerPropertyValueEditor.GetReferences(x.Value["udi"])))
{
yield return umbracoEntityReference;
}
}
foreach (var umbracoEntityReference in _macroParameterParser.FindUmbracoEntityReferencesFromGridControlMacros(macroValues))
yield return umbracoEntityReference;
if (macroValues is not null)
{
foreach (var umbracoEntityReference in _macroParameterParser.FindUmbracoEntityReferencesFromGridControlMacros(macroValues))
{
yield return umbracoEntityReference;
}
}
}
}
}

View File

@@ -225,15 +225,14 @@ namespace Umbraco.Cms.Core.PropertyEditors
/// <returns></returns>
public IEnumerable<UmbracoEntityReference> GetReferences(object? value)
{
var asString = value == null ? string.Empty : value is string str ? str : value.ToString();
var asString = value == null ? string.Empty : value is string str ? str : value.ToString()!;
foreach (var udi in _imageSourceParser.FindUdisFromDataAttributes(asString!))
foreach (var udi in _imageSourceParser.FindUdisFromDataAttributes(asString))
{
yield return new UmbracoEntityReference(udi);
}
IEnumerable<Udi?> udis = _localLinkParser.FindUdisFromLocalLinks(asString!);
foreach (var udi in _localLinkParser.FindUdisFromLocalLinks(asString!))
foreach (var udi in _localLinkParser.FindUdisFromLocalLinks(asString))
{
if (udi is not null)
{

View File

@@ -82,17 +82,17 @@ namespace Umbraco.Cms.Core.Security
return PasswordVerificationResult.Failed;
}
PersistedPasswordSettings deserialized;
PersistedPasswordSettings? deserialized;
try
{
deserialized = _jsonSerializer.Deserialize<PersistedPasswordSettings>(user.PasswordConfig);
deserialized = _jsonSerializer.Deserialize<PersistedPasswordSettings>(user.PasswordConfig ?? string.Empty);
}
catch
{
return PasswordVerificationResult.Failed;
}
if (!LegacyPasswordSecurity.SupportHashAlgorithm(deserialized.HashAlgorithm))
if (deserialized?.HashAlgorithm is null || !LegacyPasswordSecurity.SupportHashAlgorithm(deserialized.HashAlgorithm))
{
return PasswordVerificationResult.Failed;
}

View File

@@ -9,6 +9,7 @@ using Umbraco.Cms.Core.Models.Editors;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.Macros;
using Umbraco.Extensions;
namespace Umbraco.Cms.Infrastructure.Templates
{
@@ -33,11 +34,11 @@ namespace Umbraco.Cms.Infrastructure.Templates
public IEnumerable<UmbracoEntityReference> FindUmbracoEntityReferencesFromEmbeddedMacros(string text)
{
// There may be more than one macro with the same alias on the page so using a tuple
var foundMacros = new List<Tuple<string, Dictionary<string, string>>>();
var foundMacros = new List<Tuple<string?, Dictionary<string, string>>>();
// This legacy ParseMacros() already finds the macros within a Rich Text Editor using regexes
// It seems to lowercase the macro parameter alias - so making the dictionary case insensitive
MacroTagParser.ParseMacros(text, textblock => { }, (macroAlias, macroAttributes) => foundMacros.Add(new Tuple<string, Dictionary<string, string>>(macroAlias, new Dictionary<string, string>(macroAttributes, StringComparer.OrdinalIgnoreCase))));
MacroTagParser.ParseMacros(text, textblock => { }, (macroAlias, macroAttributes) => foundMacros.Add(new Tuple<string?, Dictionary<string, string>>(macroAlias, new Dictionary<string, string>(macroAttributes, StringComparer.OrdinalIgnoreCase))));
foreach (var umbracoEntityReference in GetUmbracoEntityReferencesFromMacros(foundMacros))
{
yield return umbracoEntityReference;
@@ -51,7 +52,7 @@ namespace Umbraco.Cms.Infrastructure.Templates
/// <returns></returns>
public IEnumerable<UmbracoEntityReference> FindUmbracoEntityReferencesFromGridControlMacros(IEnumerable<GridValue.GridControl> macroGridControls)
{
var foundMacros = new List<Tuple<string, Dictionary<string, string>>>();
var foundMacros = new List<Tuple<string?, Dictionary<string, string>>>();
foreach (var macroGridControl in macroGridControls)
{
@@ -60,7 +61,7 @@ namespace Umbraco.Cms.Infrastructure.Templates
// Collect any macro parameters that contain the media udi format
if (gridMacro is not null && gridMacro.MacroParameters is not null && gridMacro.MacroParameters.Any())
{
foundMacros.Add(new Tuple<string, Dictionary<string, string>>(gridMacro.MacroAlias, gridMacro.MacroParameters));
foundMacros.Add(new Tuple<string?, Dictionary<string, string>>(gridMacro.MacroAlias, gridMacro.MacroParameters));
}
}
@@ -70,7 +71,7 @@ namespace Umbraco.Cms.Infrastructure.Templates
}
}
private IEnumerable<UmbracoEntityReference> GetUmbracoEntityReferencesFromMacros(List<Tuple<string, Dictionary<string, string>>> macros)
private IEnumerable<UmbracoEntityReference> GetUmbracoEntityReferencesFromMacros(List<Tuple<string?, Dictionary<string, string>>> macros)
{
if (_macroService is not IMacroWithAliasService macroWithAliasService)
@@ -83,7 +84,7 @@ namespace Umbraco.Cms.Infrastructure.Templates
// Here we are finding the used macros' Udis (there should be a Related Macro relation type - but Relations don't accept 'Macro' as an option)
var foundMacroUmbracoEntityReferences = new List<UmbracoEntityReference>();
// Get all the macro configs in one hit for these unique macro aliases - this is now cached with a custom cache policy
var macroConfigs = macroWithAliasService.GetAll(uniqueMacroAliases.ToArray());
var macroConfigs = macroWithAliasService.GetAll(uniqueMacroAliases.WhereNotNull().ToArray());
foreach (var macro in macros)
{
@@ -116,7 +117,7 @@ namespace Umbraco.Cms.Infrastructure.Templates
var foundUmbracoEntityReferences = new List<UmbracoEntityReference>();
foreach (var parameter in macroConfig.Properties)
{
if (macroParameters.TryGetValue(parameter.Alias, out string parameterValue))
if (macroParameters.TryGetValue(parameter.Alias, out string? parameterValue))
{
var parameterEditorAlias = parameter.EditorAlias;
// Lookup propertyEditor from the registered ParameterEditors with the implmementation to avoid looking up for each parameter
@@ -146,10 +147,10 @@ namespace Umbraco.Cms.Infrastructure.Templates
private class GridMacro
{
[JsonProperty("macroAlias")]
public string MacroAlias { get; set; }
public string? MacroAlias { get; set; }
[JsonProperty("macroParamsDictionary")]
public Dictionary<string, string> MacroParameters { get; set; }
public Dictionary<string, string>? MacroParameters { get; set; }
}
}
}