diff --git a/src/Umbraco.Core/Install/Models/UserModel.cs b/src/Umbraco.Core/Install/Models/UserModel.cs index b4226fa948..392730b3b6 100644 --- a/src/Umbraco.Core/Install/Models/UserModel.cs +++ b/src/Umbraco.Core/Install/Models/UserModel.cs @@ -6,13 +6,13 @@ namespace Umbraco.Cms.Core.Install.Models public class UserModel { [DataMember(Name = "name")] - public string? Name { get; set; } + public string Name { get; set; } = null!; [DataMember(Name = "email")] - public string Email { get; set; } + public string Email { get; set; } = null!; [DataMember(Name = "password")] - public string Password { get; set; } + public string Password { get; set; } = null!; [DataMember(Name = "subscribeToNewsLetter")] public bool SubscribeToNewsLetter { get; set; } diff --git a/src/Umbraco.Core/Models/Entities/EntityBase.cs b/src/Umbraco.Core/Models/Entities/EntityBase.cs index 9461fc1651..57b9eeae1f 100644 --- a/src/Umbraco.Core/Models/Entities/EntityBase.cs +++ b/src/Umbraco.Core/Models/Entities/EntityBase.cs @@ -19,8 +19,8 @@ namespace Umbraco.Cms.Core.Models.Entities private bool _hasIdentity; private int _id; private Guid _key; - private DateTime? _createDate; - private DateTime? _updateDate; + private DateTime _createDate; + private DateTime _updateDate; /// [DataMember] @@ -50,7 +50,7 @@ namespace Umbraco.Cms.Core.Models.Entities /// [DataMember] - public DateTime? CreateDate + public DateTime CreateDate { get => _createDate; set => SetPropertyValueAndDetectChanges(value, ref _createDate, nameof(CreateDate)); @@ -58,7 +58,7 @@ namespace Umbraco.Cms.Core.Models.Entities /// [DataMember] - public DateTime? UpdateDate + public DateTime UpdateDate { get => _updateDate; set => SetPropertyValueAndDetectChanges(value, ref _updateDate, nameof(UpdateDate)); diff --git a/src/Umbraco.Core/Models/IKeyValue.cs b/src/Umbraco.Core/Models/IKeyValue.cs index 767e22a8c3..2a8c6528bf 100644 --- a/src/Umbraco.Core/Models/IKeyValue.cs +++ b/src/Umbraco.Core/Models/IKeyValue.cs @@ -4,7 +4,7 @@ namespace Umbraco.Cms.Core.Models { public interface IKeyValue : IEntity { - string? Identifier { get; set; } + string Identifier { get; set; } string? Value { get; set; } } diff --git a/src/Umbraco.Core/Models/KeyValue.cs b/src/Umbraco.Core/Models/KeyValue.cs index 76f03c2729..4e38ee3390 100644 --- a/src/Umbraco.Core/Models/KeyValue.cs +++ b/src/Umbraco.Core/Models/KeyValue.cs @@ -11,14 +11,14 @@ namespace Umbraco.Cms.Core.Models [DataContract(IsReference = true)] public class KeyValue : EntityBase, IKeyValue, IEntity { - private string? _identifier; + private string _identifier = null!; private string? _value; /// - public string? Identifier + public string Identifier { get => _identifier; - set => SetPropertyValueAndDetectChanges(value, ref _identifier, nameof(Identifier)); + set => SetPropertyValueAndDetectChanges(value, ref _identifier!, nameof(Identifier)); } /// diff --git a/src/Umbraco.Core/Models/Language.cs b/src/Umbraco.Core/Models/Language.cs index aa16262b15..0c2182f1fc 100644 --- a/src/Umbraco.Core/Models/Language.cs +++ b/src/Umbraco.Core/Models/Language.cs @@ -16,13 +16,13 @@ namespace Umbraco.Cms.Core.Models { private readonly GlobalSettings _globalSettings; - private string _isoCode = string.Empty; + private string? _isoCode; private string? _cultureName; private bool _isDefaultVariantLanguage; private bool _mandatory; private int? _fallbackLanguageId; - public Language(GlobalSettings globalSettings, string isoCode) + public Language(GlobalSettings globalSettings, string? isoCode) { IsoCode = isoCode; _globalSettings = globalSettings; @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.Models /// [DataMember] - public string CultureName + public string? CultureName { // CultureInfo.DisplayName is the name in the installed .NET language // .NativeName is the name in culture info's language diff --git a/src/Umbraco.Core/Models/Macro.cs b/src/Umbraco.Core/Models/Macro.cs index acc66b6c38..bccb1bbb83 100644 --- a/src/Umbraco.Core/Models/Macro.cs +++ b/src/Umbraco.Core/Models/Macro.cs @@ -68,8 +68,8 @@ namespace Umbraco.Cms.Core.Models /// /// /// - public Macro(IShortStringHelper shortStringHelper, string @alias, string name, - string macroSource, + public Macro(IShortStringHelper shortStringHelper, string @alias, string? name, + string? macroSource, bool cacheByPage = false, bool cacheByMember = false, bool dontRender = true, diff --git a/src/Umbraco.Core/Models/MacroProperty.cs b/src/Umbraco.Core/Models/MacroProperty.cs index 0c80f68380..659334258e 100644 --- a/src/Umbraco.Core/Models/MacroProperty.cs +++ b/src/Umbraco.Core/Models/MacroProperty.cs @@ -25,7 +25,7 @@ namespace Umbraco.Cms.Core.Models /// /// /// - public MacroProperty(string @alias, string name, int sortOrder, string editorAlias) + public MacroProperty(string @alias, string? name, int sortOrder, string editorAlias) { _alias = alias; _name = name; diff --git a/src/Umbraco.Core/Models/Member.cs b/src/Umbraco.Core/Models/Member.cs index 00d1fe93fe..301e22b458 100644 --- a/src/Umbraco.Core/Models/Member.cs +++ b/src/Umbraco.Core/Models/Member.cs @@ -362,7 +362,7 @@ namespace Umbraco.Cms.Core.Models /// Part of the standard properties collection. /// [DataMember] - public DateTime? LastLoginDate + public DateTime LastLoginDate { get { @@ -398,7 +398,7 @@ namespace Umbraco.Cms.Core.Models /// Part of the standard properties collection. /// [DataMember] - public DateTime? LastPasswordChangeDate + public DateTime LastPasswordChangeDate { get { diff --git a/src/Umbraco.Core/Models/Membership/IMembershipUser.cs b/src/Umbraco.Core/Models/Membership/IMembershipUser.cs index 517416341b..b4a38479f6 100644 --- a/src/Umbraco.Core/Models/Membership/IMembershipUser.cs +++ b/src/Umbraco.Core/Models/Membership/IMembershipUser.cs @@ -25,8 +25,8 @@ namespace Umbraco.Cms.Core.Models.Membership string? Comments { get; set; } bool IsApproved { get; set; } bool IsLockedOut { get; set; } - DateTime? LastLoginDate { get; set; } - DateTime? LastPasswordChangeDate { get; set; } + DateTime LastLoginDate { get; set; } + DateTime LastPasswordChangeDate { get; set; } DateTime LastLockoutDate { get; set; } /// diff --git a/src/Umbraco.Core/Models/ServerRegistration.cs b/src/Umbraco.Core/Models/ServerRegistration.cs index cc86ee6bdd..553460eb5b 100644 --- a/src/Umbraco.Core/Models/ServerRegistration.cs +++ b/src/Umbraco.Core/Models/ServerRegistration.cs @@ -31,7 +31,7 @@ namespace Umbraco.Cms.Core.Models /// The date and time the registration was last accessed. /// A value indicating whether the registration is active. /// A value indicating whether the registration is master. - public ServerRegistration(int id, string? serverAddress, string? serverIdentity, DateTime? registered, DateTime? accessed, bool isActive, bool isSchedulingPublisher) + public ServerRegistration(int id, string? serverAddress, string? serverIdentity, DateTime registered, DateTime accessed, bool isActive, bool isSchedulingPublisher) { UpdateDate = accessed; CreateDate = registered; diff --git a/src/Umbraco.Core/Models/Template.cs b/src/Umbraco.Core/Models/Template.cs index b2e3f16de9..67fdecadfd 100644 --- a/src/Umbraco.Core/Models/Template.cs +++ b/src/Umbraco.Core/Models/Template.cs @@ -22,12 +22,12 @@ namespace Umbraco.Cms.Core.Models : this(shortStringHelper, name, alias, null) { } - public Template(IShortStringHelper shortStringHelper, string? name, string alias, Func? getFileContent) + public Template(IShortStringHelper shortStringHelper, string? name, string? alias, Func? getFileContent) : base(string.Empty, getFileContent) { _shortStringHelper = shortStringHelper; _name = name; - _alias = alias.ToCleanString(shortStringHelper, CleanStringType.UnderscoreAlias); + _alias = alias?.ToCleanString(shortStringHelper, CleanStringType.UnderscoreAlias) ?? string.Empty; _masterTemplateId = new Lazy(() => -1); } diff --git a/src/Umbraco.Core/Persistence/Repositories/IContentTypeRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/IContentTypeRepositoryBase.cs index e7336156de..2a427da9dd 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IContentTypeRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IContentTypeRepositoryBase.cs @@ -11,7 +11,7 @@ namespace Umbraco.Cms.Core.Persistence.Repositories public interface IContentTypeRepositoryBase : IReadWriteQueryRepository, IReadRepository where TItem : IContentTypeComposition { - TItem Get(string alias); + TItem? Get(string alias); IEnumerable> Move(TItem moving, EntityContainer container); /// diff --git a/src/Umbraco.Core/Persistence/Repositories/IKeyValueRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IKeyValueRepository.cs index 94001609d6..c9ee7a9d25 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IKeyValueRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IKeyValueRepository.cs @@ -10,6 +10,6 @@ namespace Umbraco.Cms.Core.Persistence.Repositories /// /// /// - IReadOnlyDictionary? FindByKeyPrefix(string keyPrefix); + IReadOnlyDictionary? FindByKeyPrefix(string keyPrefix); } } diff --git a/src/Umbraco.Core/PropertyEditors/BlockListConfiguration.cs b/src/Umbraco.Core/PropertyEditors/BlockListConfiguration.cs index a8620641c7..c799a00df6 100644 --- a/src/Umbraco.Core/PropertyEditors/BlockListConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/BlockListConfiguration.cs @@ -9,7 +9,7 @@ namespace Umbraco.Cms.Core.PropertyEditors public class BlockListConfiguration { [ConfigurationField("blocks", "Available Blocks", "views/propertyeditors/blocklist/prevalue/blocklist.blockconfiguration.html", Description = "Define the available blocks.")] - public BlockConfiguration[]? Blocks { get; set; } + public BlockConfiguration[] Blocks { get; set; } = null!; [DataContract] public class BlockConfiguration diff --git a/src/Umbraco.Core/Security/IdentityUserLogin.cs b/src/Umbraco.Core/Security/IdentityUserLogin.cs index efe0dcbf66..402660ead9 100644 --- a/src/Umbraco.Core/Security/IdentityUserLogin.cs +++ b/src/Umbraco.Core/Security/IdentityUserLogin.cs @@ -22,7 +22,7 @@ namespace Umbraco.Cms.Core.Security /// /// Initializes a new instance of the class. /// - public IdentityUserLogin(int id, string loginProvider, string providerKey, string userId, DateTime? createDate) + public IdentityUserLogin(int id, string loginProvider, string providerKey, string userId, DateTime createDate) { Id = id; LoginProvider = loginProvider; diff --git a/src/Umbraco.Core/Services/IEntityService.cs b/src/Umbraco.Core/Services/IEntityService.cs index 6d43e37ac5..cb72735c02 100644 --- a/src/Umbraco.Core/Services/IEntityService.cs +++ b/src/Umbraco.Core/Services/IEntityService.cs @@ -116,7 +116,7 @@ namespace Umbraco.Cms.Core.Services /// The object type of the entities. /// The unique identifiers of the entities. /// If is empty, returns all entities. - IEnumerable GetAll(UmbracoObjectTypes objectType, Guid?[] keys); + IEnumerable GetAll(UmbracoObjectTypes objectType, Guid[] keys); /// /// Gets entities of a given object type. diff --git a/src/Umbraco.Core/Services/IKeyValueService.cs b/src/Umbraco.Core/Services/IKeyValueService.cs index 179bbe5580..1ebf6e9728 100644 --- a/src/Umbraco.Core/Services/IKeyValueService.cs +++ b/src/Umbraco.Core/Services/IKeyValueService.cs @@ -19,7 +19,7 @@ namespace Umbraco.Cms.Core.Services /// /// /// - IReadOnlyDictionary FindByKeyPrefix(string keyPrefix); + IReadOnlyDictionary? FindByKeyPrefix(string keyPrefix); /// /// Sets a value. diff --git a/src/Umbraco.Core/Services/ILocalizationService.cs b/src/Umbraco.Core/Services/ILocalizationService.cs index 33caa957eb..09b6a2ad06 100644 --- a/src/Umbraco.Core/Services/ILocalizationService.cs +++ b/src/Umbraco.Core/Services/ILocalizationService.cs @@ -45,7 +45,7 @@ namespace Umbraco.Cms.Core.Services /// /// Id of the /// - IDictionaryItem GetDictionaryItemById(Guid id); + IDictionaryItem? GetDictionaryItemById(Guid id); /// /// Gets a by its key @@ -108,7 +108,7 @@ namespace Umbraco.Cms.Core.Services /// /// Iso Code of the language (ie. en-US) /// - ILanguage GetLanguageByIsoCode(string isoCode); + ILanguage? GetLanguageByIsoCode(string? isoCode); /// /// Gets a language identifier from its ISO code. diff --git a/src/Umbraco.Core/Services/KeyValueService.cs b/src/Umbraco.Core/Services/KeyValueService.cs index f7fe99909c..6c09272c42 100644 --- a/src/Umbraco.Core/Services/KeyValueService.cs +++ b/src/Umbraco.Core/Services/KeyValueService.cs @@ -27,7 +27,7 @@ namespace Umbraco.Cms.Core.Services } /// - public IReadOnlyDictionary FindByKeyPrefix(string keyPrefix) + public IReadOnlyDictionary? FindByKeyPrefix(string keyPrefix) { using (var scope = _scopeProvider.CreateScope(autoComplete: true)) { diff --git a/src/Umbraco.Core/Services/LocalizationService.cs b/src/Umbraco.Core/Services/LocalizationService.cs index c249dd0e0b..d9405ccf2c 100644 --- a/src/Umbraco.Core/Services/LocalizationService.cs +++ b/src/Umbraco.Core/Services/LocalizationService.cs @@ -147,7 +147,7 @@ namespace Umbraco.Cms.Core.Services /// /// Id of the /// - public IDictionaryItem GetDictionaryItemById(Guid id) + public IDictionaryItem? GetDictionaryItemById(Guid id) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -315,8 +315,12 @@ namespace Umbraco.Cms.Core.Services /// /// Iso Code of the language (ie. en-US) /// - public ILanguage GetLanguageByIsoCode(string isoCode) + public ILanguage? GetLanguageByIsoCode(string? isoCode) { + if (isoCode is null) + { + return null; + } using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { return _languageRepository.GetByIsoCode(isoCode); diff --git a/src/Umbraco.Infrastructure/Examine/ExamineIndexModel.cs b/src/Umbraco.Infrastructure/Examine/ExamineIndexModel.cs index ff9f499217..cdff934da0 100644 --- a/src/Umbraco.Infrastructure/Examine/ExamineIndexModel.cs +++ b/src/Umbraco.Infrastructure/Examine/ExamineIndexModel.cs @@ -7,16 +7,16 @@ namespace Umbraco.Cms.Infrastructure.Examine public class ExamineIndexModel { [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "healthStatus")] - public string HealthStatus { get; set; } + public string? HealthStatus { get; set; } [DataMember(Name = "isHealthy")] public bool IsHealthy => HealthStatus == "Healthy"; [DataMember(Name = "providerProperties")] - public IReadOnlyDictionary ProviderProperties { get; set; } + public IReadOnlyDictionary? ProviderProperties { get; set; } [DataMember(Name = "canRebuild")] public bool CanRebuild { get; set; } diff --git a/src/Umbraco.Infrastructure/Examine/RebuildOnStartupHandler.cs b/src/Umbraco.Infrastructure/Examine/RebuildOnStartupHandler.cs index 7ec59e1c2e..9ec145b030 100644 --- a/src/Umbraco.Infrastructure/Examine/RebuildOnStartupHandler.cs +++ b/src/Umbraco.Infrastructure/Examine/RebuildOnStartupHandler.cs @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Infrastructure.Examine // with less objects. private static bool _isReady; private static bool _isReadSet; - private static object _isReadyLock; + private static object? _isReadyLock; public RebuildOnStartupHandler( ISyncBootStateAccessor syncBootStateAccessor, diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs index 17ae1de634..11372c89ae 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs @@ -68,7 +68,7 @@ namespace Umbraco.Cms.Infrastructure.Install.InstallSteps throw new InvalidOperationException("Could not find the super user!"); } admin.Email = user.Email.Trim(); - admin.Name = user.Name?.Trim(); + admin.Name = user.Name!.Trim(); admin.Username = user.Email.Trim(); _userService.Save(admin); diff --git a/src/Umbraco.Infrastructure/Install/PackageMigrationRunner.cs b/src/Umbraco.Infrastructure/Install/PackageMigrationRunner.cs index 6580bc8596..2af5266247 100644 --- a/src/Umbraco.Infrastructure/Install/PackageMigrationRunner.cs +++ b/src/Umbraco.Infrastructure/Install/PackageMigrationRunner.cs @@ -53,7 +53,7 @@ namespace Umbraco.Cms.Infrastructure.Install /// public IEnumerable RunPackageMigrationsIfPending(string packageName) { - IReadOnlyDictionary keyValues = _keyValueService.FindByKeyPrefix(Constants.Conventions.Migrations.KeyValuePrefix); + IReadOnlyDictionary? keyValues = _keyValueService.FindByKeyPrefix(Constants.Conventions.Migrations.KeyValuePrefix); IReadOnlyList pendingMigrations = _pendingPackageMigrations.GetPendingPackageMigrations(keyValues); IEnumerable packagePlans = _packageMigrationPlans.Values diff --git a/src/Umbraco.Infrastructure/Install/UnattendedInstaller.cs b/src/Umbraco.Infrastructure/Install/UnattendedInstaller.cs index 5f9b438f2f..bf38c2b664 100644 --- a/src/Umbraco.Infrastructure/Install/UnattendedInstaller.cs +++ b/src/Umbraco.Infrastructure/Install/UnattendedInstaller.cs @@ -60,7 +60,7 @@ namespace Umbraco.Cms.Infrastructure.Install _runtimeState.DetermineRuntimeLevel(); if (_runtimeState.Reason == RuntimeLevelReason.InstallMissingDatabase) { - _dbProviderFactoryCreator.CreateDatabase(_databaseFactory.ProviderName, _databaseFactory.ConnectionString); + _dbProviderFactoryCreator.CreateDatabase(_databaseFactory.ProviderName!, _databaseFactory.ConnectionString!); } bool connect; @@ -99,7 +99,7 @@ namespace Umbraco.Cms.Infrastructure.Install { using (database = _databaseFactory.CreateDatabase()) { - var hasUmbracoTables = database.IsUmbracoInstalled(); + var hasUmbracoTables = database?.IsUmbracoInstalled() ?? false; // database has umbraco tables, assume Umbraco is already installed if (hasUmbracoTables) @@ -110,10 +110,10 @@ namespace Umbraco.Cms.Infrastructure.Install // all conditions fulfilled, do the install _logger.LogInformation("Starting unattended install."); - database.BeginTransaction(); + database?.BeginTransaction(); DatabaseSchemaCreator creator = _databaseSchemaCreatorFactory.Create(database); creator.InitializeDatabaseSchema(); - database.CompleteTransaction(); + database?.CompleteTransaction(); _logger.LogInformation("Unattended install completed."); // Emit an event with EventAggregator that unattended install completed diff --git a/src/Umbraco.Infrastructure/Logging/Viewer/LogMessage.cs b/src/Umbraco.Infrastructure/Logging/Viewer/LogMessage.cs index 12224c2af3..9bdea3f650 100644 --- a/src/Umbraco.Infrastructure/Logging/Viewer/LogMessage.cs +++ b/src/Umbraco.Infrastructure/Logging/Viewer/LogMessage.cs @@ -23,17 +23,17 @@ namespace Umbraco.Cms.Core.Logging.Viewer /// /// The message template describing the log event. /// - public string MessageTemplateText { get; set; } + public string? MessageTemplateText { get; set; } /// /// The message template filled with the log event properties. /// - public string RenderedMessage { get; set; } + public string? RenderedMessage { get; set; } /// /// Properties associated with the log event, including those presented in Serilog.Events.LogEvent.MessageTemplate. /// - public IReadOnlyDictionary Properties { get; set; } + public IReadOnlyDictionary? Properties { get; set; } /// /// An exception associated with the log event, or null. diff --git a/src/Umbraco.Infrastructure/Logging/Viewer/LogTemplate.cs b/src/Umbraco.Infrastructure/Logging/Viewer/LogTemplate.cs index 3398e32fd0..ecded4d35b 100644 --- a/src/Umbraco.Infrastructure/Logging/Viewer/LogTemplate.cs +++ b/src/Umbraco.Infrastructure/Logging/Viewer/LogTemplate.cs @@ -2,7 +2,7 @@ { public class LogTemplate { - public string MessageTemplate { get; set; } + public string? MessageTemplate { get; set; } public int Count { get; set; } } diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseSchemaCreator.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseSchemaCreator.cs index e914c3a176..3058fbfdf0 100644 --- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseSchemaCreator.cs +++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseSchemaCreator.cs @@ -223,7 +223,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install // In theory you could have: FK_ or fk_ ...or really any standard that your development department (or developer) chooses to use. foreach (var unknown in unknownConstraintsInDatabase) { - if (foreignKeysInSchema!.InvariantContains(unknown) || primaryKeysInSchema.InvariantContains(unknown)) + if (foreignKeysInSchema!.InvariantContains(unknown) || primaryKeysInSchema!.InvariantContains(unknown)) { result.ValidConstraints.Add(unknown); } @@ -259,16 +259,16 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install //Add valid and invalid primary key differences to the result object IEnumerable validPrimaryKeyDifferences = - primaryKeysInDatabase.Intersect(primaryKeysInSchema, StringComparer.InvariantCultureIgnoreCase); + primaryKeysInDatabase!.Intersect(primaryKeysInSchema, StringComparer.InvariantCultureIgnoreCase)!; foreach (var primaryKey in validPrimaryKeyDifferences) { result.ValidConstraints.Add(primaryKey); } IEnumerable invalidPrimaryKeyDifferences = - primaryKeysInDatabase.Except(primaryKeysInSchema, StringComparer.InvariantCultureIgnoreCase) + primaryKeysInDatabase!.Except(primaryKeysInSchema, StringComparer.InvariantCultureIgnoreCase)! .Union(primaryKeysInSchema.Except(primaryKeysInDatabase, - StringComparer.InvariantCultureIgnoreCase)); + StringComparer.InvariantCultureIgnoreCase))!; foreach (var primaryKey in invalidPrimaryKeyDifferences) { result.Errors.Add(new Tuple("Constraint", primaryKey)); diff --git a/src/Umbraco.Infrastructure/Models/Blocks/BlockValue.cs b/src/Umbraco.Infrastructure/Models/Blocks/BlockValue.cs index c6328bc0c3..3b6df71422 100644 --- a/src/Umbraco.Infrastructure/Models/Blocks/BlockValue.cs +++ b/src/Umbraco.Infrastructure/Models/Blocks/BlockValue.cs @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Core.Models.Blocks public class BlockValue { [JsonProperty("layout")] - public IDictionary Layout { get; set; } + public IDictionary Layout { get; set; } = null!; [JsonProperty("contentData")] public List ContentData { get; set; } = new List(); diff --git a/src/Umbraco.Infrastructure/Models/GridValue.cs b/src/Umbraco.Infrastructure/Models/GridValue.cs index b6caed78f4..e873287ffb 100644 --- a/src/Umbraco.Infrastructure/Models/GridValue.cs +++ b/src/Umbraco.Infrastructure/Models/GridValue.cs @@ -13,75 +13,75 @@ namespace Umbraco.Cms.Core.Models public class GridValue { [JsonProperty("name")] - public string Name { get; set; } + public string? Name { get; set; } [JsonProperty("sections")] - public IEnumerable Sections { get; set; } + public IEnumerable Sections { get; set; } = null!; public class GridSection { [JsonProperty("grid")] - public string Grid { get; set; } // TODO: what is this? + public string? Grid { get; set; } // TODO: what is this? [JsonProperty("rows")] - public IEnumerable Rows { get; set; } + public IEnumerable Rows { get; set; } = null!; } public class GridRow { [JsonProperty("name")] - public string Name { get; set; } + public string? Name { get; set; } [JsonProperty("id")] public Guid Id { get; set; } [JsonProperty("areas")] - public IEnumerable Areas { get; set; } + public IEnumerable Areas { get; set; } = null!; [JsonProperty("styles")] - public JToken Styles { get; set; } + public JToken? Styles { get; set; } [JsonProperty("config")] - public JToken Config { get; set; } + public JToken? Config { get; set; } } public class GridArea { [JsonProperty("grid")] - public string Grid { get; set; } // TODO: what is this? + public string? Grid { get; set; } // TODO: what is this? [JsonProperty("controls")] - public IEnumerable Controls { get; set; } + public IEnumerable Controls { get; set; } = null!; [JsonProperty("styles")] - public JToken Styles { get; set; } + public JToken? Styles { get; set; } [JsonProperty("config")] - public JToken Config { get; set; } + public JToken? Config { get; set; } } public class GridControl { [JsonProperty("value")] - public JToken Value { get; set; } + public JToken Value { get; set; } = null!; [JsonProperty("editor")] - public GridEditor Editor { get; set; } + public GridEditor Editor { get; set; } = null!; [JsonProperty("styles")] - public JToken Styles { get; set; } + public JToken? Styles { get; set; } [JsonProperty("config")] - public JToken Config { get; set; } + public JToken? Config { get; set; } } public class GridEditor { [JsonProperty("alias")] - public string Alias { get; set; } + public string Alias { get; set; } = null!; [JsonProperty("view")] - public string View { get; set; } + public string? View { get; set; } } } } diff --git a/src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs b/src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs index 8b49f6ffa2..8bd1e38463 100644 --- a/src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs @@ -52,18 +52,24 @@ namespace Umbraco.Cms.Core.Models.Mapping if (source is IMediaEntitySlim mediaSlim) { - //pass UpdateDate for MediaPicker ListView ordering - source.AdditionalData["UpdateDate"] = mediaSlim.UpdateDate; - source.AdditionalData["MediaPath"] = mediaSlim.MediaPath; + if (source.AdditionalData is not null) + { + //pass UpdateDate for MediaPicker ListView ordering + source.AdditionalData["UpdateDate"] = mediaSlim.UpdateDate; + source.AdditionalData["MediaPath"] = mediaSlim.MediaPath; + } } - // NOTE: we're mapping the objects in AdditionalData by object reference here. - // it works fine for now, but it's something to keep in mind in the future - foreach(var kvp in source.AdditionalData) + if (source.AdditionalData is not null) { - if (kvp.Value is not null) + // NOTE: we're mapping the objects in AdditionalData by object reference here. + // it works fine for now, but it's something to keep in mind in the future + foreach(var kvp in source.AdditionalData) { - target.AdditionalData[kvp.Key] = kvp.Value; + if (kvp.Value is not null) + { + target.AdditionalData[kvp.Key] = kvp.Value; + } } } diff --git a/src/Umbraco.Infrastructure/ModelsBuilder/ModelsBuilderAssemblyAttribute.cs b/src/Umbraco.Infrastructure/ModelsBuilder/ModelsBuilderAssemblyAttribute.cs index 37199c0990..f016a3ecd2 100644 --- a/src/Umbraco.Infrastructure/ModelsBuilder/ModelsBuilderAssemblyAttribute.cs +++ b/src/Umbraco.Infrastructure/ModelsBuilder/ModelsBuilderAssemblyAttribute.cs @@ -18,6 +18,6 @@ namespace Umbraco.Cms.Infrastructure.ModelsBuilder /// Gets or sets a hash value representing the state of the custom source code files /// and the Umbraco content types that were used to generate and compile the assembly. /// - public string SourceHash { get; set; } + public string? SourceHash { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs index c4951c2aaf..483a90a4dc 100644 --- a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs +++ b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs @@ -91,14 +91,20 @@ namespace Umbraco.Cms.Infrastructure.Packaging var installationSummary = new InstallationSummary(compiledPackage.Name) { Warnings = compiledPackage.Warnings, - DataTypesInstalled = ImportDataTypes(compiledPackage.DataTypes.ToList(), userId, out IEnumerable dataTypeEntityContainersInstalled), + DataTypesInstalled = + ImportDataTypes(compiledPackage.DataTypes.ToList(), userId, + out IEnumerable dataTypeEntityContainersInstalled), LanguagesInstalled = ImportLanguages(compiledPackage.Languages, userId), DictionaryItemsInstalled = ImportDictionaryItems(compiledPackage.DictionaryItems, userId), MacrosInstalled = ImportMacros(compiledPackage.Macros, userId), MacroPartialViewsInstalled = ImportMacroPartialViews(compiledPackage.MacroPartialViews, userId), TemplatesInstalled = ImportTemplates(compiledPackage.Templates.ToList(), userId), - DocumentTypesInstalled = ImportDocumentTypes(compiledPackage.DocumentTypes, userId, out IEnumerable documentTypeEntityContainersInstalled), - MediaTypesInstalled = ImportMediaTypes(compiledPackage.MediaTypes, userId, out IEnumerable mediaTypeEntityContainersInstalled), + DocumentTypesInstalled = + ImportDocumentTypes(compiledPackage.DocumentTypes, userId, + out IEnumerable documentTypeEntityContainersInstalled), + MediaTypesInstalled = + ImportMediaTypes(compiledPackage.MediaTypes, userId, + out IEnumerable mediaTypeEntityContainersInstalled), StylesheetsInstalled = ImportStylesheets(compiledPackage.Stylesheets, userId), ScriptsInstalled = ImportScripts(compiledPackage.Scripts, userId), PartialViewsInstalled = ImportPartialViews(compiledPackage.PartialViews, userId) @@ -114,8 +120,10 @@ namespace Umbraco.Cms.Infrastructure.Packaging var importedDocTypes = installationSummary.DocumentTypesInstalled.ToDictionary(x => x.Alias, x => x); var importedMediaTypes = installationSummary.MediaTypesInstalled.ToDictionary(x => x.Alias, x => x); - installationSummary.ContentInstalled = ImportContentBase(compiledPackage.Documents, importedDocTypes, userId, _contentTypeService, _contentService); - installationSummary.MediaInstalled = ImportContentBase(compiledPackage.Media, importedMediaTypes, userId, _mediaTypeService, _mediaService); + installationSummary.ContentInstalled = ImportContentBase(compiledPackage.Documents, importedDocTypes, + userId, _contentTypeService, _contentService); + installationSummary.MediaInstalled = ImportContentBase(compiledPackage.Media, importedMediaTypes, + userId, _mediaTypeService, _mediaService); scope.Complete(); @@ -139,8 +147,10 @@ namespace Umbraco.Cms.Infrastructure.Packaging /// Optional id of the User performing the operation. Default is zero (admin). /// Collection of entity containers installed by the package to be populated with those created in installing data types. /// An enumerable list of generated ContentTypes - public IReadOnlyList ImportMediaTypes(IEnumerable docTypeElements, int userId, out IEnumerable entityContainersInstalled) - => ImportDocumentTypes(docTypeElements.ToList(), true, userId, _mediaTypeService, out entityContainersInstalled); + public IReadOnlyList ImportMediaTypes(IEnumerable docTypeElements, int userId, + out IEnumerable entityContainersInstalled) + => ImportDocumentTypes(docTypeElements.ToList(), true, userId, _mediaTypeService, + out entityContainersInstalled); #endregion @@ -152,9 +162,11 @@ namespace Umbraco.Cms.Infrastructure.Packaging int userId, IContentTypeBaseService typeService, IContentServiceBase service) - where TContentBase : class, IContentBase - where TContentTypeComposition : IContentTypeComposition - => docs.SelectMany(x => ImportContentBase(x.XmlData.Elements().Where(doc => (string)doc.Attribute("isDoc") == string.Empty), -1, importedDocumentTypes, userId, typeService, service)).ToList(); + where TContentBase : class, IContentBase + where TContentTypeComposition : IContentTypeComposition + => docs.SelectMany(x => + ImportContentBase(x.XmlData.Elements().Where(doc => (string?)doc.Attribute("isDoc") == string.Empty), -1, + importedDocumentTypes, userId, typeService, service)).ToList(); /// /// Imports and saves package xml as @@ -174,7 +186,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging where TContentBase : class, IContentBase where TContentTypeComposition : IContentTypeComposition { - var contents = ParseContentBaseRootXml(roots, parentId, importedDocumentTypes, typeService, service).ToList(); + var contents = ParseContentBaseRootXml(roots, parentId, importedDocumentTypes, typeService, service) + .ToList(); if (contents.Any()) { service.Save(contents, userId); @@ -205,7 +218,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging IDictionary importedContentTypes, IContentTypeBaseService typeService, IContentServiceBase service) - where TContentBase : class, IContentBase + where TContentBase : class?, IContentBase where TContentTypeComposition : IContentTypeComposition { var contents = new List(); @@ -218,21 +231,25 @@ namespace Umbraco.Cms.Infrastructure.Packaging TContentTypeComposition contentType = FindContentTypeByAlias(contentTypeAlias, typeService); if (contentType == null) { - throw new InvalidOperationException("Could not find content type with alias " + contentTypeAlias); + throw new InvalidOperationException( + "Could not find content type with alias " + contentTypeAlias); } importedContentTypes.Add(contentTypeAlias, contentType); } - if (TryCreateContentFromXml(root, importedContentTypes[contentTypeAlias], default, parentId, service, out TContentBase content)) + if (TryCreateContentFromXml(root, importedContentTypes[contentTypeAlias], null, parentId, service, + out var content)) { contents.Add(content); } - var children = root.Elements().Where(doc => (string)doc.Attribute("isDoc") == string.Empty).ToList(); + var children = root.Elements().Where(doc => (string?)doc.Attribute("isDoc") == string.Empty).ToList(); if (children.Count > 0) { - contents.AddRange(CreateContentFromXml(children, content, importedContentTypes, typeService, service).WhereNotNull()); + contents.AddRange( + CreateContentFromXml(children, content, importedContentTypes, typeService, service) + .WhereNotNull()); } } @@ -261,16 +278,18 @@ namespace Umbraco.Cms.Infrastructure.Packaging } // Create and add the child to the list - if (TryCreateContentFromXml(child, importedContentTypes[contentTypeAlias], parent, default, service, out var content)) + if (TryCreateContentFromXml(child, importedContentTypes[contentTypeAlias], parent, default, service, + out var content)) { list.Add(content); } // Recursive call - var grandChildren = child.Elements().Where(x => (string)x.Attribute("isDoc") == string.Empty).ToList(); + var grandChildren = child.Elements().Where(x => (string?)x.Attribute("isDoc") == string.Empty).ToList(); if (grandChildren.Any()) { - list.AddRange(CreateContentFromXml(grandChildren, content, importedContentTypes, typeService, service)); + list.AddRange(CreateContentFromXml(grandChildren, content, importedContentTypes, typeService, + service)); } } @@ -280,11 +299,11 @@ namespace Umbraco.Cms.Infrastructure.Packaging private bool TryCreateContentFromXml( XElement element, TContentTypeComposition contentType, - TContentBase parent, + TContentBase? parent, int parentId, IContentServiceBase service, out TContentBase output) - where TContentBase : class, IContentBase + where TContentBase : class?, IContentBase where TContentTypeComposition : IContentTypeComposition { Guid key = element.RequiredAttributeValue("key"); @@ -297,15 +316,15 @@ namespace Umbraco.Cms.Infrastructure.Packaging return false; } - var level = element.Attribute("level").Value; - var sortOrder = element.Attribute("sortOrder").Value; - var nodeName = element.Attribute("nodeName").Value; - var path = element.Attribute("path").Value; + var level = element.Attribute("level")?.Value ?? string.Empty; + var sortOrder = element.Attribute("sortOrder")?.Value ?? string.Empty; + var nodeName = element.Attribute("nodeName")?.Value ?? string.Empty; + var path = element.Attribute("path")?.Value; var templateId = element.AttributeValue("template"); var properties = from property in element.Elements() - where property.Attribute("isDoc") == null - select property; + where property.Attribute("isDoc") == null + select property; //TODO: This will almost never work, we can't reference a template by an INT Id within a package manifest, we need to change the // packager to package templates by UDI and resolve by the same, in 98% of cases, this isn't going to work, or it will resolve the wrong template. @@ -322,7 +341,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging } } - TContentBase content = CreateContent( + TContentBase? content = CreateContent( nodeName, parent, parentId, @@ -332,12 +351,18 @@ namespace Umbraco.Cms.Infrastructure.Packaging int.Parse(sortOrder, CultureInfo.InvariantCulture), template?.Id); + if (content is null) + { + throw new InvalidOperationException("Cloud not create content"); + } + // Handle culture specific node names const string nodeNamePrefix = "nodeName-"; // Get the installed culture iso names, we create a localized content node with a culture that does not exist in the project // We have to use Invariant comparisons, because when we get them from ContentBase in EntityXmlSerializer they're all lowercase. var installedLanguages = _localizationService.GetAllLanguages().Select(l => l.IsoCode).ToArray(); - foreach (var localizedNodeName in element.Attributes().Where(a => a.Name.LocalName.InvariantStartsWith(nodeNamePrefix))) + foreach (var localizedNodeName in element.Attributes() + .Where(a => a.Name.LocalName.InvariantStartsWith(nodeNamePrefix))) { var newCulture = localizedNodeName.Name.LocalName.Substring(nodeNamePrefix.Length); // Skip the culture if it does not exist in the current project @@ -362,7 +387,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging var propertyValue = property.Value; // Handle properties language attributes - var propertyLang = property.Attribute(XName.Get("lang"))?.Value; + var propertyLang = property.Attribute(XName.Get("lang"))?.Value ?? string.Empty; foundLanguages.Add(propertyLang); if (propTypes.TryGetValue(propertyTypeAlias, out var propertyType)) { @@ -379,7 +404,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging foreach (var propertyLang in foundLanguages) { - if (string.IsNullOrEmpty(content.GetCultureName(propertyLang)) && installedLanguages.InvariantContains(propertyLang)) + if (string.IsNullOrEmpty(content.GetCultureName(propertyLang)) && + installedLanguages.InvariantContains(propertyLang)) { content.SetCultureName(nodeName, propertyLang); } @@ -389,8 +415,9 @@ namespace Umbraco.Cms.Infrastructure.Packaging return true; } - private TContentBase CreateContent(string name, TContentBase parent, int parentId, TContentTypeComposition contentType, Guid key, int level, int sortOrder, int? templateId) - where TContentBase : class, IContentBase + private TContentBase? CreateContent(string name, TContentBase? parent, + int parentId, TContentTypeComposition contentType, Guid key, int level, int sortOrder, int? templateId) + where TContentBase : class?, IContentBase where TContentTypeComposition : IContentTypeComposition { switch (contentType) @@ -398,21 +425,33 @@ namespace Umbraco.Cms.Infrastructure.Packaging case IContentType c: if (parent is null) { - return new Content(name, parentId, c) { Key = key, Level = level, SortOrder = sortOrder, TemplateId = templateId, } as TContentBase; + return new Content(name, parentId, c) + { + Key = key, Level = level, SortOrder = sortOrder, TemplateId = templateId, + } as TContentBase; } else { - return new Content(name, (IContent)parent, c) { Key = key, Level = level, SortOrder = sortOrder, TemplateId = templateId, } as TContentBase; + return new Content(name, (IContent)parent, c) + { + Key = key, Level = level, SortOrder = sortOrder, TemplateId = templateId, + } as TContentBase; } case IMediaType m: if (parent is null) { - return new Core.Models.Media(name, parentId, m) { Key = key, Level = level, SortOrder = sortOrder, } as TContentBase; + return new Core.Models.Media(name, parentId, m) + { + Key = key, Level = level, SortOrder = sortOrder, + } as TContentBase; } else { - return new Core.Models.Media(name, (IMedia)parent, m) { Key = key, Level = level, SortOrder = sortOrder, } as TContentBase; + return new Core.Models.Media(name, (IMedia)parent, m) + { + Key = key, Level = level, SortOrder = sortOrder, + } as TContentBase; } default: @@ -425,7 +464,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging #region DocumentTypes public IReadOnlyList ImportDocumentType(XElement docTypeElement, int userId) - => ImportDocumentTypes(new[] { docTypeElement }, userId, out _); + => ImportDocumentTypes(new[] {docTypeElement}, userId, out _); /// /// Imports and saves package xml as @@ -443,8 +482,10 @@ namespace Umbraco.Cms.Infrastructure.Packaging /// Optional id of the User performing the operation. Default is zero (admin). /// Collection of entity containers installed by the package to be populated with those created in installing data types. /// An enumerable list of generated ContentTypes - public IReadOnlyList ImportDocumentTypes(IEnumerable docTypeElements, int userId, out IEnumerable entityContainersInstalled) - => ImportDocumentTypes(docTypeElements.ToList(), true, userId, _contentTypeService, out entityContainersInstalled); + public IReadOnlyList ImportDocumentTypes(IEnumerable docTypeElements, int userId, + out IEnumerable entityContainersInstalled) + => ImportDocumentTypes(docTypeElements.ToList(), true, userId, _contentTypeService, + out entityContainersInstalled); /// /// Imports and saves package xml as @@ -453,7 +494,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging /// Boolean indicating whether or not to import the /// Optional id of the User performing the operation. Default is zero (admin). /// An enumerable list of generated ContentTypes - public IReadOnlyList ImportDocumentTypes(IReadOnlyCollection unsortedDocumentTypes, bool importStructure, int userId, IContentTypeBaseService service) + public IReadOnlyList ImportDocumentTypes(IReadOnlyCollection unsortedDocumentTypes, + bool importStructure, int userId, IContentTypeBaseService service) where T : class, IContentTypeComposition => ImportDocumentTypes(unsortedDocumentTypes, importStructure, userId, service); @@ -465,7 +507,9 @@ namespace Umbraco.Cms.Infrastructure.Packaging /// Optional id of the User performing the operation. Default is zero (admin). /// Collection of entity containers installed by the package to be populated with those created in installing data types. /// An enumerable list of generated ContentTypes - public IReadOnlyList ImportDocumentTypes(IReadOnlyCollection unsortedDocumentTypes, bool importStructure, int userId, IContentTypeBaseService service, out IEnumerable entityContainersInstalled) + public IReadOnlyList ImportDocumentTypes(IReadOnlyCollection unsortedDocumentTypes, + bool importStructure, int userId, IContentTypeBaseService service, + out IEnumerable entityContainersInstalled) where T : class, IContentTypeComposition { var importedContentTypes = new Dictionary(); @@ -475,7 +519,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging var graph = new TopoGraph>(x => x.Key, x => x.Dependencies); var isSingleDocTypeImport = unsortedDocumentTypes.Count == 1; - var importedFolders = CreateContentTypeFolderStructure(unsortedDocumentTypes, out entityContainersInstalled); + var importedFolders = + CreateContentTypeFolderStructure(unsortedDocumentTypes, out entityContainersInstalled); if (isSingleDocTypeImport == false) { @@ -488,13 +533,13 @@ namespace Umbraco.Cms.Infrastructure.Packaging var dependencies = new HashSet(); //Add the Master as a dependency - if (string.IsNullOrEmpty((string)infoElement.Element("Master")) == false) + if (string.IsNullOrEmpty((string?)infoElement?.Element("Master")) == false) { - dependencies.Add(infoElement.Element("Master").Value); + dependencies.Add(infoElement.Element("Master")?.Value!); } //Add compositions as dependencies - var compositionsElement = infoElement.Element("Compositions"); + var compositionsElement = infoElement?.Element("Compositions"); if (compositionsElement != null && compositionsElement.HasElements) { var compositions = compositionsElement.Elements("Composition"); @@ -507,7 +552,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging } } - graph.AddItem(TopoGraph.CreateNode(infoElement.Element("Alias").Value, elementCopy, dependencies.ToArray())); + graph.AddItem(TopoGraph.CreateNode(infoElement!.Element("Alias")!.Value, elementCopy, + dependencies.ToArray())); } } @@ -519,9 +565,9 @@ namespace Umbraco.Cms.Infrastructure.Packaging //Iterate the sorted document types and create them as IContentType objects foreach (XElement documentType in documentTypes) { - var alias = documentType.Element("Info").Element("Alias").Value; + var alias = documentType.Element("Info")?.Element("Alias")?.Value; - if (importedContentTypes.ContainsKey(alias) == false) + if (alias is not null && importedContentTypes.ContainsKey(alias) == false) { T contentType = service.Get(alias); @@ -552,15 +598,17 @@ namespace Umbraco.Cms.Infrastructure.Packaging //Update the structure here - we can't do it until all DocTypes have been created foreach (var documentType in documentTypes) { - var alias = documentType.Element("Info").Element("Alias").Value; + var alias = documentType.Element("Info")?.Element("Alias")?.Value; var structureElement = documentType.Element("Structure"); //Ensure that we only update ContentTypes which has actual structure-elements - if (structureElement == null || structureElement.Elements().Any() == false) + if (structureElement == null || structureElement.Elements().Any() == false || alias is null) continue; - var updated = UpdateContentTypesStructure(importedContentTypes[alias], structureElement, importedContentTypes, service); + var updated = UpdateContentTypesStructure(importedContentTypes[alias], structureElement, + importedContentTypes, service); updatedContentTypes.Add(updated); } + //Update ContentTypes with a newly added structure/list of allowed children if (updatedContentTypes.Any()) { @@ -571,34 +619,36 @@ namespace Umbraco.Cms.Infrastructure.Packaging return list; } - private Dictionary CreateContentTypeFolderStructure(IEnumerable unsortedDocumentTypes, out IEnumerable entityContainersInstalled) + private Dictionary CreateContentTypeFolderStructure(IEnumerable unsortedDocumentTypes, + out IEnumerable entityContainersInstalled) { var importedFolders = new Dictionary(); var trackEntityContainersInstalled = new List(); foreach (XElement documentType in unsortedDocumentTypes) { - XAttribute foldersAttribute = documentType.Attribute("Folders"); - XElement infoElement = documentType.Element("Info"); + XAttribute? foldersAttribute = documentType.Attribute("Folders"); + XElement? infoElement = documentType.Element("Info"); if (foldersAttribute != null && infoElement != null - // don't import any folder if this is a child doc type - the parent doc type will need to - // exist which contains it's folders - && ((string)infoElement.Element("Master")).IsNullOrWhiteSpace()) + // don't import any folder if this is a child doc type - the parent doc type will need to + // exist which contains it's folders + && ((string?)infoElement.Element("Master")).IsNullOrWhiteSpace()) { - var alias = documentType.Element("Info").Element("Alias").Value; + var alias = documentType.Element("Info")?.Element("Alias")?.Value; var folders = foldersAttribute.Value.Split(Constants.CharArrays.ForwardSlash); - XAttribute folderKeysAttribute = documentType.Attribute("FolderKeys"); + XAttribute? folderKeysAttribute = documentType.Attribute("FolderKeys"); Guid[] folderKeys = Array.Empty(); if (folderKeysAttribute != null) { - folderKeys = folderKeysAttribute.Value.Split(Constants.CharArrays.ForwardSlash).Select(x=>Guid.Parse(x)).ToArray(); + folderKeys = folderKeysAttribute.Value.Split(Constants.CharArrays.ForwardSlash) + .Select(x => Guid.Parse(x)).ToArray(); } var rootFolder = WebUtility.UrlDecode(folders[0]); - EntityContainer current = null; + EntityContainer? current = null; Guid? rootFolderKey = null; if (folderKeys.Length == folders.Length && folderKeys.Length > 0) { @@ -608,32 +658,37 @@ namespace Umbraco.Cms.Infrastructure.Packaging // The folder might already exist, but with a different key, so check if it exists, even if there is a key. // Level 1 = root level folders, there can only be one with the same name - current ??= _contentTypeService.GetContainers(rootFolder, 1).FirstOrDefault(); + current ??= _contentTypeService.GetContainers(rootFolder, 1)?.FirstOrDefault(); if (current == null) { - Attempt> tryCreateFolder = _contentTypeService.CreateContainer(-1, rootFolderKey ?? Guid.NewGuid(), rootFolder); + Attempt?> tryCreateFolder = + _contentTypeService.CreateContainer(-1, rootFolderKey ?? Guid.NewGuid(), rootFolder); if (tryCreateFolder == false) { - _logger.LogError(tryCreateFolder.Exception, "Could not create folder: {FolderName}", rootFolder); - throw tryCreateFolder.Exception; + _logger.LogError(tryCreateFolder.Exception, "Could not create folder: {FolderName}", + rootFolder); + throw tryCreateFolder.Exception!; } - var rootFolderId = tryCreateFolder.Result.Entity.Id; - current = _contentTypeService.GetContainer(rootFolderId); - trackEntityContainersInstalled.Add(current); + var rootFolderId = tryCreateFolder.Result?.Entity?.Id; + if (rootFolderId is not null) + { + current = _contentTypeService.GetContainer(rootFolderId.Value); + trackEntityContainersInstalled.Add(current!); + } } - importedFolders.Add(alias, current.Id); + importedFolders.Add(alias!, current!.Id); for (var i = 1; i < folders.Length; i++) { var folderName = WebUtility.UrlDecode(folders[i]); Guid? folderKey = (folderKeys.Length == folders.Length) ? folderKeys[i] : null; current = CreateContentTypeChildFolder(folderName, folderKey ?? Guid.NewGuid(), current); - trackEntityContainersInstalled.Add(current); - importedFolders[alias] = current.Id; + trackEntityContainersInstalled.Add(current!); + importedFolders[alias!] = current!.Id; } } } @@ -642,7 +697,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging return importedFolders; } - private EntityContainer CreateContentTypeChildFolder(string folderName, Guid folderKey, IUmbracoEntity current) + private EntityContainer? CreateContentTypeChildFolder(string folderName, Guid folderKey, IUmbracoEntity current) { var children = _entityService.GetChildren(current.Id).ToArray(); var found = children.Any(x => x.Name.InvariantEquals(folderName) || x.Key.Equals(folderKey)); @@ -656,9 +711,10 @@ namespace Umbraco.Cms.Infrastructure.Packaging if (tryCreateFolder == false) { _logger.LogError(tryCreateFolder.Exception, "Could not create folder: {FolderName}", folderName); - throw tryCreateFolder.Exception; + throw tryCreateFolder.Exception!; } - return _contentTypeService.GetContainer(tryCreateFolder.Result.Entity.Id); + + return _contentTypeService.GetContainer(tryCreateFolder.Result!.Entity!.Id); } private T CreateContentTypeFromXml( @@ -667,74 +723,58 @@ namespace Umbraco.Cms.Infrastructure.Packaging IContentTypeBaseService service) where T : class, IContentTypeComposition { - var key = Guid.Parse(documentType.Element("Info").Element("Key").Value); + var key = Guid.Parse(documentType.Element("Info")!.Element("Key")!.Value); - XElement infoElement = documentType.Element("Info"); + XElement infoElement = documentType.Element("Info")!; //Name of the master corresponds to the parent - XElement masterElement = infoElement.Element("Master"); + XElement? masterElement = infoElement.Element("Master"); - T parent = default; + T? parent = default; if (masterElement != null) { var masterAlias = masterElement.Value; parent = importedContentTypes.ContainsKey(masterAlias) - ? importedContentTypes[masterAlias] - : service.Get(masterAlias); + ? importedContentTypes[masterAlias] + : service.Get(masterAlias); } - var alias = infoElement.Element("Alias").Value; - T contentType = CreateContentType(key, parent, -1, alias); + var alias = infoElement?.Element("Alias")?.Value; + var contentType = CreateContentType(key, parent, -1, alias!); if (parent != null) { - contentType.AddContentType(parent); + contentType?.AddContentType(parent); } - return UpdateContentTypeFromXml(documentType, contentType, importedContentTypes, service); + return UpdateContentTypeFromXml(documentType, contentType, importedContentTypes, service); } - private T CreateContentType(Guid key, T parent, int parentId, string alias) + private T? CreateContentType(Guid key, T? parent, int parentId, string alias) where T : class, IContentTypeComposition { if (typeof(T) == typeof(IContentType)) { if (parent is null) { - return new ContentType(_shortStringHelper, parentId) - { - Alias = alias, - Key = key - } as T; + return new ContentType(_shortStringHelper, parentId) {Alias = alias, Key = key} as T; } else { - return new ContentType(_shortStringHelper, (IContentType)parent, alias) - { - Key = key - } as T; + return new ContentType(_shortStringHelper, (IContentType)parent, alias) {Key = key} as T; } - } if (typeof(T) == typeof(IMediaType)) { if (parent is null) { - return new MediaType(_shortStringHelper, parentId) - { - Alias = alias, - Key = key - } as T; + return new MediaType(_shortStringHelper, parentId) {Alias = alias, Key = key} as T; } else { - return new MediaType(_shortStringHelper, (IMediaType)parent, alias) - { - Key = key - } as T; + return new MediaType(_shortStringHelper, (IMediaType)parent, alias) {Key = key} as T; } - } throw new NotSupportedException($"Type {typeof(T)} is not supported"); @@ -742,23 +782,27 @@ namespace Umbraco.Cms.Infrastructure.Packaging private T UpdateContentTypeFromXml( XElement documentType, - T contentType, + T? contentType, IReadOnlyDictionary importedContentTypes, IContentTypeBaseService service) where T : IContentTypeComposition { - var key = Guid.Parse(documentType.Element("Info").Element("Key").Value); + var key = Guid.Parse(documentType.Element("Info")!.Element("Key")!.Value); var infoElement = documentType.Element("Info"); - var defaultTemplateElement = infoElement.Element("DefaultTemplate"); + var defaultTemplateElement = infoElement?.Element("DefaultTemplate"); + if (contentType is null) + { + throw new InvalidOperationException("Content type was null"); + } contentType.Key = key; - contentType.Name = infoElement.Element("Name").Value; + contentType.Name = infoElement!.Element("Name")!.Value; if (infoElement.Element("Key") != null) - contentType.Key = new Guid(infoElement.Element("Key").Value); - contentType.Icon = infoElement.Element("Icon").Value; - contentType.Thumbnail = infoElement.Element("Thumbnail").Value; - contentType.Description = infoElement.Element("Description").Value; + contentType.Key = new Guid(infoElement.Element("Key")!.Value); + contentType.Icon = infoElement.Element("Icon")?.Value; + contentType.Thumbnail = infoElement.Element("Thumbnail")?.Value; + contentType.Description = infoElement.Element("Description")?.Value; //NOTE AllowAtRoot, IsListView, IsElement and Variations are new properties in the package xml so we need to verify it exists before using it. var allowAtRoot = infoElement.Element("AllowAtRoot"); @@ -775,7 +819,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging var variationsElement = infoElement.Element("Variations"); if (variationsElement != null) - contentType.Variations = (ContentVariation)Enum.Parse(typeof(ContentVariation), variationsElement.Value); + contentType.Variations = + (ContentVariation)Enum.Parse(typeof(ContentVariation), variationsElement.Value); //Name of the master corresponds to the parent and we need to ensure that the Parent Id is set var masterElement = infoElement.Element("Master"); @@ -809,7 +854,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging if (contentType is IContentType contentTypex) { - UpdateContentTypesAllowedTemplates(contentTypex, infoElement.Element("AllowedTemplates"), defaultTemplateElement); + UpdateContentTypesAllowedTemplates(contentTypex, infoElement.Element("AllowedTemplates"), + defaultTemplateElement); } UpdateContentTypesPropertyGroups(contentType, documentType.Element("Tabs")); @@ -823,7 +869,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging return contentType; } - private void UpdateHistoryCleanupPolicy(IContentTypeWithHistoryCleanup withCleanup, XElement element) + private void UpdateHistoryCleanupPolicy(IContentTypeWithHistoryCleanup withCleanup, XElement? element) { if (element == null) { @@ -856,45 +902,51 @@ namespace Umbraco.Cms.Infrastructure.Packaging } } - private void UpdateContentTypesAllowedTemplates(IContentType contentType, XElement allowedTemplatesElement, XElement defaultTemplateElement) + private void UpdateContentTypesAllowedTemplates(IContentType contentType, XElement? allowedTemplatesElement, + XElement? defaultTemplateElement) { if (allowedTemplatesElement != null && allowedTemplatesElement.Elements("Template").Any()) { - var allowedTemplates = contentType.AllowedTemplates.ToList(); + var allowedTemplates = contentType.AllowedTemplates?.ToList(); foreach (var templateElement in allowedTemplatesElement.Elements("Template")) { var alias = templateElement.Value; var template = _fileService.GetTemplate(alias.ToSafeAlias(_shortStringHelper)); if (template != null) { - if (allowedTemplates.Any(x => x.Id == template.Id)) + if (allowedTemplates?.Any(x => x.Id == template.Id) ?? true) continue; allowedTemplates.Add(template); } else { - _logger.LogWarning("Packager: Error handling allowed templates. Template with alias '{TemplateAlias}' could not be found.", alias); + _logger.LogWarning( + "Packager: Error handling allowed templates. Template with alias '{TemplateAlias}' could not be found.", + alias); } } contentType.AllowedTemplates = allowedTemplates; } - if (string.IsNullOrEmpty((string)defaultTemplateElement) == false) + if (string.IsNullOrEmpty((string?)defaultTemplateElement) == false) { - var defaultTemplate = _fileService.GetTemplate(defaultTemplateElement.Value.ToSafeAlias(_shortStringHelper)); + var defaultTemplate = + _fileService.GetTemplate(defaultTemplateElement.Value.ToSafeAlias(_shortStringHelper)); if (defaultTemplate != null) { contentType.SetDefaultTemplate(defaultTemplate); } else { - _logger.LogWarning("Packager: Error handling default template. Default template with alias '{DefaultTemplateAlias}' could not be found.", defaultTemplateElement.Value); + _logger.LogWarning( + "Packager: Error handling default template. Default template with alias '{DefaultTemplateAlias}' could not be found.", + defaultTemplateElement.Value); } } } - private void UpdateContentTypesPropertyGroups(T contentType, XElement propertyGroupsContainer) + private void UpdateContentTypesPropertyGroups(T contentType, XElement? propertyGroupsContainer) where T : IContentTypeComposition { if (propertyGroupsContainer == null) @@ -903,7 +955,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging var propertyGroupElements = propertyGroupsContainer.Elements("Tab"); foreach (var propertyGroupElement in propertyGroupElements) { - var name = propertyGroupElement.Element("Caption").Value; // TODO Rename to Name (same in EntityXmlSerializer) + var name = propertyGroupElement.Element("Caption")! + .Value; // TODO Rename to Name (same in EntityXmlSerializer) var alias = propertyGroupElement.Element("Alias")?.Value; if (string.IsNullOrEmpty(alias)) @@ -924,7 +977,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging propertyGroup.Type = type; } - if (int.TryParse(propertyGroupElement.Element("SortOrder")?.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var sortOrder)) + if (int.TryParse(propertyGroupElement.Element("SortOrder")?.Value, NumberStyles.Integer, + CultureInfo.InvariantCulture, out var sortOrder)) { // Override the sort order with the imported value propertyGroup.SortOrder = sortOrder; @@ -932,13 +986,18 @@ namespace Umbraco.Cms.Infrastructure.Packaging } } - private void UpdateContentTypesProperties(T contentType, XElement genericPropertiesElement) + private void UpdateContentTypesProperties(T contentType, XElement? genericPropertiesElement) where T : IContentTypeComposition { + if (genericPropertiesElement is null) + { + return; + } var properties = genericPropertiesElement.Elements("GenericProperty"); foreach (var property in properties) { - var dataTypeDefinitionId = new Guid(property.Element("Definition").Value);//Unique Id for a DataTypeDefinition + var dataTypeDefinitionId = + new Guid(property.Element("Definition")!.Value); //Unique Id for a DataTypeDefinition var dataTypeDefinition = _dataTypeService.GetDataType(dataTypeDefinitionId); @@ -947,7 +1006,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging //get the alias as a string for use below - var propertyEditorAlias = property.Element("Type").Value.Trim(); + var propertyEditorAlias = property.Element("Type")!.Value.Trim(); //If no DataTypeDefinition with the guid from the xml wasn't found OR the ControlId on the DataTypeDefinition didn't match the DataType Id //We look up a DataTypeDefinition that matches @@ -974,11 +1033,13 @@ namespace Umbraco.Cms.Infrastructure.Packaging if (dataTypeDefinition == null) { // TODO: We should expose this to the UI during install! - _logger.LogWarning("Packager: Error handling creation of PropertyType '{PropertyType}'. Could not find DataTypeDefintion with unique id '{DataTypeDefinitionId}' nor one referencing the DataType with a property editor alias (or legacy control id) '{PropertyEditorAlias}'. Did the package creator forget to package up custom datatypes? This property will be converted to a label/readonly editor if one exists.", - property.Element("Name").Value, dataTypeDefinitionId, property.Element("Type").Value.Trim()); + _logger.LogWarning( + "Packager: Error handling creation of PropertyType '{PropertyType}'. Could not find DataTypeDefintion with unique id '{DataTypeDefinitionId}' nor one referencing the DataType with a property editor alias (or legacy control id) '{PropertyEditorAlias}'. Did the package creator forget to package up custom datatypes? This property will be converted to a label/readonly editor if one exists.", + property.Element("Name")?.Value, dataTypeDefinitionId, property.Element("Type")?.Value.Trim()); //convert to a label! - dataTypeDefinition = _dataTypeService.GetByEditorAlias(Constants.PropertyEditors.Aliases.Label).FirstOrDefault(); + dataTypeDefinition = _dataTypeService.GetByEditorAlias(Constants.PropertyEditors.Aliases.Label)? + .FirstOrDefault(); //if for some odd reason this isn't there then ignore if (dataTypeDefinition == null) continue; @@ -988,36 +1049,34 @@ namespace Umbraco.Cms.Infrastructure.Packaging var sortOrderElement = property.Element("SortOrder"); if (sortOrderElement != null) { - int.TryParse(sortOrderElement.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out sortOrder); + int.TryParse(sortOrderElement.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, + out sortOrder); } - var propertyType = new PropertyType(_shortStringHelper, dataTypeDefinition, property.Element("Alias").Value) - { - Name = property.Element("Name").Value, - Description = (string)property.Element("Description"), - Mandatory = property.Element("Mandatory") != null - ? property.Element("Mandatory").Value.ToLowerInvariant().Equals("true") - : false, - MandatoryMessage = property.Element("MandatoryMessage") != null - ? (string)property.Element("MandatoryMessage") - : string.Empty, - - ValidationRegExp = (string)property.Element("Validation"), - ValidationRegExpMessage = property.Element("ValidationRegExpMessage") != null - ? (string)property.Element("ValidationRegExpMessage") - : string.Empty, - SortOrder = sortOrder, - Variations = property.Element("Variations") != null - ? (ContentVariation)Enum.Parse(typeof(ContentVariation), property.Element("Variations").Value) - : ContentVariation.Nothing, - LabelOnTop = property.Element("LabelOnTop") != null - ? property.Element("LabelOnTop").Value.ToLowerInvariant().Equals("true") - : false - }; + var propertyType = + new PropertyType(_shortStringHelper, dataTypeDefinition, property.Element("Alias")!.Value) + { + Name = property.Element("Name")!.Value, + Description = (string?)property.Element("Description"), + Mandatory = property.Element("Mandatory") is not null && property.Element("Mandatory")!.Value.ToLowerInvariant().Equals("true"), + MandatoryMessage = property.Element("MandatoryMessage") != null + ? (string?)property.Element("MandatoryMessage") + : string.Empty, + ValidationRegExp = (string?)property.Element("Validation"), + ValidationRegExpMessage = property.Element("ValidationRegExpMessage") != null + ? (string?)property.Element("ValidationRegExpMessage") + : string.Empty, + SortOrder = sortOrder, + Variations = property.Element("Variations") != null + ? (ContentVariation)Enum.Parse(typeof(ContentVariation), + property.Element("Variations")!.Value) + : ContentVariation.Nothing, + LabelOnTop = property.Element("LabelOnTop") != null && property.Element("LabelOnTop")!.Value.ToLowerInvariant().Equals("true") + }; if (property.Element("Key") != null) { - propertyType.Key = new Guid(property.Element("Key").Value); + propertyType.Key = new Guid(property.Element("Key")!.Value); } var propertyGroupElement = property.Element("Tab"); @@ -1039,16 +1098,19 @@ namespace Umbraco.Cms.Infrastructure.Packaging } } - private T UpdateContentTypesStructure(T contentType, XElement structureElement, IReadOnlyDictionary importedContentTypes, IContentTypeBaseService service) + private T UpdateContentTypesStructure(T contentType, XElement structureElement, + IReadOnlyDictionary importedContentTypes, IContentTypeBaseService service) where T : IContentTypeComposition { - var allowedChildren = contentType.AllowedContentTypes.ToList(); - int sortOrder = allowedChildren.Any() ? allowedChildren.Last().SortOrder : 0; + var allowedChildren = contentType.AllowedContentTypes?.ToList(); + int sortOrder = allowedChildren?.Any() ?? false ? allowedChildren.Last().SortOrder : 0; foreach (var element in structureElement.Elements()) { var alias = element.Value; - var allowedChild = importedContentTypes.ContainsKey(alias) ? importedContentTypes[alias] : service.Get(alias); + var allowedChild = importedContentTypes.ContainsKey(alias) + ? importedContentTypes[alias] + : service.Get(alias); if (allowedChild == null) { _logger.LogWarning( @@ -1057,10 +1119,11 @@ namespace Umbraco.Cms.Infrastructure.Packaging continue; } - if (allowedChildren.Any(x => x.Id.IsValueCreated && x.Id.Value == allowedChild.Id)) + if (allowedChildren?.Any(x => x.Id.IsValueCreated && x.Id.Value == allowedChild.Id) ?? false) continue; - allowedChildren.Add(new ContentTypeSort(new Lazy(() => allowedChild.Id), sortOrder, allowedChild.Alias)); + allowedChildren?.Add(new ContentTypeSort(new Lazy(() => allowedChild.Id), sortOrder, + allowedChild.Alias)); sortOrder++; } @@ -1095,7 +1158,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging /// Optional id of the user /// An enumerable list of generated DataTypeDefinitions public IReadOnlyList ImportDataTypes(IReadOnlyCollection dataTypeElements, int userId) - => ImportDataTypes(dataTypeElements, userId, out _); + => ImportDataTypes(dataTypeElements, userId, out _); /// /// Imports and saves package xml as @@ -1104,7 +1167,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging /// Optional id of the user /// Collection of entity containers installed by the package to be populated with those created in installing data types. /// An enumerable list of generated DataTypeDefinitions - public IReadOnlyList ImportDataTypes(IReadOnlyCollection dataTypeElements, int userId, out IEnumerable entityContainersInstalled) + public IReadOnlyList ImportDataTypes(IReadOnlyCollection dataTypeElements, int userId, + out IEnumerable entityContainersInstalled) { var dataTypes = new List(); @@ -1125,7 +1189,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging //If the datatype definition doesn't already exist we create a new according to the one in the package xml if (definition == null) { - var databaseType = databaseTypeAttribute?.Value.EnumParse(true) ?? ValueStorageType.Ntext; + var databaseType = databaseTypeAttribute?.Value.EnumParse(true) ?? + ValueStorageType.Ntext; // the Id field is actually the string property editor Alias // however, the actual editor with this alias could be installed with the package, and @@ -1134,7 +1199,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging var editorAlias = dataTypeElement.Attribute("Id")?.Value?.Trim(); if (!_propertyEditors.TryGet(editorAlias, out var editor)) - editor = new VoidEditor(_dataValueEditorFactory) { Alias = editorAlias }; + editor = new VoidEditor(_dataValueEditorFactory) {Alias = editorAlias ?? string.Empty}; var dataType = new DataType(editor, _serializer) { @@ -1146,7 +1211,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging var configurationAttributeValue = dataTypeElement.Attribute("Configuration")?.Value; if (!string.IsNullOrWhiteSpace(configurationAttributeValue)) - dataType.Configuration = editor.GetConfigurationEditor().FromDatabase(configurationAttributeValue, _serializer); + dataType.Configuration = editor.GetConfigurationEditor() + .FromDatabase(configurationAttributeValue, _serializer); dataTypes.Add(dataType); } @@ -1165,7 +1231,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging return dataTypes; } - private Dictionary CreateDataTypeFolderStructure(IEnumerable datatypeElements, out IEnumerable entityContainersInstalled) + private Dictionary CreateDataTypeFolderStructure(IEnumerable datatypeElements, + out IEnumerable entityContainersInstalled) { var importedFolders = new Dictionary(); var trackEntityContainersInstalled = new List(); @@ -1175,15 +1242,17 @@ namespace Umbraco.Cms.Infrastructure.Packaging if (foldersAttribute != null) { - var name = datatypeElement.Attribute("Name").Value; + var name = datatypeElement.Attribute("Name")?.Value; var folders = foldersAttribute.Value.Split(Constants.CharArrays.ForwardSlash); var folderKeysAttribute = datatypeElement.Attribute("FolderKeys"); var folderKeys = Array.Empty(); if (folderKeysAttribute != null) { - folderKeys = folderKeysAttribute.Value.Split(Constants.CharArrays.ForwardSlash).Select(x=>Guid.Parse(x)).ToArray(); + folderKeys = folderKeysAttribute.Value.Split(Constants.CharArrays.ForwardSlash) + .Select(x => Guid.Parse(x)).ToArray(); } + var rootFolder = WebUtility.UrlDecode(folders[0]); var rootFolderKey = folderKeys.Length > 0 ? folderKeys[0] : Guid.NewGuid(); //there will only be a single result by name for level 1 (root) containers @@ -1194,47 +1263,50 @@ namespace Umbraco.Cms.Infrastructure.Packaging var tryCreateFolder = _dataTypeService.CreateContainer(-1, rootFolderKey, rootFolder); if (tryCreateFolder == false) { - _logger.LogError(tryCreateFolder.Exception, "Could not create folder: {FolderName}", rootFolder); - throw tryCreateFolder.Exception; + _logger.LogError(tryCreateFolder.Exception, "Could not create folder: {FolderName}", + rootFolder); + throw tryCreateFolder.Exception!; } - current = _dataTypeService.GetContainer(tryCreateFolder.Result.Entity.Id); - trackEntityContainersInstalled.Add(current); + current = _dataTypeService.GetContainer(tryCreateFolder.Result!.Entity!.Id); + trackEntityContainersInstalled.Add(current!); } - importedFolders.Add(name, current.Id); + importedFolders.Add(name!, current!.Id); for (var i = 1; i < folders.Length; i++) { var folderName = WebUtility.UrlDecode(folders[i]); Guid? folderKey = (folderKeys.Length == folders.Length) ? folderKeys[i] : null; - current = CreateDataTypeChildFolder(folderName, folderKey ?? Guid.NewGuid(), current); - trackEntityContainersInstalled.Add(current); - importedFolders[name] = current.Id; + current = CreateDataTypeChildFolder(folderName, folderKey ?? Guid.NewGuid(), current!); + trackEntityContainersInstalled.Add(current!); + importedFolders[name!] = current!.Id; } } } + entityContainersInstalled = trackEntityContainersInstalled; return importedFolders; } - private EntityContainer CreateDataTypeChildFolder(string folderName, Guid folderKey, IUmbracoEntity current) + private EntityContainer? CreateDataTypeChildFolder(string folderName, Guid folderKey, IUmbracoEntity current) { var children = _entityService.GetChildren(current.Id).ToArray(); - var found = children.Any(x => x.Name.InvariantEquals(folderName) ||x.Key.Equals(folderKey)); + var found = children.Any(x => x.Name.InvariantEquals(folderName) || x.Key.Equals(folderKey)); if (found) { var containerId = children.Single(x => x.Name.InvariantEquals(folderName)).Id; return _dataTypeService.GetContainer(containerId); } - var tryCreateFolder = _dataTypeService.CreateContainer(current.Id, folderKey,folderName); + var tryCreateFolder = _dataTypeService.CreateContainer(current.Id, folderKey, folderName); if (tryCreateFolder == false) { _logger.LogError(tryCreateFolder.Exception, "Could not create folder: {FolderName}", folderName); - throw tryCreateFolder.Exception; + throw tryCreateFolder.Exception!; } - return _dataTypeService.GetContainer(tryCreateFolder.Result.Entity.Id); + + return _dataTypeService.GetContainer(tryCreateFolder.Result!.Entity!.Id); } #endregion @@ -1247,13 +1319,15 @@ namespace Umbraco.Cms.Infrastructure.Packaging /// Xml to import /// /// An enumerable list of dictionary items - public IReadOnlyList ImportDictionaryItems(IEnumerable dictionaryItemElementList, int userId) + public IReadOnlyList ImportDictionaryItems(IEnumerable dictionaryItemElementList, + int userId) { var languages = _localizationService.GetAllLanguages().ToList(); return ImportDictionaryItems(dictionaryItemElementList, languages, null, userId); } - private IReadOnlyList ImportDictionaryItems(IEnumerable dictionaryItemElementList, List languages, Guid? parentId, int userId) + private IReadOnlyList ImportDictionaryItems(IEnumerable dictionaryItemElementList, + List languages, Guid? parentId, int userId) { var items = new List(); foreach (XElement dictionaryItemElement in dictionaryItemElementList) @@ -1264,12 +1338,13 @@ namespace Umbraco.Cms.Infrastructure.Packaging return items; } - private IEnumerable ImportDictionaryItem(XElement dictionaryItemElement, List languages, Guid? parentId, int userId) + private IEnumerable ImportDictionaryItem(XElement dictionaryItemElement, + List languages, Guid? parentId, int userId) { var items = new List(); - IDictionaryItem dictionaryItem; - var itemName = dictionaryItemElement.Attribute("Name").Value; + IDictionaryItem? dictionaryItem; + var itemName = dictionaryItemElement.Attribute("Name")?.Value; Guid key = dictionaryItemElement.RequiredAttributeValue("Key"); dictionaryItem = _localizationService.GetDictionaryItemById(key); @@ -1279,20 +1354,23 @@ namespace Umbraco.Cms.Infrastructure.Packaging } else { - dictionaryItem = CreateNewDictionaryItem(key, itemName, dictionaryItemElement, languages, parentId); + dictionaryItem = CreateNewDictionaryItem(key, itemName!, dictionaryItemElement, languages, parentId); } _localizationService.Save(dictionaryItem, userId); items.Add(dictionaryItem); - items.AddRange(ImportDictionaryItems(dictionaryItemElement.Elements("DictionaryItem"), languages, dictionaryItem.Key, userId)); + items.AddRange(ImportDictionaryItems(dictionaryItemElement.Elements("DictionaryItem"), languages, + dictionaryItem.Key, userId)); return items; } - private IDictionaryItem UpdateDictionaryItem(IDictionaryItem dictionaryItem, XElement dictionaryItemElement, List languages) + private IDictionaryItem UpdateDictionaryItem(IDictionaryItem dictionaryItem, XElement dictionaryItemElement, + List languages) { var translations = dictionaryItem.Translations.ToList(); - foreach (var valueElement in dictionaryItemElement.Elements("Value").Where(v => DictionaryValueIsNew(translations, v))) + foreach (var valueElement in dictionaryItemElement.Elements("Value") + .Where(v => DictionaryValueIsNew(translations, v))) { AddDictionaryTranslation(translations, valueElement, languages); } @@ -1301,9 +1379,12 @@ namespace Umbraco.Cms.Infrastructure.Packaging return dictionaryItem; } - private static DictionaryItem CreateNewDictionaryItem(Guid itemId, string itemName, XElement dictionaryItemElement, List languages, Guid? parentId) + private static DictionaryItem CreateNewDictionaryItem(Guid itemId, string itemName, + XElement dictionaryItemElement, List languages, Guid? parentId) { - DictionaryItem dictionaryItem = parentId.HasValue ? new DictionaryItem(parentId.Value, itemName) : new DictionaryItem(itemName); + DictionaryItem dictionaryItem = parentId.HasValue + ? new DictionaryItem(parentId.Value, itemName) + : new DictionaryItem(itemName); dictionaryItem.Key = itemId; var translations = new List(); @@ -1317,12 +1398,17 @@ namespace Umbraco.Cms.Infrastructure.Packaging return dictionaryItem; } - private static bool DictionaryValueIsNew(IEnumerable translations, XElement valueElement) - => translations.All(t => string.Compare(t.Language.IsoCode, valueElement.Attribute("LanguageCultureAlias").Value, StringComparison.InvariantCultureIgnoreCase) != 0); + private static bool DictionaryValueIsNew(IEnumerable translations, + XElement valueElement) + => translations.All(t => string.Compare(t.Language?.IsoCode, + valueElement.Attribute("LanguageCultureAlias")?.Value, + StringComparison.InvariantCultureIgnoreCase) != + 0); - private static void AddDictionaryTranslation(ICollection translations, XElement valueElement, IEnumerable languages) + private static void AddDictionaryTranslation(ICollection translations, + XElement valueElement, IEnumerable languages) { - var languageId = valueElement.Attribute("LanguageCultureAlias").Value; + var languageId = valueElement.Attribute("LanguageCultureAlias")?.Value; var language = languages.SingleOrDefault(l => l.IsoCode == languageId); if (language == null) { @@ -1352,9 +1438,9 @@ namespace Umbraco.Cms.Infrastructure.Packaging var existingLanguage = _localizationService.GetLanguageByIsoCode(isoCode); if (existingLanguage != null) continue; - var langauge = new Language(_globalSettings, isoCode) + var langauge = new Language(_globalSettings, isoCode!) { - CultureName = languageElement.AttributeValue("FriendlyName") + CultureName = languageElement.AttributeValue("FriendlyName")! }; _localizationService.Save(langauge, userId); list.Add(langauge); @@ -1387,7 +1473,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging return macros; } - public IReadOnlyList ImportMacroPartialViews(IEnumerable macroPartialViewsElements, int userId) + public IReadOnlyList ImportMacroPartialViews(IEnumerable macroPartialViewsElements, + int userId) { var result = new List(); @@ -1406,18 +1493,20 @@ namespace Umbraco.Cms.Infrastructure.Packaging } else if (path.StartsWith("~")) { - _logger.LogWarning("Importing macro partial views outside of the Views/MacroPartials directory is not supported: {Path}", path); + _logger.LogWarning( + "Importing macro partial views outside of the Views/MacroPartials directory is not supported: {Path}", + path); continue; } - IPartialView macroPartialView = _fileService.GetPartialViewMacro(path); + IPartialView? macroPartialView = _fileService.GetPartialViewMacro(path); // only update if it doesn't exist if (macroPartialView == null) { var content = macroPartialViewXml.Value ?? string.Empty; - macroPartialView = new PartialView(PartialViewType.PartialViewMacro, path) { Content = content }; + macroPartialView = new PartialView(PartialViewType.PartialViewMacro, path) {Content = content}; _fileService.SavePartialViewMacro(macroPartialView, userId); result.Add(macroPartialView); } @@ -1428,10 +1517,10 @@ namespace Umbraco.Cms.Infrastructure.Packaging private IMacro ParseMacroElement(XElement macroElement) { - var macroKey = Guid.Parse(macroElement.Element("key").Value); - var macroName = macroElement.Element("name").Value; - var macroAlias = macroElement.Element("alias").Value; - var macroSource = macroElement.Element("macroSource").Value; + var macroKey = Guid.Parse(macroElement.Element("key")!.Value); + var macroName = macroElement.Element("name")?.Value; + var macroAlias = macroElement.Element("alias")!.Value; + var macroSource = macroElement.Element("macroSource")?.Value; //Following xml elements are treated as nullable properties var useInEditorElement = macroElement.Element("useInEditor"); @@ -1471,10 +1560,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging var existingMacro = _macroService.GetById(macroKey) as Macro; var macro = existingMacro ?? new Macro(_shortStringHelper, macroAlias, macroName, macroSource, - cacheByPage, cacheByMember, dontRender, useInEditor, cacheDuration) - { - Key = macroKey - }; + cacheByPage, cacheByMember, dontRender, useInEditor, cacheDuration) {Key = macroKey}; var properties = macroElement.Element("properties"); if (properties != null) @@ -1483,16 +1569,17 @@ namespace Umbraco.Cms.Infrastructure.Packaging foreach (XElement property in properties.Elements()) { var propertyKey = property.RequiredAttributeValue("key"); - var propertyName = property.Attribute("name").Value; - var propertyAlias = property.Attribute("alias").Value; - var editorAlias = property.Attribute("propertyType").Value; - XAttribute sortOrderAttribute = property.Attribute("sortOrder"); + var propertyName = property.Attribute("name")?.Value; + var propertyAlias = property.Attribute("alias")!.Value; + var editorAlias = property.Attribute("propertyType")!.Value; + XAttribute? sortOrderAttribute = property.Attribute("sortOrder"); if (sortOrderAttribute != null) { sortOrder = int.Parse(sortOrderAttribute.Value, CultureInfo.InvariantCulture); } - if (macro.Properties.Values.Any(x => string.Equals(x.Alias, propertyAlias, StringComparison.OrdinalIgnoreCase))) + if (macro.Properties.Values.Any(x => + string.Equals(x.Alias, propertyAlias, StringComparison.OrdinalIgnoreCase))) { continue; } @@ -1523,7 +1610,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging continue; } - IScript script = _fileService.GetScript(path); + IScript? script = _fileService.GetScript(path!); // only update if it doesn't exist if (script == null) @@ -1534,7 +1621,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging continue; } - script = new Script(path) { Content = content }; + script = new Script(path!) {Content = content}; _fileService.SaveScript(script, userId); result.Add(script); } @@ -1556,14 +1643,14 @@ namespace Umbraco.Cms.Infrastructure.Packaging throw new InvalidOperationException("No path attribute found"); } - IPartialView partialView = _fileService.GetPartialView(path); + IPartialView? partialView = _fileService.GetPartialView(path); // only update if it doesn't exist if (partialView == null) { var content = partialViewXml.Value ?? string.Empty; - partialView = new PartialView(PartialViewType.PartialView, path) { Content = content }; + partialView = new PartialView(PartialViewType.PartialView, path) {Content = content}; _fileService.SavePartialView(partialView, userId); result.Add(partialView); } @@ -1586,7 +1673,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging continue; } - IStylesheet s = _fileService.GetStylesheet(stylesheetPath); + IStylesheet? s = _fileService.GetStylesheet(stylesheetPath!); if (s == null) { var content = n.Element("Content")?.Value; @@ -1595,15 +1682,15 @@ namespace Umbraco.Cms.Infrastructure.Packaging continue; } - s = new Stylesheet(stylesheetPath) { Content = content }; + s = new Stylesheet(stylesheetPath!) {Content = content}; _fileService.SaveStylesheet(s, userId); } foreach (var prop in n.XPathSelectElements("Properties/Property")) { - var alias = prop.Element("Alias")?.Value; - var sp = s.Properties.SingleOrDefault(p => p != null && p.Alias == alias); - var name = prop.Element("Name")?.Value; + var alias = prop.Element("Alias")!.Value; + var sp = s.Properties?.SingleOrDefault(p => p != null && p.Alias == alias); + var name = prop.Element("Name")!.Value; if (sp == null) { sp = new StylesheetProperty(name, "#" + name.ToSafeAlias(_shortStringHelper), string.Empty); @@ -1623,7 +1710,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging } sp.Alias = alias; - sp.Value = prop.Element("Value")?.Value; + sp.Value = prop.Element("Value")!.Value; } _fileService.SaveStylesheet(s, userId); @@ -1638,7 +1725,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging #region Templates public IEnumerable ImportTemplate(XElement templateElement, int userId) - => ImportTemplates(new[] { templateElement }, userId); + => ImportTemplates(new[] {templateElement}, userId); /// /// Imports and saves package xml as @@ -1657,21 +1744,22 @@ namespace Umbraco.Cms.Infrastructure.Packaging var dependencies = new List(); var elementCopy = tempElement; //Ensure that the Master of the current template is part of the import, otherwise we ignore this dependency as part of the dependency sorting. - if (string.IsNullOrEmpty((string)elementCopy.Element("Master")) == false && - templateElements.Any(x => (string)x.Element("Alias") == (string)elementCopy.Element("Master"))) + if (string.IsNullOrEmpty((string?)elementCopy.Element("Master")) == false && + templateElements.Any(x => (string?)x.Element("Alias") == (string?)elementCopy.Element("Master"))) { - dependencies.Add((string)elementCopy.Element("Master")); + dependencies.Add((string)elementCopy.Element("Master")!); } - else if (string.IsNullOrEmpty((string)elementCopy.Element("Master")) == false && - templateElements.Any(x => (string)x.Element("Alias") == (string)elementCopy.Element("Master")) == false) + else if (string.IsNullOrEmpty((string?)elementCopy.Element("Master")) == false && + templateElements.Any(x => + (string?)x.Element("Alias") == (string?)elementCopy.Element("Master")) == false) { _logger.LogInformation( "Template '{TemplateAlias}' has an invalid Master '{TemplateMaster}', so the reference has been ignored.", - (string)elementCopy.Element("Alias"), - (string)elementCopy.Element("Master")); + (string?)elementCopy.Element("Alias"), + (string?)elementCopy.Element("Master")); } - graph.AddItem(TopoGraph.CreateNode((string)elementCopy.Element("Alias"), elementCopy, dependencies)); + graph.AddItem(TopoGraph.CreateNode((string)elementCopy.Element("Alias")!, elementCopy, dependencies)); } //Sort templates by dependencies to a potential master template @@ -1680,9 +1768,9 @@ namespace Umbraco.Cms.Infrastructure.Packaging { var templateElement = item.Item; - var templateName = templateElement.Element("Name").Value; - var alias = templateElement.Element("Alias").Value; - var design = templateElement.Element("Design").Value; + var templateName = templateElement.Element("Name")?.Value; + var alias = templateElement.Element("Alias")!.Value; + var design = templateElement.Element("Design")?.Value; var masterElement = templateElement.Element("Master"); var existingTemplate = _fileService.GetTemplate(alias) as Template; diff --git a/src/Umbraco.Infrastructure/Persistence/DatabaseAnnotations/ConstraintAttribute.cs b/src/Umbraco.Infrastructure/Persistence/DatabaseAnnotations/ConstraintAttribute.cs index 25744d63eb..8b8386c93f 100644 --- a/src/Umbraco.Infrastructure/Persistence/DatabaseAnnotations/ConstraintAttribute.cs +++ b/src/Umbraco.Infrastructure/Persistence/DatabaseAnnotations/ConstraintAttribute.cs @@ -15,11 +15,11 @@ namespace Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations /// Overrides the default naming of a property constraint: /// DF_tableName_propertyName /// - public string Name { get; set; } + public string? Name { get; set; } /// /// Gets or sets the Default value /// - public object Default { get; set; } + public object? Default { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Persistence/DatabaseModelDefinitions/ColumnDefinition.cs b/src/Umbraco.Infrastructure/Persistence/DatabaseModelDefinitions/ColumnDefinition.cs index c597b74cde..a80bbbe3f6 100644 --- a/src/Umbraco.Infrastructure/Persistence/DatabaseModelDefinitions/ColumnDefinition.cs +++ b/src/Umbraco.Infrastructure/Persistence/DatabaseModelDefinitions/ColumnDefinition.cs @@ -6,12 +6,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions { public class ColumnDefinition { - public virtual string Name { get; set; } + public virtual string Name { get; set; } = null!; //This type is typically used as part of a migration public virtual DbType? Type { get; set; } //When DbType isn't set explicitly the Type will be used to find the right DbType in the SqlSyntaxProvider. //This type is typically used as part of an initial table creation - public Type PropertyType { get; set; } + public Type PropertyType { get; set; } = null!; /// /// Used for column types that cannot be natively mapped. @@ -21,15 +21,15 @@ namespace Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions public virtual int Seeding { get; set; } public virtual int Size { get; set; } public virtual int Precision { get; set; } - public virtual string CustomType { get; set; } - public virtual object DefaultValue { get; set; } - public virtual string ConstraintName { get; set; } + public virtual string? CustomType { get; set; } + public virtual object? DefaultValue { get; set; } + public virtual string? ConstraintName { get; set; } public virtual bool IsForeignKey { get; set; } public virtual bool IsIdentity { get; set; } public virtual bool IsIndexed { get; set; }//Clustered? public virtual bool IsPrimaryKey { get; set; } - public virtual string PrimaryKeyName { get; set; } - public virtual string PrimaryKeyColumns { get; set; }//When the primary key spans multiple columns + public virtual string? PrimaryKeyName { get; set; } + public virtual string? PrimaryKeyColumns { get; set; }//When the primary key spans multiple columns public virtual bool IsNullable { get; set; } public virtual bool IsUnique { get; set; } public virtual string? TableName { get; set; } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/AccessDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/AccessDto.cs index ead7948191..e8842b7cfd 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/AccessDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/AccessDto.cs @@ -30,11 +30,11 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("createDate")] [Constraint(Default = SystemMethods.CurrentDateTime)] - public DateTime? CreateDate { get; set; } + public DateTime CreateDate { get; set; } [Column("updateDate")] [Constraint(Default = SystemMethods.CurrentDateTime)] - public DateTime? UpdateDate { get; set; } + public DateTime UpdateDate { get; set; } [ResultColumn] [Reference(ReferenceType.Many, ReferenceMemberName = "AccessId")] diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/AccessRuleDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/AccessRuleDto.cs index a730fe97f6..307f91337b 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/AccessRuleDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/AccessRuleDto.cs @@ -27,10 +27,10 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("createDate")] [Constraint(Default = SystemMethods.CurrentDateTime)] - public DateTime? CreateDate { get; set; } + public DateTime CreateDate { get; set; } [Column("updateDate")] [Constraint(Default = SystemMethods.CurrentDateTime)] - public DateTime? UpdateDate { get; set; } + public DateTime UpdateDate { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/AxisDefintionDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/AxisDefintionDto.cs index 226011cf90..431502a896 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/AxisDefintionDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/AxisDefintionDto.cs @@ -8,7 +8,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos public int NodeId { get; set; } [Column("alias")] - public string Alias { get; set; } + public string? Alias { get; set; } [Column("ParentID")] public int ParentId { get; set; } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/CacheInstructionDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/CacheInstructionDto.cs index 5dfa432f20..7d57fca606 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/CacheInstructionDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/CacheInstructionDto.cs @@ -21,12 +21,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("jsonInstruction")] [SpecialDbType(SpecialDbTypes.NTEXT)] [NullSetting(NullSetting = NullSettings.NotNull)] - public string Instructions { get; set; } + public string Instructions { get; set; } = null!; [Column("originated")] [NullSetting(NullSetting = NullSettings.NotNull)] [Length(500)] - public string OriginIdentity { get; set; } + public string OriginIdentity { get; set; } = null!; [Column("instructionCount")] [NullSetting(NullSetting = NullSettings.NotNull)] diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ColumnInSchemaDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ColumnInSchemaDto.cs index c5c1c158e2..961a54bf68 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/ColumnInSchemaDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ColumnInSchemaDto.cs @@ -5,21 +5,21 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos internal class ColumnInSchemaDto { [Column("TABLE_NAME")] - public string TableName { get; set; } + public string TableName { get; set; } = null!; [Column("COLUMN_NAME")] - public string ColumnName { get; set; } + public string ColumnName { get; set; } = null!; [Column("ORDINAL_POSITION")] public int OrdinalPosition { get; set; } [Column("COLUMN_DEFAULT")] - public string ColumnDefault { get; set; } + public string ColumnDefault { get; set; } = null!; [Column("IS_NULLABLE")] - public string IsNullable { get; set; } + public string IsNullable { get; set; } = null!; [Column("DATA_TYPE")] - public string DataType { get; set; } + public string DataType { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ConstraintPerColumnDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ConstraintPerColumnDto.cs index c8a05b41d7..e9aff45305 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/ConstraintPerColumnDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ConstraintPerColumnDto.cs @@ -5,12 +5,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos internal class ConstraintPerColumnDto { [Column("TABLE_NAME")] - public string TableName { get; set; } + public string TableName { get; set; } = null!; [Column("COLUMN_NAME")] - public string ColumnName { get; set; } + public string ColumnName { get; set; } = null!; [Column("CONSTRAINT_NAME")] - public string ConstraintName { get; set; } + public string ConstraintName { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ConstraintPerTableDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ConstraintPerTableDto.cs index c8bbf17114..c8f9a1abbf 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/ConstraintPerTableDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ConstraintPerTableDto.cs @@ -5,9 +5,9 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos internal class ConstraintPerTableDto { [Column("TABLE_NAME")] - public string TableName { get; set; } + public string TableName { get; set; } = null!; [Column("CONSTRAINT_NAME")] - public string ConstraintName { get; set; } + public string ConstraintName { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentDto.cs index c5a2b8b9c4..232f055e85 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentDto.cs @@ -21,13 +21,13 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [ResultColumn] [Reference(ReferenceType.OneToOne, ColumnName = "NodeId")] - public NodeDto NodeDto { get; set; } + public NodeDto NodeDto { get; set; } = null!; // although a content has many content versions, // they can only be loaded one by one (as several content), // so this here is a OneToOne reference [ResultColumn] [Reference(ReferenceType.OneToOne, ReferenceMemberName = "NodeId")] - public ContentVersionDto ContentVersionDto { get; set; } + public ContentVersionDto ContentVersionDto { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentNuDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentNuDto.cs index a5ca3496ee..eb3077cb3b 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentNuDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentNuDto.cs @@ -26,15 +26,15 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("data")] [SpecialDbType(SpecialDbTypes.NTEXT)] [NullSetting(NullSetting = NullSettings.Null)] - public string Data { get; set; } + public string? Data { get; set; } [Column("rv")] public long Rv { get; set; } [Column("dataRaw")] [NullSetting(NullSetting = NullSettings.Null)] - public byte[] RawData { get; set; } + public byte[]? RawData { get; set; } + - } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentScheduleDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentScheduleDto.cs index 4706f0417d..d50da8a124 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentScheduleDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentScheduleDto.cs @@ -28,6 +28,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos public DateTime Date { get; set; } [Column("action")] - public string Action { get; set; } + public string? Action { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeAllowedContentTypeDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeAllowedContentTypeDto.cs index 6f503b360c..c9a4b274b7 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeAllowedContentTypeDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeAllowedContentTypeDto.cs @@ -23,6 +23,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [ResultColumn] [Reference(ReferenceType.OneToOne)] - public ContentTypeDto ContentTypeDto { get; set; } + public ContentTypeDto? ContentTypeDto { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeTemplateDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeTemplateDto.cs index d6fe17f2c6..0b79aeb7aa 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeTemplateDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ContentTypeTemplateDto.cs @@ -24,6 +24,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [ResultColumn] [Reference(ReferenceType.OneToOne)] - public ContentTypeDto ContentTypeDto { get; set; } + public ContentTypeDto? ContentTypeDto { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/CreatedPackageSchemaDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/CreatedPackageSchemaDto.cs index 37e6fd8d8d..ae6b922657 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/CreatedPackageSchemaDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/CreatedPackageSchemaDto.cs @@ -20,12 +20,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Length(255)] [NullSetting(NullSetting = NullSettings.NotNull)] [Index(IndexTypes.UniqueNonClustered, ForColumns = "name", Name = "IX_" + TableName + "_Name")] - public string Name { get; set; } + public string Name { get; set; } = null!; [Column("value")] [SpecialDbType(SpecialDbTypes.NVARCHARMAX)] [NullSetting(NullSetting = NullSettings.NotNull)] - public string Value { get; set; } + public string Value { get; set; } = null!; [Column("updateDate")] [Constraint(Default = SystemMethods.CurrentDateTime)] diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/DataTypeDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/DataTypeDto.cs index b94cf3c541..c51ce4947c 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/DataTypeDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/DataTypeDto.cs @@ -14,11 +14,11 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos public int NodeId { get; set; } [Column("propertyEditorAlias")] - public string EditorAlias { get; set; } // TODO: should this have a length + public string EditorAlias { get; set; } = null!; // TODO: should this have a length [Column("dbType")] [Length(50)] - public string DbType { get; set; } + public string DbType { get; set; } = null!; [Column("config")] [SpecialDbType(SpecialDbTypes.NTEXT)] @@ -27,6 +27,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [ResultColumn] [Reference(ReferenceType.OneToOne, ColumnName = "NodeId")] - public NodeDto NodeDto { get; set; } + public NodeDto NodeDto { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/DefaultConstraintPerColumnDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/DefaultConstraintPerColumnDto.cs index 445f38f53c..1441133daa 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/DefaultConstraintPerColumnDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/DefaultConstraintPerColumnDto.cs @@ -4,16 +4,15 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos { internal class DefaultConstraintPerColumnDto { - [Column("TABLE_NAME")] - public string TableName { get; set; } + [Column("TABLE_NAME")] public string TableName { get; set; } = null!; [Column("COLUMN_NAME")] - public string ColumnName { get; set; } + public string ColumnName { get; set; } = null!; [Column("NAME")] - public string Name { get; set; } + public string Name { get; set; } = null!; [Column("DEFINITION")] - public string Definition { get; set; } + public string Definition { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/DefinedIndexDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/DefinedIndexDto.cs index 79a7de2273..287757dc9f 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/DefinedIndexDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/DefinedIndexDto.cs @@ -6,13 +6,13 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos { [Column("TABLE_NAME")] - public string TableName { get; set; } + public string TableName { get; set; } = null!; [Column("INDEX_NAME")] - public string IndexName { get; set; } + public string IndexName { get; set; } = null!; [Column("COLUMN_NAME")] - public string ColumnName { get; set; } + public string ColumnName { get; set; } = null!; [Column("UNIQUE")] public short Unique { get; set; } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/DictionaryDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/DictionaryDto.cs index ac95a2fdf2..ad14f20c6b 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/DictionaryDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/DictionaryDto.cs @@ -29,10 +29,10 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("key")] [Length(450)] [Index(IndexTypes.UniqueNonClustered, Name = "IX_" + TableName + "_key")] - public string Key { get; set; } + public string Key { get; set; } = null!; [ResultColumn] [Reference(ReferenceType.Many, ColumnName = "UniqueId", ReferenceMemberName = "UniqueId")] - public List LanguageTextDtos { get; set; } + public List? LanguageTextDtos { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/DocumentDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/DocumentDto.cs index 7f63157c43..39e4e933b2 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/DocumentDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/DocumentDto.cs @@ -41,18 +41,18 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [ResultColumn] [Reference(ReferenceType.OneToOne, ReferenceMemberName = "NodeId")] - public ContentDto ContentDto { get; set; } + public ContentDto ContentDto { get; set; } = null!; // although a content has many content versions, // they can only be loaded one by one (as several content), // so this here is a OneToOne reference [ResultColumn] [Reference(ReferenceType.OneToOne)] - public DocumentVersionDto DocumentVersionDto { get; set; } + public DocumentVersionDto DocumentVersionDto { get; set; } = null!; // same [ResultColumn] [Reference(ReferenceType.OneToOne)] - public DocumentVersionDto PublishedVersionDto { get; set; } + public DocumentVersionDto PublishedVersionDto { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/DocumentVersionDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/DocumentVersionDto.cs index decf793b9a..2d06129ba6 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/DocumentVersionDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/DocumentVersionDto.cs @@ -25,6 +25,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [ResultColumn] [Reference(ReferenceType.OneToOne)] - public ContentVersionDto ContentVersionDto { get; set; } + public ContentVersionDto ContentVersionDto { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/DomainDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/DomainDto.cs index ac85ef8044..60f0635035 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/DomainDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/DomainDto.cs @@ -22,12 +22,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos public int? RootStructureId { get; set; } [Column("domainName")] - public string DomainName { get; set; } + public string DomainName { get; set; } = null!; /// /// Used for a result on the query to get the associated language for a domain if there is one /// [ResultColumn("languageISOCode")] - public string IsoCode { get; set; } + public string IsoCode { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ExternalLoginTokenDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ExternalLoginTokenDto.cs index c5f3b7c8ac..cd16703bdc 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/ExternalLoginTokenDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ExternalLoginTokenDto.cs @@ -17,19 +17,19 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos public int Id { get; set; } [Column("externalLoginId")] - [ForeignKey(typeof(ExternalLoginDto), Column = "id")] + [ForeignKey(typeof(ExternalLoginDto), Column = "id")] public int ExternalLoginId { get; set; } [Column("name")] [Length(255)] [NullSetting(NullSetting = NullSettings.NotNull)] [Index(IndexTypes.UniqueNonClustered, ForColumns = "externalLoginId,name", Name = "IX_" + TableName + "_Name")] - public string Name { get; set; } + public string Name { get; set; } = null!; [Column("value")] [SpecialDbType(SpecialDbTypes.NVARCHARMAX)] [NullSetting(NullSetting = NullSettings.NotNull)] - public string Value { get; set; } + public string Value { get; set; } = null!; [Column("createDate")] [Constraint(Default = SystemMethods.CurrentDateTime)] @@ -37,6 +37,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [ResultColumn] [Reference(ReferenceType.OneToOne, ColumnName = "ExternalLoginId")] - public ExternalLoginDto ExternalLoginDto { get; set; } + public ExternalLoginDto ExternalLoginDto { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/KeyValueDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/KeyValueDto.cs index b23f9a6c04..654d3071b0 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/KeyValueDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/KeyValueDto.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("key")] [Length(256)] [PrimaryKeyColumn(AutoIncrement = false, Clustered = true)] - public string? Key { get; set; } + public string Key { get; set; } = null!; [Column("value")] [NullSetting(NullSetting = NullSettings.Null)] @@ -21,6 +21,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("updated")] [Constraint(Default = SystemMethods.CurrentDateTime)] - public DateTime? UpdateDate { get; set; } + public DateTime UpdateDate { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/LanguageDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/LanguageDto.cs index 1cbbda465a..e5b25fa166 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/LanguageDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/LanguageDto.cs @@ -24,7 +24,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Index(IndexTypes.UniqueNonClustered)] [NullSetting(NullSetting = NullSettings.Null)] [Length(14)] - public string IsoCode { get; set; } + public string? IsoCode { get; set; } /// /// Gets or sets the culture name of the language. @@ -32,7 +32,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("languageCultureName")] [NullSetting(NullSetting = NullSettings.Null)] [Length(100)] - public string CultureName { get; set; } + public string? CultureName { get; set; } /// /// Gets or sets a value indicating whether the language is the default language. diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/LanguageTextDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/LanguageTextDto.cs index 0928e828f4..3d08c9de98 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/LanguageTextDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/LanguageTextDto.cs @@ -26,6 +26,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("value")] [Length(1000)] - public string Value { get; set; } + public string Value { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/LockDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/LockDto.cs index 89bb5d12af..21fe45c22b 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/LockDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/LockDto.cs @@ -19,6 +19,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("name")] [NullSetting(NullSetting = NullSettings.NotNull)] [Length(64)] - public string Name { get; set; } + public string Name { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/MediaDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/MediaDto.cs index 661b9589f8..374f2437ff 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/MediaDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/MediaDto.cs @@ -12,10 +12,10 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [ResultColumn] [Reference(ReferenceType.OneToOne, ReferenceMemberName = "NodeId")] - public ContentDto ContentDto { get; set; } + public ContentDto ContentDto { get; set; } = null!; [ResultColumn] [Reference(ReferenceType.OneToOne)] - public MediaVersionDto MediaVersionDto { get; set; } + public MediaVersionDto MediaVersionDto { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/MediaVersionDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/MediaVersionDto.cs index bcea2e7673..dabdb14ca7 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/MediaVersionDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/MediaVersionDto.cs @@ -22,6 +22,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [ResultColumn] [Reference(ReferenceType.OneToOne)] - public ContentVersionDto ContentVersionDto { get; set; } + public ContentVersionDto ContentVersionDto { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/NodeDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/NodeDto.cs index bd41a2a297..621aba121a 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/NodeDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/NodeDto.cs @@ -63,6 +63,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("createDate")] [Constraint(Default = SystemMethods.CurrentDateTime)] - public DateTime? CreateDate { get; set; } + public DateTime CreateDate { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeGroupDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeGroupDto.cs index 8b116fab59..489cb7fcb5 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeGroupDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeGroupDto.cs @@ -35,7 +35,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos public string? Text { get; set; } [Column("alias")] - public string Alias { get; set; } + public string Alias { get; set; } = null!; [Column("sortorder")] public int SortOrder { get; set; } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeGroupReadOnlyDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeGroupReadOnlyDto.cs index 1dc7956f29..f93b9b602a 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeGroupReadOnlyDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeGroupReadOnlyDto.cs @@ -12,7 +12,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos public int? Id { get; set; } [Column("PropertyGroupName")] - public string Text { get; set; } + public string? Text { get; set; } [Column("PropertyGroupSortOrder")] public int SortOrder { get; set; } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeReadOnlyDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeReadOnlyDto.cs index 018fddba33..ae1358b5cd 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeReadOnlyDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/PropertyTypeReadOnlyDto.cs @@ -21,10 +21,10 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos public int? PropertyTypeGroupId { get; set; } [Column("Alias")] - public string Alias { get; set; } + public string? Alias { get; set; } [Column("Name")] - public string Name { get; set; } + public string? Name { get; set; } [Column("PropertyTypeSortOrder")] public int SortOrder { get; set; } @@ -33,16 +33,16 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos public bool Mandatory { get; set; } [Column("mandatoryMessage")] - public string MandatoryMessage { get; set; } + public string? MandatoryMessage { get; set; } [Column("validationRegExp")] - public string ValidationRegExp { get; set; } + public string? ValidationRegExp { get; set; } [Column("validationRegExpMessage")] - public string ValidationRegExpMessage { get; set; } + public string? ValidationRegExpMessage { get; set; } [Column("Description")] - public string Description { get; set; } + public string? Description { get; set; } [Column("labelOnTop")] public bool LabelOnTop { get; set; } @@ -59,10 +59,10 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos /* DataType */ [Column("propertyEditorAlias")] - public string PropertyEditorAlias { get; set; } + public string? PropertyEditorAlias { get; set; } [Column("dbType")] - public string DbType { get; set; } + public string? DbType { get; set; } [Column("UniqueID")] public Guid UniqueId { get; set; } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/RelationDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/RelationDto.cs index d872801163..b197f12692 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/RelationDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/RelationDto.cs @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("datetime")] [Constraint(Default = SystemMethods.CurrentDateTime)] - public DateTime? Datetime { get; set; } + public DateTime Datetime { get; set; } [Column("comment")] [Length(1000)] diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/RelationTypeDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/RelationTypeDto.cs index 50d7960ff8..28cbcaed2d 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/RelationTypeDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/RelationTypeDto.cs @@ -33,12 +33,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("name")] [NullSetting(NullSetting = NullSettings.NotNull)] [Index(IndexTypes.UniqueNonClustered, Name = "IX_umbracoRelationType_name")] - public string Name { get; set; } + public string Name { get; set; } = null!; [Column("alias")] [NullSetting(NullSetting = NullSettings.NotNull)] [Length(100)] [Index(IndexTypes.UniqueNonClustered, Name = "IX_umbracoRelationType_alias")] - public string Alias { get; set; } + public string Alias { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/ServerRegistrationDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/ServerRegistrationDto.cs index b50d3ca3d2..89ef0039ab 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/ServerRegistrationDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/ServerRegistrationDto.cs @@ -25,10 +25,10 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("registeredDate")] [Constraint(Default = SystemMethods.CurrentDateTime)] - public DateTime? DateRegistered { get; set; } + public DateTime DateRegistered { get; set; } [Column("lastNotifiedDate")] - public DateTime? DateAccessed { get; set; } + public DateTime DateAccessed { get; set; } [Column("isActive")] [Index(IndexTypes.NonClustered)] diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/TemplateDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/TemplateDto.cs index 474d9692d7..9a80cdd8e2 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/TemplateDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/TemplateDto.cs @@ -20,10 +20,10 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("alias")] [Length(100)] [NullSetting(NullSetting = NullSettings.Null)] - public string Alias { get; set; } + public string? Alias { get; set; } [ResultColumn] [Reference(ReferenceType.OneToOne, ColumnName = "NodeId")] - public NodeDto NodeDto { get; set; } + public NodeDto NodeDto { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/User2NodeNotifyDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/User2NodeNotifyDto.cs index 59d8cdd2c8..fd8806124e 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/User2NodeNotifyDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/User2NodeNotifyDto.cs @@ -20,6 +20,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("action")] [SpecialDbType(SpecialDbTypes.NCHAR)] [Length(1)] - public string Action { get; set; } + public string? Action { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2AppDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2AppDto.cs index 4b2af86a53..b5719c1c63 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2AppDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2AppDto.cs @@ -14,6 +14,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos [Column("app")] [Length(50)] - public string AppAlias { get; set; } + public string AppAlias { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2NodePermissionDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2NodePermissionDto.cs index e9b216fdba..4461089f96 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2NodePermissionDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/UserGroup2NodePermissionDto.cs @@ -18,6 +18,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos public int NodeId { get; set; } [Column("permission")] - public string Permission { get; set; } + public string? Permission { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/UserLoginDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/UserLoginDto.cs index 6508afcec0..4d18a39557 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/UserLoginDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/UserLoginDto.cs @@ -52,6 +52,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos /// [Column("ipAddress")] [NullSetting(NullSetting = NullSettings.Null)] - public string IpAddress { get; set; } + public string? IpAddress { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Dtos/UserNotificationDto.cs b/src/Umbraco.Infrastructure/Persistence/Dtos/UserNotificationDto.cs index 7c947dd9f2..c6116648c7 100644 --- a/src/Umbraco.Infrastructure/Persistence/Dtos/UserNotificationDto.cs +++ b/src/Umbraco.Infrastructure/Persistence/Dtos/UserNotificationDto.cs @@ -15,6 +15,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Dtos public Guid NodeObjectType { get; set; } [Column("action")] - public string Action { get; set; } + public string Action { get; set; } = null!; } } diff --git a/src/Umbraco.Infrastructure/Persistence/Factories/UserFactory.cs b/src/Umbraco.Infrastructure/Persistence/Factories/UserFactory.cs index e4f98c708c..efb4acb6d7 100644 --- a/src/Umbraco.Infrastructure/Persistence/Factories/UserFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/Factories/UserFactory.cs @@ -112,7 +112,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Factories { return new ReadOnlyUserGroup(group.Id, group.Name, group.Icon, group.StartContentId, group.StartMediaId, group.Alias, - group.UserGroup2AppDtos.Select(x => x.AppAlias).ToArray(), + group.UserGroup2AppDtos.Select(x => x.AppAlias).WhereNotNull().ToArray(), group.DefaultPermissions == null ? Enumerable.Empty() : group.DefaultPermissions.ToCharArray().Select(x => x.ToString())); } } diff --git a/src/Umbraco.Infrastructure/Persistence/IUmbracoDatabaseFactory.cs b/src/Umbraco.Infrastructure/Persistence/IUmbracoDatabaseFactory.cs index 10af5a7421..382eda81b0 100644 --- a/src/Umbraco.Infrastructure/Persistence/IUmbracoDatabaseFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/IUmbracoDatabaseFactory.cs @@ -59,7 +59,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence /// /// Getting the causes the factory to initialize if it is not already initialized. /// - ISqlContext? SqlContext { get; } + ISqlContext SqlContext { get; } /// /// Gets the . diff --git a/src/Umbraco.Infrastructure/Persistence/Querying/CachedExpression.cs b/src/Umbraco.Infrastructure/Persistence/Querying/CachedExpression.cs index ba02920de0..ae812193c9 100644 --- a/src/Umbraco.Infrastructure/Persistence/Querying/CachedExpression.cs +++ b/src/Umbraco.Infrastructure/Persistence/Querying/CachedExpression.cs @@ -8,12 +8,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Querying /// internal class CachedExpression : Expression { - private string _visitResult; + private string _visitResult = null!; /// /// Gets or sets the inner Expression. /// - public Expression InnerExpression { get; private set; } + public Expression InnerExpression { get; private set; } = null!; /// /// Gets or sets the compiled SQL statement output. diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs index 630620901a..499664e9e7 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs @@ -169,7 +169,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement .Select(documentDto => documentDto.DocumentVersionDto, r1 => r1.Select(documentVersionDto => documentVersionDto.ContentVersionDto)) .Select(documentDto => documentDto.PublishedVersionDto, "pdv", r1 => - r1.Select(documentVersionDto => documentVersionDto.ContentVersionDto, "pcv"))) + r1.Select(documentVersionDto => documentVersionDto!.ContentVersionDto, "pcv"))) // select the variant name, coalesce to the invariant name, as "variantName" .AndSelect(VariantNameSqlExpression + " AS variantName"); diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/KeyValueRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/KeyValueRepository.cs index 8a752776da..a1d9658e38 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/KeyValueRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/KeyValueRepository.cs @@ -21,9 +21,9 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement { } /// - public IReadOnlyDictionary? FindByKeyPrefix(string keyPrefix) + public IReadOnlyDictionary? FindByKeyPrefix(string keyPrefix) => Get(Query().Where(entity => entity.Identifier!.StartsWith(keyPrefix)))? - .ToDictionary(x => x.Identifier!, x => x.Value!); + .ToDictionary(x => x.Identifier!, x => x.Value); #region Overrides of IReadWriteQueryRepository diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberGroupRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberGroupRepository.cs index 16d400858c..66eb4b5da5 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberGroupRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberGroupRepository.cs @@ -137,7 +137,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement typeof(IMemberGroup).FullName + "." + name, () => { - var qry = Query().Where(group => group.Name.Equals(name)); + var qry = Query().Where(group => group.Name!.Equals(name)); var result = Get(qry); return result?.FirstOrDefault(); }, diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/PermissionRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/PermissionRepository.cs index 24a18380ac..9919707e8a 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/PermissionRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/PermissionRepository.cs @@ -328,7 +328,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement // perms can contain null if there are no permissions assigned, but the node is chosen in the UI. permissions.Add(new EntityPermission(permission.Key, np.Key, - perms.Where(x => x is not null).ToArray())); + perms.WhereNotNull().ToArray())); } } diff --git a/src/Umbraco.Infrastructure/Persistence/SqlSyntax/SqlSyntaxProviderBase.cs b/src/Umbraco.Infrastructure/Persistence/SqlSyntax/SqlSyntaxProviderBase.cs index 86dd570b43..fd07c46685 100644 --- a/src/Umbraco.Infrastructure/Persistence/SqlSyntax/SqlSyntaxProviderBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/SqlSyntax/SqlSyntaxProviderBase.cs @@ -503,7 +503,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.SqlSyntax return string.Format(DecimalColumnDefinitionFormat, precision, scale); } - var definition = DbTypeMap.ColumnTypeMap[type]; + var definition = DbTypeMap.ColumnTypeMap[type!]; var dbTypeDefinition = column.Size != default ? $"{definition}({column.Size})" : definition; diff --git a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs index 799c4f5729..95c0f01093 100644 --- a/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs @@ -50,7 +50,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence private RetryPolicy? _connectionRetryPolicy; private RetryPolicy? _commandRetryPolicy; private NPoco.MapperCollection? _pocoMappers; - private SqlContext? _sqlContext; + private SqlContext _sqlContext = null!; private bool _upgrading; private bool _initialized; @@ -197,7 +197,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence } /// - public ISqlContext? SqlContext + public ISqlContext SqlContext { get { diff --git a/src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerValueEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerValueEditor.cs index 0386514b51..4c84ce5f64 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerValueEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerValueEditor.cs @@ -66,14 +66,14 @@ namespace Umbraco.Cms.Core.PropertyEditors if (documentLinks?.Count > 0) { entities.AddRange( - _entityService.GetAll(UmbracoObjectTypes.Document, documentLinks.Select(link => link.Udi?.Guid).ToArray()) + _entityService.GetAll(UmbracoObjectTypes.Document, documentLinks.Select(link => link.Udi!.Guid).ToArray()) ); } if (mediaLinks?.Count > 0) { entities.AddRange( - _entityService.GetAll(UmbracoObjectTypes.Media, mediaLinks.Select(link => link.Udi?.Guid).ToArray()) + _entityService.GetAll(UmbracoObjectTypes.Media, mediaLinks.Select(link => link.Udi!.Guid).ToArray()) ); } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyHandler.cs b/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyHandler.cs index 35389d88ff..58c1f2461e 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyHandler.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyHandler.cs @@ -49,10 +49,10 @@ namespace Umbraco.Cms.Core.PropertyEditors { // get it's sibling 'key' property var ncKeyVal = prop.Parent?["key"] as JValue; - if (((onlyMissingKeys && ncKeyVal == null) || (!onlyMissingKeys && ncKeyVal != null)) && prop.Parent?["key"] is not null) + if ((onlyMissingKeys && ncKeyVal == null) || (!onlyMissingKeys && ncKeyVal != null)) { // create or replace - prop.Parent["key"] = createGuid().ToString(); + prop.Parent!["key"] = createGuid().ToString(); } } else if (!isNestedContent || prop.Name != "key") diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/BlockListPropertyValueConverter.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/BlockListPropertyValueConverter.cs index 421a258f7a..dc1663b14d 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/BlockListPropertyValueConverter.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/BlockListPropertyValueConverter.cs @@ -44,7 +44,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters } /// - public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, + public override object? ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview) { // NOTE: The intermediate object is just a json string, we don't actually convert from source -> intermediate since source is always just a json string @@ -64,15 +64,19 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters // Get configuration var configuration = propertyType.DataType.ConfigurationAs(); - var blockConfigMap = configuration?.Blocks?.ToDictionary(x => x.ContentElementTypeKey); - var validSettingsElementTypes = blockConfigMap?.Values.Select(x => x.SettingsElementTypeKey) + if (configuration is null) + { + return null; + } + var blockConfigMap = configuration.Blocks.ToDictionary(x => x.ContentElementTypeKey); + var validSettingsElementTypes = blockConfigMap.Values.Select(x => x.SettingsElementTypeKey) .Where(x => x.HasValue).Distinct().ToList(); // Convert the content data var contentPublishedElements = new Dictionary(); foreach (var data in converted.BlockValue.ContentData) { - if (!blockConfigMap?.ContainsKey(data.ContentTypeKey) ?? false) continue; + if (!blockConfigMap.ContainsKey(data.ContentTypeKey)) continue; var element = _blockConverter.ConvertToElement(data, referenceCacheLevel, preview); if (element == null) continue; @@ -105,7 +109,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters if (contentGuidUdi is null || !contentPublishedElements.TryGetValue(contentGuidUdi.Guid, out var contentData)) continue; - if (contentData is null || (!blockConfigMap?.TryGetValue(contentData.ContentType.Key, out var blockConfig) ?? true)) + if (contentData is null || (!blockConfigMap.TryGetValue(contentData.ContentType.Key, out var blockConfig))) continue; // Get the setting reference diff --git a/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs b/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs index 20eea6a3df..b7d6f0ea6e 100644 --- a/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs +++ b/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs @@ -436,12 +436,12 @@ namespace Umbraco.Cms.Core.Security // don't assign anything if nothing has changed as this will trigger the track changes of the model if (identityUser.IsPropertyDirty(nameof(BackOfficeIdentityUser.LastLoginDateUtc)) || (user.LastLoginDate != default && identityUser.LastLoginDateUtc.HasValue == false) - || (identityUser.LastLoginDateUtc.HasValue && user.LastLoginDate?.ToUniversalTime() != identityUser.LastLoginDateUtc.Value)) + || (identityUser.LastLoginDateUtc.HasValue && user.LastLoginDate.ToUniversalTime() != identityUser.LastLoginDateUtc.Value)) { anythingChanged = true; // if the LastLoginDate is being set to MinValue, don't convert it ToLocalTime - DateTime? dt = identityUser.LastLoginDateUtc == DateTime.MinValue ? DateTime.MinValue : identityUser.LastLoginDateUtc?.ToLocalTime(); + DateTime dt = identityUser.LastLoginDateUtc == DateTime.MinValue ? DateTime.MinValue : identityUser.LastLoginDateUtc?.ToLocalTime() ?? DateTime.MinValue; user.LastLoginDate = dt; } @@ -454,10 +454,10 @@ namespace Umbraco.Cms.Core.Security if (identityUser.IsPropertyDirty(nameof(BackOfficeIdentityUser.LastPasswordChangeDateUtc)) || (user.LastPasswordChangeDate != default && identityUser.LastPasswordChangeDateUtc.HasValue == false) - || (identityUser.LastPasswordChangeDateUtc.HasValue && user.LastPasswordChangeDate?.ToUniversalTime() != identityUser.LastPasswordChangeDateUtc.Value)) + || (identityUser.LastPasswordChangeDateUtc.HasValue && user.LastPasswordChangeDate.ToUniversalTime() != identityUser.LastPasswordChangeDateUtc.Value)) { anythingChanged = true; - user.LastPasswordChangeDate = identityUser.LastPasswordChangeDateUtc?.ToLocalTime(); + user.LastPasswordChangeDate = identityUser.LastPasswordChangeDateUtc?.ToLocalTime() ?? DateTime.Now; } if (identityUser.IsPropertyDirty(nameof(BackOfficeIdentityUser.EmailConfirmed)) diff --git a/src/Umbraco.Infrastructure/Security/IdentityMapDefinition.cs b/src/Umbraco.Infrastructure/Security/IdentityMapDefinition.cs index d3c616af0a..7e1a2dcf9a 100644 --- a/src/Umbraco.Infrastructure/Security/IdentityMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Security/IdentityMapDefinition.cs @@ -72,8 +72,8 @@ namespace Umbraco.Cms.Core.Security target.CalculatedContentStartNodeIds = source.CalculateContentStartNodeIds(_entityService, _appCaches); target.Email = source.Email; target.UserName = source.Username; - target.LastPasswordChangeDateUtc = source.LastPasswordChangeDate?.ToUniversalTime(); - target.LastLoginDateUtc = source.LastLoginDate?.ToUniversalTime(); + target.LastPasswordChangeDateUtc = source.LastPasswordChangeDate.ToUniversalTime(); + target.LastLoginDateUtc = source.LastLoginDate.ToUniversalTime(); target.InviteDateUtc = source.InvitedDate?.ToUniversalTime(); target.EmailConfirmed = source.EmailConfirmedDate.HasValue; target.Name = source.Name; @@ -93,8 +93,8 @@ namespace Umbraco.Cms.Core.Security { target.Email = source.Email; target.UserName = source.Username; - target.LastPasswordChangeDateUtc = source.LastPasswordChangeDate?.ToUniversalTime(); - target.LastLoginDateUtc = source.LastLoginDate?.ToUniversalTime(); + target.LastPasswordChangeDateUtc = source.LastPasswordChangeDate.ToUniversalTime(); + target.LastLoginDateUtc = source.LastLoginDate.ToUniversalTime(); target.EmailConfirmed = source.EmailConfirmedDate.HasValue; target.Name = source.Name; target.AccessFailedCount = source.FailedPasswordAttempts; diff --git a/src/Umbraco.Infrastructure/Security/MemberUserStore.cs b/src/Umbraco.Infrastructure/Security/MemberUserStore.cs index 24fab739e5..2386e5b65a 100644 --- a/src/Umbraco.Infrastructure/Security/MemberUserStore.cs +++ b/src/Umbraco.Infrastructure/Security/MemberUserStore.cs @@ -563,21 +563,21 @@ namespace Umbraco.Cms.Core.Security // don't assign anything if nothing has changed as this will trigger the track changes of the model if (identityUser.IsPropertyDirty(nameof(MemberIdentityUser.LastLoginDateUtc)) || (member.LastLoginDate != default && identityUser.LastLoginDateUtc.HasValue == false) - || (identityUser.LastLoginDateUtc.HasValue && member.LastLoginDate?.ToUniversalTime() != identityUser.LastLoginDateUtc.Value)) + || (identityUser.LastLoginDateUtc.HasValue && member.LastLoginDate.ToUniversalTime() != identityUser.LastLoginDateUtc.Value)) { changeType = MemberDataChangeType.LoginOnly; // if the LastLoginDate is being set to MinValue, don't convert it ToLocalTime - DateTime? dt = identityUser.LastLoginDateUtc == DateTime.MinValue ? DateTime.MinValue : identityUser.LastLoginDateUtc?.ToLocalTime(); + DateTime dt = identityUser.LastLoginDateUtc == DateTime.MinValue ? DateTime.MinValue : identityUser.LastLoginDateUtc?.ToLocalTime() ?? DateTime.MinValue; member.LastLoginDate = dt; } if (identityUser.IsPropertyDirty(nameof(MemberIdentityUser.LastPasswordChangeDateUtc)) || (member.LastPasswordChangeDate != default && identityUser.LastPasswordChangeDateUtc.HasValue == false) - || (identityUser.LastPasswordChangeDateUtc.HasValue && member.LastPasswordChangeDate?.ToUniversalTime() != identityUser.LastPasswordChangeDateUtc.Value)) + || (identityUser.LastPasswordChangeDateUtc.HasValue && member.LastPasswordChangeDate.ToUniversalTime() != identityUser.LastPasswordChangeDateUtc.Value)) { changeType = MemberDataChangeType.FullSave; - member.LastPasswordChangeDate = identityUser.LastPasswordChangeDateUtc?.ToLocalTime(); + member.LastPasswordChangeDate = identityUser.LastPasswordChangeDateUtc?.ToLocalTime() ?? DateTime.Now; } if (identityUser.IsPropertyDirty(nameof(MemberIdentityUser.Comments)) diff --git a/src/Umbraco.Infrastructure/Security/SignOutSuccessResult.cs b/src/Umbraco.Infrastructure/Security/SignOutSuccessResult.cs index f1b4688505..539e0f1ed6 100644 --- a/src/Umbraco.Infrastructure/Security/SignOutSuccessResult.cs +++ b/src/Umbraco.Infrastructure/Security/SignOutSuccessResult.cs @@ -2,6 +2,6 @@ namespace Umbraco.Cms.Infrastructure.Security { public class SignOutSuccessResult { - public string SignOutRedirectUrl { get; set; } + public string? SignOutRedirectUrl { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs b/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs index 65ea915433..10aea6c888 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs @@ -111,7 +111,7 @@ namespace Umbraco.Cms.Core.Services.Implement public IEnumerable GetAllInstalledPackages() { - IReadOnlyDictionary keyValues = _keyValueService.FindByKeyPrefix(Constants.Conventions.Migrations.KeyValuePrefix); + IReadOnlyDictionary? keyValues = _keyValueService.FindByKeyPrefix(Constants.Conventions.Migrations.KeyValuePrefix); var installedPackages = new Dictionary(); @@ -128,7 +128,12 @@ namespace Umbraco.Cms.Core.Services.Implement } var currentPlans = installedPackage.PackageMigrationPlans.ToList(); - keyValues.TryGetValue(Constants.Conventions.Migrations.KeyValuePrefix + plan.Name, out var currentState); + if (keyValues is null || keyValues.TryGetValue(Constants.Conventions.Migrations.KeyValuePrefix + plan.Name, + out var currentState)) + { + currentState = null; + } + currentPlans.Add(new InstalledPackageMigrationPlans { CurrentMigrationId = currentState, diff --git a/src/Umbraco.Web.BackOffice/Controllers/LogViewerController.cs b/src/Umbraco.Web.BackOffice/Controllers/LogViewerController.cs index 2fd5521b27..b7303e53d5 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/LogViewerController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/LogViewerController.cs @@ -149,7 +149,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers } [HttpGet] - public ReadOnlyDictionary GetLogLevels() + public ReadOnlyDictionary GetLogLevels() { return _logLevelLoader.GetLogLevelsFromSinks(); }