Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V15/task/cleanup obsolete #17433

Merged
merged 15 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task<IActionResult> Index(CancellationToken cancellationToken, Back

if (string.IsNullOrEmpty(model.UmbracoUrl))
{
model.UmbracoUrl = _hostingEnvironment.ToAbsolute(_globalSettings.UmbracoPath);
model.UmbracoUrl = _hostingEnvironment.ToAbsolute(Constants.System.DefaultUmbracoPath);
}

if (string.IsNullOrEmpty(model.ReturnUrl))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore;

Check notice on line 1 in src/Umbraco.Cms.Persistence.EFCore/Extensions/UmbracoEFCoreServiceCollectionExtensions.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/15.0)

✅ No longer an issue: Code Duplication

The module no longer contains too many functions with similar structure
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Serilog;
Expand All @@ -14,45 +14,6 @@
{
public delegate void DefaultEFCoreOptionsAction(DbContextOptionsBuilder options, string? providerName, string? connectionString);

[Obsolete("Use AddUmbracoDbContext<T>(this IServiceCollection services, Action<DbContextOptionsBuilder>? optionsAction = null) instead.")]
public static IServiceCollection AddUmbracoEFCoreContext<T>(this IServiceCollection services, DefaultEFCoreOptionsAction? defaultEFCoreOptionsAction = null)
where T : DbContext
{
services.AddPooledDbContextFactory<T>((provider, builder) => SetupDbContext(defaultEFCoreOptionsAction, provider, builder));
services.AddTransient(services => services.GetRequiredService<IDbContextFactory<T>>().CreateDbContext());

services.AddUnique<IAmbientEFCoreScopeStack<T>, AmbientEFCoreScopeStack<T>>();
services.AddUnique<IEFCoreScopeAccessor<T>, EFCoreScopeAccessor<T>>();
services.AddUnique<IEFCoreScopeProvider<T>, EFCoreScopeProvider<T>>();
services.AddSingleton<IDistributedLockingMechanism, SqliteEFCoreDistributedLockingMechanism<T>>();
services.AddSingleton<IDistributedLockingMechanism, SqlServerEFCoreDistributedLockingMechanism<T>>();

return services;
}

[Obsolete("Use AddUmbracoDbContext<T>(this IServiceCollection services, Action<DbContextOptionsBuilder>? optionsAction = null) instead.")]
public static IServiceCollection AddUmbracoEFCoreContext<T>(this IServiceCollection services, string connectionString, string providerName, DefaultEFCoreOptionsAction? defaultEFCoreOptionsAction = null)
where T : DbContext
{
// Replace data directory
string? dataDirectory = AppDomain.CurrentDomain.GetData(Constants.System.DataDirectoryName)?.ToString();
if (string.IsNullOrEmpty(dataDirectory) is false)
{
connectionString = connectionString.Replace(Constants.System.DataDirectoryPlaceholder, dataDirectory);
}

services.AddPooledDbContextFactory<T>(options => defaultEFCoreOptionsAction?.Invoke(options, providerName, connectionString));
services.AddTransient(services => services.GetRequiredService<IDbContextFactory<T>>().CreateDbContext());

services.AddUnique<IAmbientEFCoreScopeStack<T>, AmbientEFCoreScopeStack<T>>();
services.AddUnique<IEFCoreScopeAccessor<T>, EFCoreScopeAccessor<T>>();
services.AddUnique<IEFCoreScopeProvider<T>, EFCoreScopeProvider<T>>();
services.AddSingleton<IDistributedLockingMechanism, SqliteEFCoreDistributedLockingMechanism<T>>();
services.AddSingleton<IDistributedLockingMechanism, SqlServerEFCoreDistributedLockingMechanism<T>>();

return services;
}

/// <summary>
/// Adds a EFCore DbContext with all the services needed to integrate with Umbraco scopes.
/// </summary>
Expand Down Expand Up @@ -149,26 +110,4 @@

builder.UseDatabaseProvider(connectionStrings.ProviderName, connectionStrings.ConnectionString);
}

[Obsolete]
private static void SetupDbContext(DefaultEFCoreOptionsAction? defaultEFCoreOptionsAction, IServiceProvider provider, DbContextOptionsBuilder builder)
{
ConnectionStrings connectionStrings = GetConnectionStringAndProviderName(provider);
defaultEFCoreOptionsAction?.Invoke(builder, connectionStrings.ConnectionString, connectionStrings.ProviderName);
}

