Merge branch 'v9/dev' into v9/feature/add-notifcation-for-url-collision

This commit is contained in:
Nikolaj Geisle
2021-10-14 13:02:11 +02:00
44 changed files with 1283 additions and 638 deletions

View File

@@ -1,8 +1,9 @@
using System;
using System.Xml.Linq;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
using Umbraco.Cms.Infrastructure.Migrations;
@@ -20,7 +21,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging
MediaUrlGeneratorCollection mediaUrlGenerators,
IShortStringHelper shortStringHelper,
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
IMigrationContext context)
IMigrationContext context,
IOptions<PackageMigrationSettings> options)
: base(new ImportPackageBuilderExpression(
packagingService,
mediaService,
@@ -28,7 +30,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging
mediaUrlGenerators,
shortStringHelper,
contentTypeBaseServiceProvider,
context))
context,
options))
{
}

View File

@@ -5,7 +5,9 @@ using System.Linq;
using System.Xml.Linq;
using System.Xml.XPath;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Packaging;
@@ -25,7 +27,9 @@ namespace Umbraco.Cms.Infrastructure.Packaging
private readonly MediaUrlGeneratorCollection _mediaUrlGenerators;
private readonly IPackagingService _packagingService;
private readonly IShortStringHelper _shortStringHelper;
private bool _executed;
private readonly PackageMigrationSettings _packageMigrationSettings;
private bool _executed;
public ImportPackageBuilderExpression(
IPackagingService packagingService,
@@ -34,7 +38,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging
MediaUrlGeneratorCollection mediaUrlGenerators,
IShortStringHelper shortStringHelper,
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
IMigrationContext context) : base(context)
IMigrationContext context,
IOptions<PackageMigrationSettings> packageMigrationSettings) : base(context)
{
_packagingService = packagingService;
_mediaService = mediaService;
@@ -42,6 +47,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
_mediaUrlGenerators = mediaUrlGenerators;
_shortStringHelper = shortStringHelper;
_contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
_packageMigrationSettings = packageMigrationSettings.Value;
}
/// <summary>
@@ -59,6 +65,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
}
_executed = true;
Context.BuildingExpression = false;
if (EmbeddedResourceMigrationType == null && PackageDataManifest == null)
@@ -67,6 +74,12 @@ namespace Umbraco.Cms.Infrastructure.Packaging
$"Nothing to execute, neither {nameof(EmbeddedResourceMigrationType)} or {nameof(PackageDataManifest)} has been set.");
}
if (!_packageMigrationSettings.RunSchemaAndContentMigrations)
{
Logger.LogInformation("Skipping import of embedded schema file, due to configuration");
return;
}
InstallationSummary installationSummary;
if (EmbeddedResourceMigrationType != null)
{

View File

@@ -91,19 +91,25 @@ namespace Umbraco.Cms.Infrastructure.Packaging
var installationSummary = new InstallationSummary(compiledPackage.Name)
{
Warnings = compiledPackage.Warnings,
DataTypesInstalled = ImportDataTypes(compiledPackage.DataTypes.ToList(), userId),
DataTypesInstalled = ImportDataTypes(compiledPackage.DataTypes.ToList(), userId, out IEnumerable<EntityContainer> 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),
MediaTypesInstalled = ImportMediaTypes(compiledPackage.MediaTypes, userId),
DocumentTypesInstalled = ImportDocumentTypes(compiledPackage.DocumentTypes, userId, out IEnumerable<EntityContainer> documentTypeEntityContainersInstalled),
MediaTypesInstalled = ImportMediaTypes(compiledPackage.MediaTypes, userId, out IEnumerable<EntityContainer> mediaTypeEntityContainersInstalled),
StylesheetsInstalled = ImportStylesheets(compiledPackage.Stylesheets, userId),
ScriptsInstalled = ImportScripts(compiledPackage.Scripts, userId),
PartialViewsInstalled = ImportPartialViews(compiledPackage.PartialViews, userId)
};
var entityContainersInstalled = new List<EntityContainer>();
entityContainersInstalled.AddRange(dataTypeEntityContainersInstalled);
entityContainersInstalled.AddRange(documentTypeEntityContainersInstalled);
entityContainersInstalled.AddRange(mediaTypeEntityContainersInstalled);
installationSummary.EntityContainersInstalled = entityContainersInstalled;
// We need a reference to the imported doc types to continue
var importedDocTypes = installationSummary.DocumentTypesInstalled.ToDictionary(x => x.Alias, x => x);
var importedMediaTypes = installationSummary.MediaTypesInstalled.ToDictionary(x => x.Alias, x => x);
@@ -116,6 +122,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
return installationSummary;
}
}
/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
/// </summary>
@@ -123,7 +130,17 @@ namespace Umbraco.Cms.Infrastructure.Packaging
/// <param name="userId">Optional id of the User performing the operation. Default is zero (admin).</param>
/// <returns>An enumerable list of generated ContentTypes</returns>
public IReadOnlyList<IMediaType> ImportMediaTypes(IEnumerable<XElement> docTypeElements, int userId)
=> ImportDocumentTypes(docTypeElements.ToList(), true, userId, _mediaTypeService);
=> ImportMediaTypes(docTypeElements, userId, out _);
/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
/// </summary>
/// <param name="docTypeElements">Xml to import</param>
/// <param name="userId">Optional id of the User performing the operation. Default is zero (admin).</param>
/// <param name="entityContainersInstalled">Collection of entity containers installed by the package to be populated with those created in installing data types.</param>
/// <returns>An enumerable list of generated ContentTypes</returns>
public IReadOnlyList<IMediaType> ImportMediaTypes(IEnumerable<XElement> docTypeElements, int userId, out IEnumerable<EntityContainer> entityContainersInstalled)
=> ImportDocumentTypes(docTypeElements.ToList(), true, userId, _mediaTypeService, out entityContainersInstalled);
#endregion
@@ -408,7 +425,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
#region DocumentTypes
public IReadOnlyList<IContentType> ImportDocumentType(XElement docTypeElement, int userId)
=> ImportDocumentTypes(new[] { docTypeElement }, userId);
=> ImportDocumentTypes(new[] { docTypeElement }, userId, out _);
/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
@@ -417,7 +434,17 @@ namespace Umbraco.Cms.Infrastructure.Packaging
/// <param name="userId">Optional id of the User performing the operation. Default is zero (admin).</param>
/// <returns>An enumerable list of generated ContentTypes</returns>
public IReadOnlyList<IContentType> ImportDocumentTypes(IEnumerable<XElement> docTypeElements, int userId)
=> ImportDocumentTypes(docTypeElements.ToList(), true, userId, _contentTypeService);
=> ImportDocumentTypes(docTypeElements.ToList(), true, userId, _contentTypeService, out _);
/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
/// </summary>
/// <param name="docTypeElements">Xml to import</param>
/// <param name="userId">Optional id of the User performing the operation. Default is zero (admin).</param>
/// <param name="entityContainersInstalled">Collection of entity containers installed by the package to be populated with those created in installing data types.</param>
/// <returns>An enumerable list of generated ContentTypes</returns>
public IReadOnlyList<IContentType> ImportDocumentTypes(IEnumerable<XElement> docTypeElements, int userId, out IEnumerable<EntityContainer> entityContainersInstalled)
=> ImportDocumentTypes(docTypeElements.ToList(), true, userId, _contentTypeService, out entityContainersInstalled);
/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
@@ -428,6 +455,18 @@ namespace Umbraco.Cms.Infrastructure.Packaging
/// <returns>An enumerable list of generated ContentTypes</returns>
public IReadOnlyList<T> ImportDocumentTypes<T>(IReadOnlyCollection<XElement> unsortedDocumentTypes, bool importStructure, int userId, IContentTypeBaseService<T> service)
where T : class, IContentTypeComposition
=> ImportDocumentTypes(unsortedDocumentTypes, importStructure, userId, service);
/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
/// </summary>
/// <param name="unsortedDocumentTypes">Xml to import</param>
/// <param name="importStructure">Boolean indicating whether or not to import the </param>
/// <param name="userId">Optional id of the User performing the operation. Default is zero (admin).</param>
/// <param name="entityContainersInstalled">Collection of entity containers installed by the package to be populated with those created in installing data types.</param>
/// <returns>An enumerable list of generated ContentTypes</returns>
public IReadOnlyList<T> ImportDocumentTypes<T>(IReadOnlyCollection<XElement> unsortedDocumentTypes, bool importStructure, int userId, IContentTypeBaseService<T> service, out IEnumerable<EntityContainer> entityContainersInstalled)
where T : class, IContentTypeComposition
{
var importedContentTypes = new Dictionary<string, T>();
@@ -436,7 +475,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
var graph = new TopoGraph<string, TopoGraph.Node<string, XElement>>(x => x.Key, x => x.Dependencies);
var isSingleDocTypeImport = unsortedDocumentTypes.Count == 1;
var importedFolders = CreateContentTypeFolderStructure(unsortedDocumentTypes);
var importedFolders = CreateContentTypeFolderStructure(unsortedDocumentTypes, out entityContainersInstalled);
if (isSingleDocTypeImport == false)
{
@@ -532,9 +571,10 @@ namespace Umbraco.Cms.Infrastructure.Packaging
return list;
}
private Dictionary<string, int> CreateContentTypeFolderStructure(IEnumerable<XElement> unsortedDocumentTypes)
private Dictionary<string, int> CreateContentTypeFolderStructure(IEnumerable<XElement> unsortedDocumentTypes, out IEnumerable<EntityContainer> entityContainersInstalled)
{
var importedFolders = new Dictionary<string, int>();
var trackEntityContainersInstalled = new List<EntityContainer>();
foreach (var documentType in unsortedDocumentTypes)
{
var foldersAttribute = documentType.Attribute("Folders");
@@ -578,8 +618,10 @@ namespace Umbraco.Cms.Infrastructure.Packaging
_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);
}
importedFolders.Add(alias, current.Id);
@@ -589,11 +631,13 @@ namespace Umbraco.Cms.Infrastructure.Packaging
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;
}
}
}
entityContainersInstalled = trackEntityContainersInstalled;
return importedFolders;
}
@@ -1012,10 +1056,20 @@ namespace Umbraco.Cms.Infrastructure.Packaging
/// <param name="userId">Optional id of the user</param>
/// <returns>An enumerable list of generated DataTypeDefinitions</returns>
public IReadOnlyList<IDataType> ImportDataTypes(IReadOnlyCollection<XElement> dataTypeElements, int userId)
=> ImportDataTypes(dataTypeElements, userId, out _);
/// <summary>
/// Imports and saves package xml as <see cref="IDataType"/>
/// </summary>
/// <param name="dataTypeElements">Xml to import</param>
/// <param name="userId">Optional id of the user</param>
/// <param name="entityContainersInstalled">Collection of entity containers installed by the package to be populated with those created in installing data types.</param>
/// <returns>An enumerable list of generated DataTypeDefinitions</returns>
public IReadOnlyList<IDataType> ImportDataTypes(IReadOnlyCollection<XElement> dataTypeElements, int userId, out IEnumerable<EntityContainer> entityContainersInstalled)
{
var dataTypes = new List<IDataType>();
var importedFolders = CreateDataTypeFolderStructure(dataTypeElements);
var importedFolders = CreateDataTypeFolderStructure(dataTypeElements, out entityContainersInstalled);
foreach (var dataTypeElement in dataTypeElements)
{
@@ -1072,9 +1126,10 @@ namespace Umbraco.Cms.Infrastructure.Packaging
return dataTypes;
}
private Dictionary<string, int> CreateDataTypeFolderStructure(IEnumerable<XElement> datatypeElements)
private Dictionary<string, int> CreateDataTypeFolderStructure(IEnumerable<XElement> datatypeElements, out IEnumerable<EntityContainer> entityContainersInstalled)
{
var importedFolders = new Dictionary<string, int>();
var trackEntityContainersInstalled = new List<EntityContainer>();
foreach (var datatypeElement in datatypeElements)
{
var foldersAttribute = datatypeElement.Attribute("Folders");
@@ -1103,7 +1158,9 @@ namespace Umbraco.Cms.Infrastructure.Packaging
_logger.LogError(tryCreateFolder.Exception, "Could not create folder: {FolderName}", rootFolder);
throw tryCreateFolder.Exception;
}
current = _dataTypeService.GetContainer(tryCreateFolder.Result.Entity.Id);
trackEntityContainersInstalled.Add(current);
}
importedFolders.Add(name, current.Id);
@@ -1113,11 +1170,12 @@ namespace Umbraco.Cms.Infrastructure.Packaging
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;
}
}
}
entityContainersInstalled = trackEntityContainersInstalled;
return importedFolders;
}

