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

OSOE-751: Upgrade to Orchard Core 1.8 #160

Merged
merged 46 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c57ba17
Upgrading to .NET 8 and OC 1.8.2
Psichorex Jan 18, 2024
d845d84
Addressing warnings.
Psichorex Jan 19, 2024
c7e6731
Addressing warnings.
Psichorex Jan 20, 2024
a41d98e
Addressing warnings.
Psichorex Jan 20, 2024
425acc0
Addressing warnings.
Psichorex Jan 20, 2024
857e19d
Addressing warnings.
Psichorex Jan 20, 2024
f170b6c
Adding DecoratedResourceManager
Psichorex Jan 27, 2024
d0f85aa
Renaming.
Psichorex Jan 27, 2024
98d268a
Resolving jQuery not being registered prior to its user script.
Psichorex Jan 27, 2024
646c223
Updating ResourceManagerDecorator.
Psichorex Jan 28, 2024
c2004e8
Adding summary.
Psichorex Jan 28, 2024
71068ed
Keeping H.
Psichorex Jan 29, 2024
943ac57
Keeping T.
Psichorex Jan 29, 2024
ac6bf26
Keeping T.
Psichorex Jan 29, 2024
a857043
Keeping H.
Psichorex Jan 29, 2024
43545cc
Keeping H.
Psichorex Jan 29, 2024
bb5e8d3
Removing field.
Psichorex Jan 29, 2024
d2dc72a
Removing field.
Psichorex Jan 29, 2024
4cecd5a
Removing field.
Psichorex Jan 29, 2024
480e3dc
Removing field.
Psichorex Jan 29, 2024
8c35cf6
Removing field.
Psichorex Jan 29, 2024
a25607f
Keeping T.
Psichorex Jan 29, 2024
f946d0c
Merge remote-tracking branch 'origin/dev' into issue/OSOE-751
Psichorex Jan 29, 2024
761ef56
Merge remote-tracking branch 'origin/dev' into issue/OSOE-751
Psichorex Jan 30, 2024
edc7f6b
Revert "Addressing warnings."This reverts commit c7e673188b8bf5a278f1…
Psichorex Jan 30, 2024
ca914d8
Fix.
Psichorex Jan 30, 2024
8e2511d
Fix.
Psichorex Jan 30, 2024
c7e6e84
Fixes.
Psichorex Jan 30, 2024
6d6b049
Making ResourceManagerDecorator easier to update
Piedone Feb 1, 2024
0635547
Optimization
Piedone Feb 1, 2024
4bf30c3
Update Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTex…
Psichorex Feb 1, 2024
235f271
Moving decorator to BaseTheme.
Psichorex Feb 1, 2024
efc2dad
Merge branch 'issue/OSOE-751' of https://github.com/Lombiq/Helpful-Ex…
Psichorex Feb 1, 2024
6bbbc89
Addressing ctor logic.
Psichorex Feb 1, 2024
895bade
Adding directive.
Psichorex Feb 1, 2024
e61f9a2
Minor fixing.
Psichorex Feb 1, 2024
437f57c
Adding form-label.
Psichorex Feb 1, 2024
5481622
Removing supresses.
Psichorex Feb 5, 2024
8048da7
Upgrading alpha of Tests.UI.
Psichorex Feb 16, 2024
0ee41ad
Upgrading alpha of HelpfulLibraries.
Psichorex Feb 16, 2024
fce006c
Upgrading publish-nuget branch reference.
Psichorex Feb 16, 2024
f6c6265
Using alpha.
Psichorex Feb 17, 2024
3deab83
Updating UITT with latest Atata.
Psichorex Feb 18, 2024
90387bc
Using new UITT alpha.
Psichorex Feb 20, 2024
cc2d664
Using new UITT alpha.
Psichorex Feb 21, 2024
e39c494
Reverting to dev reference.
Psichorex Feb 21, 2024
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
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*;node_modules\**</DefaultItemExcludes>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using AngleSharp.Io;
using AngleSharp.Io;
using Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -55,7 +55,7 @@ public async Task<IActionResult> Convert(IFormFile file)
json = await _converter.ConvertAsync(XDocument.Load(stream));
}

