Codeunit 8912 Environment Cleanup Subs

Base Application, System.Environment

src/Layers/W1/BaseApp/EnvironmentCleanupSubs.Codeunit.al113 lines, Copyright (c) Microsoft Corporation. MIT

// ------------------------------------------------------------------------------------------------// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the MIT License. See License.txt in the project root for license information.// ------------------------------------------------------------------------------------------------namespace System.Environment;#if not CLEAN28using Microsoft.CRM.Outlook;#endifusing Microsoft.EServices.EDocument;using Microsoft.Finance.Currency;using Microsoft.Finance.VAT.Registration;using Microsoft.Integration.Dataverse;using Microsoft.Utilities;using System.Automation;using System.DataAdministration;using System.Environment.Configuration;using System.Integration.PowerBI;using System.Threading;codeunit 8912 "Environment Cleanup Subs"{    Access = Internal;    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Environment Cleanup", 'OnClearCompanyConfig', '', false, false)]    local procedure ClearCompanyConfigGeneral(CompanyName: Text; SourceEnv: Enum "Environment Type"; DestinationEnv: Enum "Environment Type")    var        OCRServiceSetup: Record "OCR Service Setup";        DocExchServiceSetup: Record "Doc. Exch. Service Setup";        CurrExchRateUpdateSetup: Record "Curr. Exch. Rate Update Setup";        VATRegNoSrvConfig: Record "VAT Reg. No. Srv Config";        ServiceConnection: Record "Service Connection";#if not CLEAN28        ExchangeSync: Record "Exchange Sync";#endif        JobQueueManagement: Codeunit "Job Queue Management";        CDSIntegrationImpl: Codeunit "CDS Integration Impl.";        nullGUID: Guid;    begin        // For behavior in all cases of copying a new env.        if CompanyName() <> CompanyName then begin            OCRServiceSetup.ChangeCompany(CompanyName);            DocExchServiceSetup.ChangeCompany(CompanyName);            CurrExchRateUpdateSetup.ChangeCompany(CompanyName);            VATRegNoSrvConfig.ChangeCompany(CompanyName);            ServiceConnection.ChangeCompany(CompanyName);#if not CLEAN28            ExchangeSync.ChangeCompany(CompanyName);#endif        end;        OCRServiceSetup.ModifyAll("Password Key", nullGUID);        OCRServiceSetup.ModifyAll(Enabled, false);        DocExchServiceSetup.ModifyAll(Enabled, false);        CurrExchRateUpdateSetup.ModifyAll(Enabled, false);        VATRegNoSrvConfig.ModifyAll(Enabled, false);        CDSIntegrationImpl.CleanCDSIntegration(CompanyName);        ServiceConnection.ModifyAll(Status, ServiceConnection.Status::Disabled);#if not CLEAN28        ExchangeSync.ModifyAll(Enabled, false);#endif        JobQueueManagement.SetRecurringJobsOnHold(CompanyName);    end;    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Environment Cleanup", 'OnClearCompanyConfig', '', false, false)]    local procedure ClearCompanyConfigProdToProd(CompanyName: Text; SourceEnv: Enum "Environment Type"; DestinationEnv: Enum "Environment Type")    begin        // Example on how to enfore a specific scenario. For instance prod to prod.         if (SourceEnv <> SourceEnv::Production) or (DestinationEnv <> DestinationEnv::Production) then            exit;        // Prod to prod copy cleanup code goes here    end;    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Environment Cleanup", 'OnClearDatabaseConfig', '', false, false)]    local procedure ClearDatabaseConfigGeneral(SourceEnv: Enum "Environment Type"; DestinationEnv: Enum "Environment Type")    var        FlowServiceConfiguration: Record "Flow Service Configuration";    begin        // For behavior in all cases of copying a new env.        FlowServiceConfiguration.ModifyAll("Flow Service", FlowServiceConfiguration."Flow Service"::"Testing Service (TIP 1)");        Commit();    end;    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Environment Cleanup", 'OnClearDatabaseConfig', '', false, false)]    local procedure ClearDatabaseConfigProdToProd(SourceEnv: Enum "Environment Type"; DestinationEnv: Enum "Environment Type")    begin        // Example on how to enfore a specific scenario. For instance prod to prod.        if (SourceEnv <> SourceEnv::Production) or (DestinationEnv <> DestinationEnv::Production) then            exit;        // Prod to prod copy cleanup code goes here    end;    [EventSubscriber(ObjectType::Report, Report::"Copy Company", 'OnAfterCreatedNewCompanyByCopyCompany', '', false, false)]    local procedure ClearPowerBIDeploymentsOnCopiedCompany(NewCompanyName: Text[30])    var        PBIDeploymentEvents: Codeunit "PBI Deployment Events";    begin        // Copy Company replicates Power BI deployment rows from the source company. Start the        // new company clean. Hosted here (rather than inside Modules/System/PowerBI) because        // the Power BI module can't reference Report::"Copy Company".        PBIDeploymentEvents.ClearDeploymentsForCompany(NewCompanyName);    end;}