diff --git a/Apps/W1/HybridBaseDeployment/app/src/codeunits/CloudMigReplicateDataMgt.Codeunit.al b/Apps/W1/HybridBaseDeployment/app/src/codeunits/CloudMigReplicateDataMgt.Codeunit.al index eb5fb8687f..508e6ed50b 100644 --- a/Apps/W1/HybridBaseDeployment/app/src/codeunits/CloudMigReplicateDataMgt.Codeunit.al +++ b/Apps/W1/HybridBaseDeployment/app/src/codeunits/CloudMigReplicateDataMgt.Codeunit.al @@ -71,10 +71,39 @@ codeunit 40021 "Cloud Mig. Replicate Data Mgt." exit(CanBeIncluded); end; + procedure IncludeTableToReplication(TableID: Integer; CompanyName: Text[30]) + begin + IncludeExcludeTableFromReplication(TableID, CompanyName, true); + end; + + procedure ExcludeTableFromReplication(TableID: Integer; CompanyName: Text[30]) + begin + IncludeExcludeTableFromReplication(TableID, CompanyName, false); + end; + + local procedure IncludeExcludeTableFromReplication(TableID: Integer; CompanyName: Text[30]; NewReplicateData: Boolean) + var + IntelligentCloudStatus: Record "Intelligent Cloud Status"; + TablesModified: Text; + SeparatorChar: Char; + begin + IntelligentCloudStatus.SetRange("Table Id", TableID); + IntelligentCloudStatus.SetRange("Company Name", CompanyName); + if not IntelligentCloudStatus.FindSet() then + exit; + + CheckCanChangeTheTable(IntelligentCloudStatus); + SeparatorChar := ','; + IntelligentCloudStatus.FindSet(); + repeat + UpdateReplicateDataForTable(IntelligentCloudStatus, TablesModified, SeparatorChar, NewReplicateData); + until IntelligentCloudStatus.Next() = 0; + + LogMessageForChangedReplicateData(Format(TableID), NewReplicateData); + end; + internal procedure IncludeExcludeTablesFromCloudMigration(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; NewReplicateData: Boolean) var - HybridCloudManagement: Codeunit "Hybrid Cloud Management"; - TelemetryDictionary: Dictionary of [Text, Text]; TablesModified: Text; SeparatorChar: Char; begin @@ -83,49 +112,105 @@ codeunit 40021 "Cloud Mig. Replicate Data Mgt." SeparatorChar := ','; repeat - if IntelligentCloudStatus."Replicate Data" <> NewReplicateData then begin - InsertInitialLog(IntelligentCloudStatus); - IntelligentCloudStatus."Replicate Data" := NewReplicateData; - IntelligentCloudStatus.Modify(); - InsertModifyLog(IntelligentCloudStatus); - TablesModified += IntelligentCloudStatus."Table Name" + SeparatorChar; - end; + UpdateReplicateDataForTable(IntelligentCloudStatus, TablesModified, SeparatorChar, NewReplicateData); until IntelligentCloudStatus.Next() = 0; TablesModified := TablesModified.TrimEnd(SeparatorChar); + LogMessageForChangedReplicateData(TablesModified, NewReplicateData); + end; + + local procedure UpdateReplicateDataForTable(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; var TablesModified: Text; SeparatorChar: Char; NewReplicateData: Boolean) + begin + if IntelligentCloudStatus."Replicate Data" <> NewReplicateData then begin + InsertInitialLog(IntelligentCloudStatus); + IntelligentCloudStatus."Replicate Data" := NewReplicateData; + IntelligentCloudStatus.Modify(); + InsertModifyLog(IntelligentCloudStatus); + TablesModified += IntelligentCloudStatus."Table Name" + SeparatorChar; + end; + end; + + local procedure LogMessageForChangedReplicateData(TablesModified: Text; NewReplicateData: Boolean) + var + HybridCloudManagement: Codeunit "Hybrid Cloud Management"; + TelemetryDictionary: Dictionary of [Text, Text]; + begin TelemetryDictionary.Add('Category', HybridCloudManagement.GetTelemetryCategory()); TelemetryDictionary.Add('TablesModified', TablesModified); TelemetryDictionary.Add('ReplicateData', Format(NewReplicateData, 0, 9)); Session.LogMessage('0000MRJ', ChangedReplicationPropertyLbl, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, TelemetryDictionary); end; - internal procedure ChangePreserveCloudData(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; NewPreserveCloudData: Boolean) + procedure SetPreserveDataForTable(TableID: Integer; CompanyName: Text[30]) + begin + SetResetPreserveDataForTable(TableID, CompanyName, true); + end; + + procedure ResetPreserveDataForTable(TableID: Integer; CompanyName: Text[30]) + begin + SetResetPreserveDataForTable(TableID, CompanyName, false); + end; + + local procedure SetResetPreserveDataForTable(TableID: Integer; CompanyName: Text[30]; NewPreserveCloudData: Boolean) var - HybridCloudManagement: Codeunit "Hybrid Cloud Management"; - TelemetryDictionary: Dictionary of [Text, Text]; + IntelligentCloudStatus: Record "Intelligent Cloud Status"; TablesModified: Text; SeparatorChar: Char; begin + IntelligentCloudStatus.SetRange("Table Id", TableID); + IntelligentCloudStatus.SetRange("Company Name", CompanyName); if not IntelligentCloudStatus.FindSet() then exit; + CheckCanChangeTheTable(IntelligentCloudStatus); SeparatorChar := ','; + IntelligentCloudStatus.FindSet(); repeat - if IntelligentCloudStatus."Preserve Cloud Data" <> NewPreserveCloudData then begin - if (not NewPreserveCloudData) and (IntelligentCloudStatus."Table Id" = Database::"Tenant Media") then - Error(NotPossibleToReplaceTenantMediaTableErr); + UpdatePreserveDataForTable(IntelligentCloudStatus, TablesModified, SeparatorChar, NewPreserveCloudData); + until IntelligentCloudStatus.Next() = 0; - if (NewPreserveCloudData) and (IntelligentCloudStatus."Company Name" = '') then - Error(NotPossibleToDeltaSyncDataPerCompanyErr); + LogMessageForChangedPreserveData(Format(TableID), NewPreserveCloudData); + end; - InsertInitialLog(IntelligentCloudStatus); - IntelligentCloudStatus."Preserve Cloud Data" := NewPreserveCloudData; - IntelligentCloudStatus.Modify(); - InsertModifyLog(IntelligentCloudStatus); - end; + internal procedure ChangePreserveCloudData(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; NewPreserveCloudData: Boolean) + var + TablesModified: Text; + SeparatorChar: Char; + begin + if not IntelligentCloudStatus.FindSet() then + exit; + + SeparatorChar := ','; + repeat + UpdatePreserveDataForTable(IntelligentCloudStatus, TablesModified, SeparatorChar, NewPreserveCloudData); until IntelligentCloudStatus.Next() = 0; TablesModified := TablesModified.TrimEnd(SeparatorChar); + LogMessageForChangedPreserveData(TablesModified, NewPreserveCloudData); + end; + + local procedure UpdatePreserveDataForTable(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; var TablesModified: Text; SeparatorChar: Char; NewPreserveCloudData: Boolean) + begin + if IntelligentCloudStatus."Preserve Cloud Data" <> NewPreserveCloudData then begin + if (not NewPreserveCloudData) and (IntelligentCloudStatus."Table Id" = Database::"Tenant Media") then + Error(NotPossibleToReplaceTenantMediaTableErr); + + if (NewPreserveCloudData) and (IntelligentCloudStatus."Company Name" = '') then + Error(NotPossibleToDeltaSyncDataPerCompanyErr); + + InsertInitialLog(IntelligentCloudStatus); + IntelligentCloudStatus."Preserve Cloud Data" := NewPreserveCloudData; + IntelligentCloudStatus.Modify(); + InsertModifyLog(IntelligentCloudStatus); + TablesModified += IntelligentCloudStatus."Table Name" + SeparatorChar; + end; + end; + + local procedure LogMessageForChangedPreserveData(TablesModified: Text; NewPreserveCloudData: Boolean) + var + HybridCloudManagement: Codeunit "Hybrid Cloud Management"; + TelemetryDictionary: Dictionary of [Text, Text]; + begin TelemetryDictionary.Add('Category', HybridCloudManagement.GetTelemetryCategory()); TelemetryDictionary.Add('TablesModified', TablesModified); TelemetryDictionary.Add('PreserveCloudData', Format(NewPreserveCloudData, 0, 9));