View File

@@ -1,12 +1,17 @@
using System;
using System.ComponentModel;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
using Umbraco.Cms.Infrastructure.Migrations;
using Umbraco.Cms.Web.Common.DependencyInjection;
namespace Umbraco.Cms.Infrastructure.Packaging
{
public abstract class PackageMigrationBase : MigrationBase
{
private readonly IPackagingService _packagingService;
@@ -15,6 +20,7 @@ namespace Umbraco.Cms.Infrastructure.Packaging
private readonly MediaUrlGeneratorCollection _mediaUrlGenerators;
private readonly IShortStringHelper _shortStringHelper;
private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider;
private readonly IOptions<PackageMigrationSettings> _packageMigrationsSettings;
public PackageMigrationBase(
IPackagingService packagingService,
@@ -23,7 +29,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging
MediaUrlGeneratorCollection mediaUrlGenerators,
IShortStringHelper shortStringHelper,
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
IMigrationContext context)
IMigrationContext context,
IOptions<PackageMigrationSettings> packageMigrationsSettings)
: base(context)
{
_packagingService = packagingService;
@@ -32,6 +39,29 @@ namespace Umbraco.Cms.Infrastructure.Packaging
_mediaUrlGenerators = mediaUrlGenerators;
_shortStringHelper = shortStringHelper;
_contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
_packageMigrationsSettings = packageMigrationsSettings;
}
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Use ctor with all params")]
public PackageMigrationBase(
IPackagingService packagingService,
IMediaService mediaService,
MediaFileManager mediaFileManager,
MediaUrlGeneratorCollection mediaUrlGenerators,
IShortStringHelper shortStringHelper,
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
IMigrationContext context)
: this(
packagingService,
mediaService,
mediaFileManager,
mediaUrlGenerators,
shortStringHelper,
contentTypeBaseServiceProvider,
context,
StaticServiceProvider.Instance.GetRequiredService<IOptions<PackageMigrationSettings>>())
{
}
public IImportPackageBuilder ImportPackage => BeginBuild(
@@ -42,7 +72,8 @@ namespace Umbraco.Cms.Infrastructure.Packaging
_mediaUrlGenerators,
_shortStringHelper,
_contentTypeBaseServiceProvider,
Context));
Context,
_packageMigrationsSettings));
}
}

