diff --git a/src/Commands/Admin/SetHomeSite.cs b/src/Commands/Admin/SetHomeSite.cs index 549fbb8eb..1cf65a227 100644 --- a/src/Commands/Admin/SetHomeSite.cs +++ b/src/Commands/Admin/SetHomeSite.cs @@ -27,6 +27,28 @@ public class SetHomeSite : PnPSharePointOnlineAdminCmdlet protected override void ExecuteCmdlet() { Tenant.EnsureProperties(t => t.IsMultipleVivaConnectionsFlightEnabled, t => t.IsVivaHomeFlightEnabled); + HomeSiteConfigurationParam configurationParam; + + bool hasVivaConnectionsDefaultStart = ParameterSpecified(nameof(VivaConnectionsDefaultStart)); + bool hasDraftMode = ParameterSpecified(nameof(DraftMode)); + + // Replace the current configurationParam assignment block with the following: + + configurationParam = null; + if (hasVivaConnectionsDefaultStart || hasDraftMode) + { + configurationParam = new(); + if (hasVivaConnectionsDefaultStart) + { + configurationParam.vivaConnectionsDefaultStart = VivaConnectionsDefaultStart; + configurationParam.IsVivaConnectionsDefaultStartPresent = true; + } + if (hasDraftMode) + { + configurationParam.isInDraftMode = DraftMode; + configurationParam.IsInDraftModePresent = true; + } + } if (Tenant.IsMultipleVivaConnectionsFlightEnabled) { @@ -34,12 +56,10 @@ protected override void ExecuteCmdlet() { IEnumerable enumerable = Tenant.GetTargetedSitesDetails()?.Where((TargetedSiteDetails hs) => !hs.IsVivaBackendSite); AdminContext.ExecuteQueryRetry(); - bool flag = false; if (enumerable == null || enumerable.Count() == 0) { Tenant.AddHomeSite(HomeSiteUrl, 1, null); AdminContext.ExecuteQueryRetry(); - flag = true; } else if (enumerable.Count() == 1 && !IsSameSiteUrl(enumerable.First().Url, HomeSiteUrl)) { @@ -47,16 +67,10 @@ protected override void ExecuteCmdlet() AdminContext.ExecuteQueryRetry(); Tenant.AddHomeSite(HomeSiteUrl, 1, null); AdminContext.ExecuteQueryRetry(); - flag = true; } - HomeSiteConfigurationParam configurationParam = new() - { - vivaConnectionsDefaultStart = VivaConnectionsDefaultStart, - IsVivaConnectionsDefaultStartPresent = VivaConnectionsDefaultStart, - isInDraftMode = DraftMode, - IsInDraftModePresent = DraftMode || flag - }; + ClientResult clientResult = Tenant.UpdateTargetedSite(HomeSiteUrl, configurationParam); + AdminContext.ExecuteQueryRetry(); WriteObject(clientResult.Value); } @@ -64,18 +78,7 @@ protected override void ExecuteCmdlet() else if (Force || ShouldContinue("Before you set a Home site, make sure you review the documentation at https://aka.ms/homesites.", Properties.Resources.Confirm)) { Tenant.ValidateVivaHomeParameterExists(VivaConnectionsDefaultStart); - HomeSiteConfigurationParam configuration = null; - if (VivaConnectionsDefaultStart || DraftMode) - { - configuration = new HomeSiteConfigurationParam - { - vivaConnectionsDefaultStart = VivaConnectionsDefaultStart, - IsVivaConnectionsDefaultStartPresent = VivaConnectionsDefaultStart, - isInDraftMode = DraftMode, - IsInDraftModePresent = DraftMode - }; - } - ClientResult clientResult = Tenant.SetSPHSiteWithConfiguration(HomeSiteUrl, configuration); + ClientResult clientResult = Tenant.SetSPHSiteWithConfiguration(HomeSiteUrl, configurationParam); AdminContext.ExecuteQueryRetry(); WriteObject(clientResult.Value); }