diff --git a/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs b/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs index 9da8aaf5..4ab28c92 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs @@ -1,4 +1,6 @@ using OrchardCore.Environment.Shell; +using System.Collections.Generic; +using System.Linq; namespace Lombiq.Hosting.Tenants.Maintenance.Helpers; @@ -13,11 +15,22 @@ public static string ReplaceTenantName(string url, string tenantName) => public static string GetEvaluatedValueForTenant( string valueForDefaultTenant, string valueForAnyTenant, - ShellSettings shellSettings) + ShellSettings shellSettings, + IDictionary valueForTenantByName = null) { - var evaluatedValue = !string.IsNullOrEmpty(valueForAnyTenant) - ? ReplaceTenantName(valueForAnyTenant, shellSettings.Name) - : string.Empty; + var evaluatedValue = string.Empty; + + if (!string.IsNullOrEmpty(valueForAnyTenant)) + { + evaluatedValue = ReplaceTenantName(valueForAnyTenant, shellSettings.Name); + } + else if (valueForTenantByName?.Any() == true) + { + foreach (var pair in valueForTenantByName) + { + if (pair.Key == shellSettings.Name) evaluatedValue = pair.Value; + } + } return shellSettings.IsDefaultShell() ? valueForDefaultTenant : evaluatedValue; } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceOptions.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceOptions.cs index 21104e88..b9e0a393 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceOptions.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceOptions.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.UpdateSiteUrl; public class UpdateSiteUrlMaintenanceOptions @@ -5,4 +7,5 @@ public class UpdateSiteUrlMaintenanceOptions public bool IsEnabled { get; set; } public string DefaultTenantSiteUrl { get; set; } public string SiteUrl { get; set; } + public IDictionary SiteUrlFromTenantName { get; init; } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs index 68931684..f27eca5c 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs @@ -34,7 +34,8 @@ public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) siteSettings.BaseUrl = TenantUrlHelpers.GetEvaluatedValueForTenant( _options.Value.DefaultTenantSiteUrl, _options.Value.SiteUrl, - _shellSettings); + _shellSettings, + _options.Value.SiteUrlFromTenantName); await _siteService.UpdateSiteSettingsAsync(siteSettings); } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Readme.md b/Lombiq.Hosting.Tenants.Maintenance/Readme.md index 983dc56d..b05710b8 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Readme.md +++ b/Lombiq.Hosting.Tenants.Maintenance/Readme.md @@ -71,6 +71,25 @@ The following configuration options are available to set the site URL: **NOTE**: The `{TenantName}` placeholder will be replaced with the actual tenant name automatically. +Defining each tenant's URL separately is also an option, in this case, you have to use the `SiteUrlFromTenantName` property instead of `SiteUrl` and add your tenants' name and URL: + +```json +{ + "OrchardCore": { + "Lombiq_Hosting_Tenants_Maintenance": { + "UpdateSiteUrl": { + "IsEnabled": true, + "DefaultTenantSiteUrl": "https://domain.com", + "SiteUrlFromTenantName": { + "Tenant1": "https://domain.com/custom-url", + "Tenant2": "https://custom-domain.com" + } + } + } + } +} +``` + ### `Lombiq.Hosting.Tenants.Maintenance.UpdateShellRequestUrls` It's a maintenance task that updates the shell's request URLs in each tenant's shell settings based on the app configuration. It is available only for the default tenant.