[Obsolete]
private static ConnectionStrings GetConnectionStringAndProviderName(IServiceProvider serviceProvider)
{
ConnectionStrings connectionStrings = serviceProvider.GetRequiredService<IOptionsMonitor<ConnectionStrings>>().CurrentValue;

// Replace data directory
string? dataDirectory = AppDomain.CurrentDomain.GetData(Constants.System.DataDirectoryName)?.ToString();
if (string.IsNullOrEmpty(dataDirectory) is false)
{
connectionStrings.ConnectionString = connectionStrings.ConnectionString?.Replace(Constants.System.DataDirectoryPlaceholder, dataDirectory);
}

return connectionStrings;
}
}
35 changes: 0 additions & 35 deletions src/Umbraco.Core/Actions/ActionToPublish.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Umbraco.Core/Cache/DataTypeConfigurationCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public DataTypeConfigurationCache(IDataTypeService dataTypeService, IMemoryCache
var cacheKey = GetCacheKey(key);
if (_memoryCache.TryGetValue(cacheKey, out T? configuration) is false)
{
IDataType? dataType = _dataTypeService.GetDataType(key);
IDataType? dataType = _dataTypeService.GetAsync(key).GetAwaiter().GetResult();
configuration = dataType?.ConfigurationAs<T>();

// Only cache if data type was found (but still cache null configurations)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Umbraco.Cms.Core.Events;

Check warning on line 1 in src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/15.0)

❌ New issue: Overall Code Complexity

This module has a mean cyclomatic complexity of 4.40 across 15 functions. The mean complexity threshold is 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Persistence.Repositories;
Expand Down Expand Up @@ -367,16 +367,6 @@
// TODO (V14): Change into a record
public class JsonPayload
{
public JsonPayload()
{ }

[Obsolete("Use the default constructor and property initializers.")]
public JsonPayload(int id, Guid? key, TreeChangeTypes changeTypes)
{
Id = id;
Key = key;
ChangeTypes = changeTypes;
}

public int Id { get; init; }

Expand Down
73 changes: 0 additions & 73 deletions src/Umbraco.Core/Composing/TypeLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;

Check warning on line 1 in src/Umbraco.Core/Composing/TypeLoader.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/15.0)

❌ New issue: Code Duplication

The module contains 2 functions with similar structure: GetTypes,GetTypesWithAttribute. Avoid duplicated, aka copy-pasted, code inside the module. More duplication lowers the code health.
using System.Runtime.Serialization;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Cache;
Expand Down Expand Up @@ -26,40 +26,7 @@
private readonly Dictionary<CompositeTypeTypeKey, TypeList> _types = new();

private IEnumerable<Assembly>? _assemblies;

Check notice on line 29 in src/Umbraco.Core/Composing/TypeLoader.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/15.0)

✅ No longer an issue: Constructor Over-Injection

TypeLoader is no longer above the threshold for number of arguments

Check notice on line 29 in src/Umbraco.Core/Composing/TypeLoader.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/15.0)

✅ No longer an issue: Constructor Over-Injection

TypeLoader is no longer above the threshold for number of arguments
/// <summary>
/// Initializes a new instance of the <see cref="TypeLoader" /> class.
/// </summary>
[Obsolete("Please use an alternative constructor.")]
public TypeLoader(
ITypeFinder typeFinder,
IRuntimeHash runtimeHash,
IAppPolicyCache runtimeCache,
DirectoryInfo localTempPath,
ILogger<TypeLoader> logger,
IProfiler profiler,
IEnumerable<Assembly>? assembliesToScan = null)
: this(typeFinder, logger, assembliesToScan)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="TypeLoader" /> class.
/// </summary>
[Obsolete("Please use an alternative constructor.")]
public TypeLoader(
ITypeFinder typeFinder,
IRuntimeHash runtimeHash,
IAppPolicyCache runtimeCache,
DirectoryInfo localTempPath,
ILogger<TypeLoader> logger,
IProfiler profiler,
bool detectChanges,
IEnumerable<Assembly>? assembliesToScan = null)
: this(typeFinder, logger, assembliesToScan)
{
}

public TypeLoader(
ITypeFinder typeFinder,
ILogger<TypeLoader> logger,
Expand Down Expand Up @@ -100,18 +67,6 @@
[Obsolete("This will be removed in a future version.")]
public IEnumerable<TypeList> TypeLists => _types.Values;

/// <summary>
/// Sets a type list.
/// </summary>
/// <remarks>For unit tests.</remarks>
// internal for tests
[Obsolete("This will be removed in a future version.")]
public void AddTypeList(TypeList typeList)
{
Type tobject = typeof(object); // CompositeTypeTypeKey does not support null values
_types[new CompositeTypeTypeKey(typeList.BaseType ?? tobject, typeList.AttributeType ?? tobject)] = typeList;
}

#region Get Assembly Attributes

/// <summary>
Expand All @@ -136,34 +91,6 @@

#region Cache

// internal for tests
[Obsolete("This will be removed in a future version.")]
public Attempt<IEnumerable<string>> TryGetCached(Type baseType, Type attributeType) =>
Attempt<IEnumerable<string>>.Fail();

// internal for tests
[Obsolete("This will be removed in a future version.")]
public Dictionary<(string, string), IEnumerable<string>>? ReadCache() => null;

// internal for tests
[Obsolete("This will be removed in a future version.")]
public string? GetTypesListFilePath() => null;

// internal for tests
[Obsolete("This will be removed in a future version.")]
public void WriteCache()
{
}

/// <summary>
/// Clears cache.
/// </summary>
/// <remarks>Generally only used for resetting cache, for example during the install process.</remarks>
[Obsolete("This will be removed in a future version.")]
public void ClearTypesCache()
{
}

#endregion

#region Get Types
Expand Down
6 changes: 3 additions & 3 deletions src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static string GetBackOfficePath(this GlobalSettings globalSettings, IHost
return _backOfficePath;
}

_backOfficePath = hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath);
_backOfficePath = hostingEnvironment.ToAbsolute(Constants.System.DefaultUmbracoPath);
return _backOfficePath;
}

