Skip to content

Commit 0bb636e

Browse files
authored
Exclude or Include Tables from Cloud Migration (#27773)
#### Summary Enables a developer: - To prepare packages of tables for cloud sync - Disable some tables for cloud sync- those that are set as default during initial setup - in order to save database space. - Select custom tables programmatically #### Work Item(s) Fixes #27655 @nikolakukrika There are some tests in the Codeunit 139656 "Hybrid Cloud Management Tests". I am not sure if new tests are needed for this change. Fixes [AB#558218](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/558218)
1 parent 42a98a0 commit 0bb636e

File tree

1 file changed

+107
-22
lines changed

1 file changed

+107
-22
lines changed

Apps/W1/HybridBaseDeployment/app/src/codeunits/CloudMigReplicateDataMgt.Codeunit.al

+107-22
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,39 @@ codeunit 40021 "Cloud Mig. Replicate Data Mgt."
7171
exit(CanBeIncluded);
7272
end;
7373

74+
procedure IncludeTableToReplication(TableID: Integer; CompanyName: Text[30])
75+
begin
76+
IncludeExcludeTableFromReplication(TableID, CompanyName, true);
77+
end;
78+
79+
procedure ExcludeTableFromReplication(TableID: Integer; CompanyName: Text[30])
80+
begin
81+
IncludeExcludeTableFromReplication(TableID, CompanyName, false);
82+
end;
83+
84+
local procedure IncludeExcludeTableFromReplication(TableID: Integer; CompanyName: Text[30]; NewReplicateData: Boolean)
85+
var
86+
IntelligentCloudStatus: Record "Intelligent Cloud Status";
87+
TablesModified: Text;
88+
SeparatorChar: Char;
89+
begin
90+
IntelligentCloudStatus.SetRange("Table Id", TableID);
91+
IntelligentCloudStatus.SetRange("Company Name", CompanyName);
92+
if not IntelligentCloudStatus.FindSet() then
93+
exit;
94+
95+
CheckCanChangeTheTable(IntelligentCloudStatus);
96+
SeparatorChar := ',';
97+
IntelligentCloudStatus.FindSet();
98+
repeat
99+
UpdateReplicateDataForTable(IntelligentCloudStatus, TablesModified, SeparatorChar, NewReplicateData);
100+
until IntelligentCloudStatus.Next() = 0;
101+
102+
LogMessageForChangedReplicateData(Format(TableID), NewReplicateData);
103+
end;
104+
74105
internal procedure IncludeExcludeTablesFromCloudMigration(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; NewReplicateData: Boolean)
75106
var
76-
HybridCloudManagement: Codeunit "Hybrid Cloud Management";
77-
TelemetryDictionary: Dictionary of [Text, Text];
78107
TablesModified: Text;
79108
SeparatorChar: Char;
80109
begin
@@ -83,49 +112,105 @@ codeunit 40021 "Cloud Mig. Replicate Data Mgt."
83112

84113
SeparatorChar := ',';
85114
repeat
86-
if IntelligentCloudStatus."Replicate Data" <> NewReplicateData then begin
87-
InsertInitialLog(IntelligentCloudStatus);
88-
IntelligentCloudStatus."Replicate Data" := NewReplicateData;
89-
IntelligentCloudStatus.Modify();
90-
InsertModifyLog(IntelligentCloudStatus);
91-
TablesModified += IntelligentCloudStatus."Table Name" + SeparatorChar;
92-
end;
115+
UpdateReplicateDataForTable(IntelligentCloudStatus, TablesModified, SeparatorChar, NewReplicateData);
93116
until IntelligentCloudStatus.Next() = 0;
94117

95118
TablesModified := TablesModified.TrimEnd(SeparatorChar);
119+
LogMessageForChangedReplicateData(TablesModified, NewReplicateData);
120+
end;
121+
122+
local procedure UpdateReplicateDataForTable(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; var TablesModified: Text; SeparatorChar: Char; NewReplicateData: Boolean)
123+
begin
124+
if IntelligentCloudStatus."Replicate Data" <> NewReplicateData then begin
125+
InsertInitialLog(IntelligentCloudStatus);
126+
IntelligentCloudStatus."Replicate Data" := NewReplicateData;
127+
IntelligentCloudStatus.Modify();
128+
InsertModifyLog(IntelligentCloudStatus);
129+
TablesModified += IntelligentCloudStatus."Table Name" + SeparatorChar;
130+
end;
131+
end;
132+
133+
local procedure LogMessageForChangedReplicateData(TablesModified: Text; NewReplicateData: Boolean)
134+
var
135+
HybridCloudManagement: Codeunit "Hybrid Cloud Management";
136+
TelemetryDictionary: Dictionary of [Text, Text];
137+
begin
96138
TelemetryDictionary.Add('Category', HybridCloudManagement.GetTelemetryCategory());
97139
TelemetryDictionary.Add('TablesModified', TablesModified);
98140
TelemetryDictionary.Add('ReplicateData', Format(NewReplicateData, 0, 9));
99141
Session.LogMessage('0000MRJ', ChangedReplicationPropertyLbl, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, TelemetryDictionary);
100142
end;
101143

102-
internal procedure ChangePreserveCloudData(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; NewPreserveCloudData: Boolean)
144+
procedure SetPreserveDataForTable(TableID: Integer; CompanyName: Text[30])
145+
begin
146+
SetResetPreserveDataForTable(TableID, CompanyName, true);
147+
end;
148+
149+
procedure ResetPreserveDataForTable(TableID: Integer; CompanyName: Text[30])
150+
begin
151+
SetResetPreserveDataForTable(TableID, CompanyName, false);
152+
end;
153+
154+
local procedure SetResetPreserveDataForTable(TableID: Integer; CompanyName: Text[30]; NewPreserveCloudData: Boolean)
103155
var
104-
HybridCloudManagement: Codeunit "Hybrid Cloud Management";
105-
TelemetryDictionary: Dictionary of [Text, Text];
156+
IntelligentCloudStatus: Record "Intelligent Cloud Status";
106157
TablesModified: Text;
107158
SeparatorChar: Char;
108159
begin
160+
IntelligentCloudStatus.SetRange("Table Id", TableID);
161+
IntelligentCloudStatus.SetRange("Company Name", CompanyName);
109162
if not IntelligentCloudStatus.FindSet() then
110163
exit;
111164

165+
CheckCanChangeTheTable(IntelligentCloudStatus);
112166
SeparatorChar := ',';
167+
IntelligentCloudStatus.FindSet();
113168
repeat
114-
if IntelligentCloudStatus."Preserve Cloud Data" <> NewPreserveCloudData then begin
115-
if (not NewPreserveCloudData) and (IntelligentCloudStatus."Table Id" = Database::"Tenant Media") then
116-
Error(NotPossibleToReplaceTenantMediaTableErr);
169+
UpdatePreserveDataForTable(IntelligentCloudStatus, TablesModified, SeparatorChar, NewPreserveCloudData);
170+
until IntelligentCloudStatus.Next() = 0;
117171

118-
if (NewPreserveCloudData) and (IntelligentCloudStatus."Company Name" = '') then
119-
Error(NotPossibleToDeltaSyncDataPerCompanyErr);
172+
LogMessageForChangedPreserveData(Format(TableID), NewPreserveCloudData);
173+
end;
120174

121-
InsertInitialLog(IntelligentCloudStatus);
122-
IntelligentCloudStatus."Preserve Cloud Data" := NewPreserveCloudData;
123-
IntelligentCloudStatus.Modify();
124-
InsertModifyLog(IntelligentCloudStatus);
125-
end;
175+
internal procedure ChangePreserveCloudData(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; NewPreserveCloudData: Boolean)
176+
var
177+
TablesModified: Text;
178+
SeparatorChar: Char;
179+
begin
180+
if not IntelligentCloudStatus.FindSet() then
181+
exit;
182+
183+
SeparatorChar := ',';
184+
repeat
185+
UpdatePreserveDataForTable(IntelligentCloudStatus, TablesModified, SeparatorChar, NewPreserveCloudData);
126186
until IntelligentCloudStatus.Next() = 0;
127187

128188
TablesModified := TablesModified.TrimEnd(SeparatorChar);
189+
LogMessageForChangedPreserveData(TablesModified, NewPreserveCloudData);
190+
end;
191+
192+
local procedure UpdatePreserveDataForTable(var IntelligentCloudStatus: Record "Intelligent Cloud Status"; var TablesModified: Text; SeparatorChar: Char; NewPreserveCloudData: Boolean)
193+
begin
194+
if IntelligentCloudStatus."Preserve Cloud Data" <> NewPreserveCloudData then begin
195+
if (not NewPreserveCloudData) and (IntelligentCloudStatus."Table Id" = Database::"Tenant Media") then
196+
Error(NotPossibleToReplaceTenantMediaTableErr);
197+
198+
if (NewPreserveCloudData) and (IntelligentCloudStatus."Company Name" = '') then
199+
Error(NotPossibleToDeltaSyncDataPerCompanyErr);
200+
201+
InsertInitialLog(IntelligentCloudStatus);
202+
IntelligentCloudStatus."Preserve Cloud Data" := NewPreserveCloudData;
203+
IntelligentCloudStatus.Modify();
204+
InsertModifyLog(IntelligentCloudStatus);
205+
TablesModified += IntelligentCloudStatus."Table Name" + SeparatorChar;
206+
end;
207+
end;
208+
209+
local procedure LogMessageForChangedPreserveData(TablesModified: Text; NewPreserveCloudData: Boolean)
210+
var
211+
HybridCloudManagement: Codeunit "Hybrid Cloud Management";
212+
TelemetryDictionary: Dictionary of [Text, Text];
213+
begin
129214
TelemetryDictionary.Add('Category', HybridCloudManagement.GetTelemetryCategory());
130215
TelemetryDictionary.Add('TablesModified', TablesModified);
131216
TelemetryDictionary.Add('PreserveCloudData', Format(NewPreserveCloudData, 0, 9));

0 commit comments

Comments
 (0)