View File

@@ -1,7 +1,5 @@
using System;
using System.Reflection;
using NPoco;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
namespace Umbraco.Cms.Infrastructure.Persistence
{
@@ -18,6 +16,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence
/// <para>So far, this is very manual. We don't try to be clever and figure out whether the
/// columns exist already. We just ignore it.</para>
/// <para>Beware, the application MUST restart when this class behavior changes.</para>
/// <para>You can override the GetColmunnInfo method to control which columns this includes</para>
/// </remarks>
internal class UmbracoPocoDataBuilder : PocoDataBuilder
{
@@ -28,19 +27,5 @@ namespace Umbraco.Cms.Infrastructure.Persistence
{
_upgrading = upgrading;
}
protected override ColumnInfo GetColumnInfo(MemberInfo mi, Type type)
{
var columnInfo = base.GetColumnInfo(mi, type);
// TODO: Is this upgrade flag still relevant? It's a lot of hacking to just set this value
// including the interface method ConfigureForUpgrade for this one circumstance.
if (_upgrading)
{
if (type == typeof(UserDto) && mi.Name == "TourData") columnInfo.IgnoreColumn = true;
}
return columnInfo;
}
}
}

View File

@@ -1,9 +1,9 @@
using System;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Exceptions;
@@ -13,7 +13,9 @@ using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Runtime;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Web.Common.DependencyInjection;
using Umbraco.Extensions;
using ComponentCollection = Umbraco.Cms.Core.Composing.ComponentCollection;
namespace Umbraco.Cms.Infrastructure.Runtime
{
@@ -27,6 +29,9 @@ namespace Umbraco.Cms.Infrastructure.Runtime
private readonly IMainDom _mainDom;
private readonly IUmbracoDatabaseFactory _databaseFactory;
private readonly IEventAggregator _eventAggregator;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IUmbracoVersion _umbracoVersion;
private readonly IServiceProvider _serviceProvider;
private CancellationToken _cancellationToken;
/// <summary>
@@ -40,7 +45,10 @@ namespace Umbraco.Cms.Infrastructure.Runtime
IProfilingLogger profilingLogger,
IMainDom mainDom,
IUmbracoDatabaseFactory databaseFactory,
IEventAggregator eventAggregator)
IEventAggregator eventAggregator,
IHostingEnvironment hostingEnvironment,
IUmbracoVersion umbracoVersion,
IServiceProvider serviceProvider)
{
State = state;
_loggerFactory = loggerFactory;
@@ -50,9 +58,42 @@ namespace Umbraco.Cms.Infrastructure.Runtime
_mainDom = mainDom;
_databaseFactory = databaseFactory;
_eventAggregator = eventAggregator;
_hostingEnvironment = hostingEnvironment;
_umbracoVersion = umbracoVersion;
_serviceProvider = serviceProvider;
_logger = _loggerFactory.CreateLogger<CoreRuntime>();
}
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete]
public CoreRuntime(
ILoggerFactory loggerFactory,
IRuntimeState state,
ComponentCollection components,
IApplicationShutdownRegistry applicationShutdownRegistry,
IProfilingLogger profilingLogger,
IMainDom mainDom,
IUmbracoDatabaseFactory databaseFactory,
IEventAggregator eventAggregator,
IHostingEnvironment hostingEnvironment,
IUmbracoVersion umbracoVersion
):this(
loggerFactory,
state,
components,
applicationShutdownRegistry,
profilingLogger,
mainDom,
databaseFactory,
eventAggregator,
hostingEnvironment,
umbracoVersion,
null
)
{
}
/// <summary>
/// Gets the state of the Umbraco runtime.
/// </summary>
@@ -70,6 +111,7 @@ namespace Umbraco.Cms.Infrastructure.Runtime
{
_cancellationToken = cancellationToken;
StaticApplicationLogging.Initialize(_loggerFactory);
StaticServiceProvider.Instance = _serviceProvider;
AppDomain.CurrentDomain.UnhandledException += (_, args) =>
{

View File

@@ -24,7 +24,7 @@ namespace Umbraco.Cms.Core.Security
/// <summary>
/// The user store for back office users
/// </summary>
public class BackOfficeUserStore : UmbracoUserStore<BackOfficeIdentityUser, IdentityRole<string>>
public class BackOfficeUserStore : UmbracoUserStore<BackOfficeIdentityUser, IdentityRole<string>>, IUserSessionStore<BackOfficeIdentityUser>
{
private readonly IScopeProvider _scopeProvider;
private readonly IUserService _userService;