Expand Down Expand Up @@ -54,9 +54,9 @@ internal static string GetUmbracoMvcAreaNoCache(
this GlobalSettings globalSettings,
IHostingEnvironment hostingEnvironment)
{
var path = string.IsNullOrEmpty(globalSettings.UmbracoPath)
var path = string.IsNullOrEmpty(Constants.System.DefaultUmbracoPath)
? string.Empty
: hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath);
: hostingEnvironment.ToAbsolute(Constants.System.DefaultUmbracoPath);

if (path.IsNullOrWhiteSpace())
{
Expand Down
10 changes: 0 additions & 10 deletions src/Umbraco.Core/Configuration/Models/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ internal const string
[DefaultValue(StaticVersionCheckPeriod)]
public int VersionCheckPeriod { get; set; } = StaticVersionCheckPeriod;

/// <summary>
/// Gets or sets a value for the Umbraco back-office path.
/// </summary>
[Obsolete($"UmbracoPath is no longer configurable, use Constants.System.DefaultUmbracoPath instead. This property is scheduled for removal in a future version.")]
public string UmbracoPath
{
get => Constants.System.DefaultUmbracoPath;
set { }
}

/// <summary>
/// Gets or sets a value for the Umbraco icons path.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Umbraco.Core/Configuration/Models/NuCacheSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class NuCacheSettings
/// <summary>
/// Gets or sets a value defining the BTree block size.
/// </summary>
[Obsolete("This property is no longer used")]
[Obsolete("This property is no longer used. Scheduled for removal in v16")]
public int? BTreeBlockSize { get; set; }

/// <summary>
Expand Down
7 changes: 0 additions & 7 deletions src/Umbraco.Core/Configuration/Models/SecuritySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ public class SecuritySettings
[DefaultValue(StaticUserDefaultLockoutTimeInMinutes)]
public int UserDefaultLockoutTimeInMinutes { get; set; } = StaticUserDefaultLockoutTimeInMinutes;

/// <summary>
/// Gets or sets a value indicating whether to allow editing invariant properties from a non-default language variation.
/// </summary>
[Obsolete("Use ContentSettings.AllowEditFromInvariant instead")]
[DefaultValue(StaticAllowEditInvariantFromNonDefault)]
public bool AllowEditInvariantFromNonDefault { get; set; } = StaticAllowEditInvariantFromNonDefault;

/// <summary>
/// Gets or sets a value indicating whether to allow concurrent logins.
/// </summary>
Expand Down
4 changes: 0 additions & 4 deletions src/Umbraco.Core/Configuration/Models/WebRoutingSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ public class WebRoutingSettings
[DefaultValue(StaticValidateAlternativeTemplates)]
public bool ValidateAlternativeTemplates { get; set; } = StaticValidateAlternativeTemplates;

[Obsolete("Use DisableFindContentByIdentifierPath instead. This will be removed in Umbraco 15." )]
[DefaultValue(StaticDisableFindContentByIdPath)]
public bool DisableFindContentByIdPath { get; set; } = StaticDisableFindContentByIdPath;

[DefaultValue(StaticDisableFindContentByIdentifierPath)]
public bool DisableFindContentByIdentifierPath { get; set; } = StaticDisableFindContentByIdentifierPath;
/// <summary>
Expand Down
20 changes: 19 additions & 1 deletion src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
using Microsoft.Extensions.Hosting;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Exceptions;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Extensions;
using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment;

namespace Umbraco.Extensions;

public static class ModelsBuilderConfigExtensions
{
private static string? _modelsDirectoryAbsolute;

public static string ModelsDirectoryAbsolute(
this ModelsBuilderSettings modelsBuilderConfig,
IHostEnvironment hostEnvironment)
{
if (_modelsDirectoryAbsolute is null)
{
var modelsDirectory = modelsBuilderConfig.ModelsDirectory;
var root = hostEnvironment.MapPathContentRoot("~/");

_modelsDirectoryAbsolute = GetModelsDirectory(root, modelsDirectory, modelsBuilderConfig.AcceptUnsafeModelsDirectory);
}

return _modelsDirectoryAbsolute;
}

[Obsolete("Use the non obsoleted equivalent instead. Scheduled for removal in v16")]
public static string ModelsDirectoryAbsolute(
this ModelsBuilderSettings modelsBuilderConfig,
IHostingEnvironment hostingEnvironment)
Expand Down
Loading
Loading