Response.Headers.Add("Content-Disposition", "attachment;filename=export.recipe.json");
Response.Headers.Append("Content-Disposition", "attachment;filename=export.recipe.json");
return Content(json, MimeTypeNames.ApplicationJson, Encoding.UTF8);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Services;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels;
using Lombiq.HelpfulLibraries.OrchardCore.Contents;
using Microsoft.Extensions.Localization;
using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.Display.Models;
Expand Down Expand Up @@ -41,18 +40,18 @@ public override IDisplayResult Display(
var name = fieldDisplayContext.PartFieldDefinition.Name;
if (field.ContentItem.Get<ContentSetPart>(name) is not { } part) return null;

return Initialize<ContentSetContentPickerFieldViewModel>(GetDisplayShapeType(fieldDisplayContext), model =>
return Initialize<ContentSetContentPickerFieldViewModel>(GetDisplayShapeType(fieldDisplayContext), async model =>
{
model.PartFieldDefinition = fieldDisplayContext.PartFieldDefinition;
return model.InitializeAsync(
await model.InitializeAsync(
_contentSetManager,
_contentSetEventHandlers,
T,
part,
new ContentTypePartDefinition(
name,
_contentDefinitionManager.GetPartDefinition(nameof(ContentSetPart)),
new JObject()),
await _contentDefinitionManager.GetPartDefinitionAsync(nameof(ContentSetPart)),
[]),
isNew: false);
})
.Location(CommonContentDisplayTypes.Detail, CommonLocationNames.Content)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Metadata;
Expand Down Expand Up @@ -37,15 +37,14 @@ public ContentSetIndexProvider(IServiceProvider provider) =>
_provider = provider;

public override void Describe(DescribeContext<ContentItem> context) =>
context.For<ContentSetIndex>().Map(contentItem =>
context.For<ContentSetIndex>().Map(async contentItem =>
{
if (!contentItem.Latest) return Enumerable.Empty<ContentSetIndex>();

using var scope = _provider.CreateScope();
var contentDefinitionManager = scope.ServiceProvider.GetRequiredService<IContentDefinitionManager>();

return contentDefinitionManager
.GetTypeDefinition(contentItem.ContentType)
return (await contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType))
.Parts
.Where(part => part.PartDefinition.Name == nameof(ContentSetPart))
.Select(part => new { Part = contentItem.Get<ContentSetPart>(part.Name), part.Name })
Expand Down
9 changes: 5 additions & 4 deletions Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Indexes;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Indexes;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models;
using Lombiq.HelpfulLibraries.OrchardCore.Data;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.Data.Migration;
using System.Threading.Tasks;
using YesSql.Sql;

namespace Lombiq.HelpfulExtensions.Extensions.ContentSets;
Expand All @@ -15,14 +16,14 @@ public class Migrations : DataMigration
public Migrations(IContentDefinitionManager contentDefinitionManager) =>
_contentDefinitionManager = contentDefinitionManager;

public int Create()
public async Task<int> CreateAsync()
{
_contentDefinitionManager.AlterPartDefinition(nameof(ContentSetPart), builder => builder
await _contentDefinitionManager.AlterPartDefinitionAsync(nameof(ContentSetPart), builder => builder
.Attachable()
.Reusable()
.WithDisplayName("Content Set"));

SchemaBuilder.CreateMapIndexTable<ContentSetIndex>(table => table
await SchemaBuilder.CreateMapIndexTableAsync<ContentSetIndex>(table => table
.Column<string>(nameof(ContentSetIndex.ContentItemId), column => column.WithCommonUniqueIdLength())
.Column<string>(nameof(ContentSetIndex.PartName))
.Column<bool>(nameof(ContentSetIndex.IsPublished))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using OrchardCore.ContentManagement;
using System.Diagnostics.CodeAnalysis;
using OrchardCore.ContentManagement;

namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Models;

[SuppressMessage(
"Minor Code Smell",
"S2094:Classes should not be empty",
Justification = "Only data we need is the field name.")]
public class ContentSetContentPickerField : ContentField
{
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Indexes;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models;
using OrchardCore.ContentManagement;
Expand Down Expand Up @@ -58,8 +58,7 @@ await _contentManager.CloneAsync(original) is not { } content)
part.Key = newKey;
});

var contentTypePartDefinition = _contentDefinitionManager
.GetTypeDefinition(content.ContentType)
var contentTypePartDefinition = (await _contentDefinitionManager.GetTypeDefinitionAsync(content.ContentType))
.Parts
.Single(definition => definition.Name == fromPartName);

Expand Down
15 changes: 8 additions & 7 deletions Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.Data.Migration;
using System.Threading.Tasks;
using static Lombiq.HelpfulExtensions.Extensions.ContentTypes.ContentTypes;

namespace Lombiq.HelpfulExtensions.Extensions.ContentTypes;
Expand All @@ -13,9 +14,9 @@ public class Migrations : DataMigration
public Migrations(IContentDefinitionManager contentDefinitionManager) =>
_contentDefinitionManager = contentDefinitionManager;

public int Create()
public async Task<int> CreateAsync()
{
_contentDefinitionManager.AlterTypeDefinition(Page, builder => builder
await _contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder
.Creatable()
.Securable()
.Draftable()
Expand All @@ -33,16 +34,16 @@ public int Create()
.WithPart("FlowPart", part => part.WithPosition("2"))
);

_contentDefinitionManager.AlterTypeDefinition(Empty, builder => builder
await _contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => builder
.WithDescription("A base content type for ad-hoc welding parts or fields on.")
);

return 3;
}

public int UpdateFrom1()
public async Task<int> UpdateFrom1Async()
{
_contentDefinitionManager.AlterTypeDefinition(Page, builder => builder
await _contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder
.WithPart("TitlePart", part => part.WithPosition("0"))
.WithPart("AutoroutePart", part => part.WithPosition("1"))
.WithPart("FlowPart", part => part.WithPosition("2"))
Expand All @@ -51,9 +52,9 @@ public int UpdateFrom1()
return 2;
}

public int UpdateFrom2()
public async Task<int> UpdateFrom2Async()
{
_contentDefinitionManager.AlterTypeDefinition(Empty, builder => builder
await _contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => builder
.WithDescription("A base content type for ad-hoc welding parts or fields on.")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ public class AdditionalStylingPartHandler : ContentHandlerBase
public AdditionalStylingPartHandler(IContentDefinitionManager contentDefinitionManager) =>
_contentDefinitionManager = contentDefinitionManager;

public override Task ActivatedAsync(ActivatedContentContext context)
public override async Task ActivatedAsync(ActivatedContentContext context)
{
if (!context.ContentItem.Has<AdditionalStylingPart>() &&
_contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType)
(await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType))
.GetSettings<ContentTypeSettings>().Stereotype == "Widget")
{
context.ContentItem.Weld<AdditionalStylingPart>();
}

return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Controllers;
using Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Controllers;
using Lombiq.HelpfulLibraries.OrchardCore.Navigation;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Localization;
using OrchardCore.Modules;
using OrchardCore.Navigation;
using System;
using System.Threading.Tasks;

namespace Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Navigation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class OrchardExportToRecipeConverter : IOrchardExportToRecipeConverter
private readonly IEnumerable<IOrchardContentConverter> _contentConverters;
private readonly IEnumerable<IOrchardUserConverter> _userConverters;

private readonly ICollection<string> _contentTypes;
private readonly List<string> _contentTypes;

public OrchardExportToRecipeConverter(
IContentDefinitionManager contentDefinitionManager,
Expand All @@ -37,7 +37,9 @@ public OrchardExportToRecipeConverter(
_userConverters = userConverters;

_contentTypes = contentDefinitionManager
.ListTypeDefinitions()
.ListTypeDefinitionsAsync()
.GetAwaiter()
.GetResult()
Piedone marked this conversation as resolved.
Show resolved Hide resolved
.Select(definition => definition.Name)
.ToList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using OrchardCore.Users.Models;
using OrchardCore.Users.Services;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using static Lombiq.HelpfulLibraries.OrchardCore.Users.PasswordHelper;
Expand Down Expand Up @@ -30,7 +29,7 @@ public async Task ImportAsync(XElement element)
return;

var roles = element.Element("UserRolesPart").Attribute("Roles")?.Value;
var rolesList = string.IsNullOrEmpty(roles) ? new List<string>() : roles.Split(',').ToList();
var rolesList = string.IsNullOrEmpty(roles) ? new List<string>() : [.. roles.Split(',')];

await _userService.CreateUserAsync(
new User
Expand Down
Piedone marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Options;
using OrchardCore.DisplayManagement.Manifest;
using OrchardCore.DisplayManagement.Theming;
using OrchardCore.Modules;
using OrchardCore.ResourceManagement;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;

namespace Lombiq.HelpfulLibraries.OrchardCore.ResourceManagement;

/// <summary>
/// This decorator is replacing the old ReplaceBootstrapMiddleware with the same purpose.
/// Removes the built-in Bootstrap resource if the currently selected theme uses Lombiq.BaseTheme as its base theme.
/// Themes derived from Lombiq.BaseTheme use Bootstrap from NPM as it's compiled into their site stylesheet. So this
/// duplicate resource is not needed and can cause problems if not removed. This situation can arise when a module
/// (such as Lombiq.DataTables) depends on Bootstrap and doesn't explicitly depend on Lombiq.BaseTheme so the built-in
/// resource would be injected if this middleware didn't remove it.
/// </summary>
public class ResourceManagerDecorator(
IResourceManager resourceManager,
IThemeManager themeManager,
IOptions<ResourceManagementOptions> resourceManagementOptions) : IResourceManager
Psichorex marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly ResourceManagementOptions _options = resourceManagementOptions.Value;

public ResourceManifest InlineManifest => resourceManager.InlineManifest;

public void AppendMeta(MetaEntry meta, string contentSeparator) => resourceManager.AppendMeta(meta, contentSeparator);

public ResourceDefinition FindResource(RequireSettings settings) => resourceManager.FindResource(settings);

public IEnumerable<IHtmlContent> GetRegisteredFootScripts() => resourceManager.GetRegisteredFootScripts();

public IEnumerable<IHtmlContent> GetRegisteredHeadScripts() => resourceManager.GetRegisteredHeadScripts();

public IEnumerable<LinkEntry> GetRegisteredLinks() => resourceManager.GetRegisteredLinks();

public IEnumerable<MetaEntry> GetRegisteredMetas() => resourceManager.GetRegisteredMetas();

public IEnumerable<IHtmlContent> GetRegisteredStyles() => resourceManager.GetRegisteredStyles();

public IEnumerable<ResourceRequiredContext> GetRequiredResources(string resourceType) =>
resourceManager.GetRequiredResources(resourceType);

public void NotRequired(string resourceType, string resourceName) =>
resourceManager.NotRequired(resourceType, resourceName);

public void RegisterFootScript(IHtmlContent script) => resourceManager.RegisterFootScript(script);

public void RegisterHeadScript(IHtmlContent script) => resourceManager.RegisterHeadScript(script);

public void RegisterLink(LinkEntry link) => resourceManager.RegisterLink(link);

public void RegisterMeta(MetaEntry meta) => resourceManager.RegisterMeta(meta);

public RequireSettings RegisterResource(string resourceType, string resourceName) =>
resourceManager.RegisterResource(resourceType, resourceName);

public void RegisterStyle(IHtmlContent style) => resourceManager.RegisterStyle(style);

public RequireSettings RegisterUrl(string resourceType, string resourcePath, string resourceDebugPath) =>
resourceManager.RegisterUrl(resourceType, resourcePath, resourceDebugPath);

public void RenderFootScript(TextWriter writer) => resourceManager.RenderFootScript(writer);

public void RenderHeadLink(TextWriter writer) => resourceManager.RenderHeadLink(writer);

public void RenderHeadScript(TextWriter writer) => resourceManager.RenderHeadScript(writer);

public void RenderLocalScript(RequireSettings settings, TextWriter writer) => resourceManager.RenderLocalScript(settings, writer);

public void RenderLocalStyle(RequireSettings settings, TextWriter writer) => resourceManager.RenderLocalStyle(settings, writer);

public void RenderMeta(TextWriter writer) => resourceManager.RenderMeta(writer);

// Apart from the marked sections, this does the same as the method in OC's ResourceManager. This needs to be kept
// up-to-date with Orchard upgrades.
[SuppressMessage(
"StyleCop.CSharp.ReadabilityRules",
"SA1123:Do not place regions within elements",
Justification = "Needed for easier Orchard upgrades.")]
public void RenderStylesheet(TextWriter writer)
{
#region CustomCode
var displayedTheme = themeManager.GetThemeAsync().GetAwaiter().GetResult();
var currentThemeUsesLombiqBaseTheme = displayedTheme?.Id == "Lombiq.BaseTheme" ||
displayedTheme?.Manifest.ModuleInfo is ThemeAttribute { BaseTheme: "Lombiq.BaseTheme" };
#endregion

var first = true;

var styleSheets = GetRequiredResources("stylesheet").ToList();

foreach (var context in styleSheets)
{
if (context.Settings.Location == ResourceLocation.Inline)
{
continue;
}

#region CustomCode
if (context.Resource.Name.EqualsOrdinalIgnoreCase("bootstrap") && currentThemeUsesLombiqBaseTheme)
{
continue;
}
#endregion

if (!first)
{
writer.Write(Environment.NewLine);
}

first = false;

context.WriteTo(writer, _options.ContentBasePath);
}

var registeredStyles = GetRegisteredStyles().ToArray();
for (var i = 0; i < registeredStyles.Length; i++)
{
var context = registeredStyles[i];
if (!first)
{
writer.Write(Environment.NewLine);
}

first = false;

context.WriteTo(writer, NullHtmlEncoder.Default);
}
}
}
Loading