Codeunit 8356 MCP Upgrade

System Application, System.MCP

src/System Application/App/MCP/src/Configuration/Codeunits/MCPUpgrade.Codeunit.al164 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.MCP;using System.Upgrade;codeunit 8356 "MCP Upgrade"{    Subtype = Upgrade;    InherentEntitlements = X;    InherentPermissions = X;    trigger OnUpgradePerDatabase()    begin        UpgradeMCPAPIToolVersion();        UpgradeMCPSystemDefaultAsDefault();        EnableApiToolsOnExistingConfigurations();        UpgradeRegisterMCPCapability();        UpgradeMCPCapabilityBilling();#if not CLEAN27        DisableDataQueryToolsOnExistingConfigurations();#endif    end;    internal procedure UpgradeMCPAPIToolVersion()    var        MCPConfigurationTool: Record "MCP Configuration Tool";        MCPConfigImplementation: Codeunit "MCP Config Implementation";        UpgradeTag: Codeunit "Upgrade Tag";    begin        if UpgradeTag.HasDatabaseUpgradeTag(GetMCPAPIToolVersionUpgradeTag()) then            exit;        MCPConfigurationTool.SetRange("API Version", '');        if MCPConfigurationTool.FindSet() then            repeat                if MCPConfigImplementation.IsAPIPage(MCPConfigurationTool."Object ID") then begin                    MCPConfigurationTool."API Version" := MCPConfigImplementation.GetHighestAPIPageVersion(MCPConfigurationTool."Object ID");                    MCPConfigurationTool.Modify();                end;            until MCPConfigurationTool.Next() = 0;        UpgradeTag.SetUpgradeTag(GetMCPAPIToolVersionUpgradeTag());    end;    internal procedure UpgradeMCPSystemDefaultAsDefault()    var        MCPConfiguration: Record "MCP Configuration";        UpgradeTag: Codeunit "Upgrade Tag";    begin        if UpgradeTag.HasDatabaseUpgradeTag(GetMCPSystemDefaultAsDefaultUpgradeTag()) then            exit;        if MCPConfiguration.Get('') then begin            MCPConfiguration.Default := true;            MCPConfiguration.Modify();        end;        UpgradeTag.SetUpgradeTag(GetMCPSystemDefaultAsDefaultUpgradeTag());    end;    internal procedure EnableApiToolsOnExistingConfigurations()    var        MCPConfiguration: Record "MCP Configuration";        UpgradeTag: Codeunit "Upgrade Tag";    begin        if UpgradeTag.HasDatabaseUpgradeTag(GetMCPEnableApiToolsUpgradeTag()) then            exit;        MCPConfiguration.ModifyAll(EnableApiTools, true);        UpgradeTag.SetUpgradeTag(GetMCPEnableApiToolsUpgradeTag());    end;    internal procedure UpgradeRegisterMCPCapability()    var        MCPCopilotCapReg: Codeunit "MCP Copilot Cap. Reg.";        UpgradeTag: Codeunit "Upgrade Tag";    begin        if UpgradeTag.HasDatabaseUpgradeTag(GetRegisterMCPCapabilityUpgradeTag()) then            exit;        MCPCopilotCapReg.RegisterMCPCapability();        UpgradeTag.SetUpgradeTag(GetRegisterMCPCapabilityUpgradeTag());    end;    internal procedure UpgradeMCPCapabilityBilling()    var        MCPCopilotCapReg: Codeunit "MCP Copilot Cap. Reg.";        UpgradeTag: Codeunit "Upgrade Tag";    begin        if UpgradeTag.HasDatabaseUpgradeTag(GetMCPUpdateCapabilityBillingUpgradeTag()) then            exit;        MCPCopilotCapReg.UpdateMCPCapabilityBilling();        UpgradeTag.SetUpgradeTag(GetMCPUpdateCapabilityBillingUpgradeTag());    end;#if not CLEAN27    internal procedure DisableDataQueryToolsOnExistingConfigurations()    var        MCPConfiguration: Record "MCP Configuration";        UpgradeTag: Codeunit "Upgrade Tag";    begin        if UpgradeTag.HasDatabaseUpgradeTag(GetMCPDisableDataQueryToolsUpgradeTag()) then            exit;        MCPConfiguration.ModifyAll(EnableAlQueryTools, false);        UpgradeTag.SetUpgradeTag(GetMCPDisableDataQueryToolsUpgradeTag());    end;#endif    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Upgrade Tag", OnGetPerDatabaseUpgradeTags, '', false, false)]    local procedure RegisterUpgradeTags(var PerDatabaseUpgradeTags: List of [Code[250]])    begin        PerDatabaseUpgradeTags.Add(GetMCPAPIToolVersionUpgradeTag());        PerDatabaseUpgradeTags.Add(GetMCPSystemDefaultAsDefaultUpgradeTag());        PerDatabaseUpgradeTags.Add(GetMCPEnableApiToolsUpgradeTag());        PerDatabaseUpgradeTags.Add(GetRegisterMCPCapabilityUpgradeTag());        PerDatabaseUpgradeTags.Add(GetMCPUpdateCapabilityBillingUpgradeTag());#if not CLEAN27        PerDatabaseUpgradeTags.Add(GetMCPDisableDataQueryToolsUpgradeTag());#endif    end;    local procedure GetMCPAPIToolVersionUpgradeTag(): Text[250]    begin        exit('MS-619475-MCPAPIToolVersion-20260126');    end;    local procedure GetMCPSystemDefaultAsDefaultUpgradeTag(): Text[250]    begin        exit('MS-612454-MCPSystemDefaultAsDefault-20260216');    end;    local procedure GetMCPEnableApiToolsUpgradeTag(): Text[250]    begin        exit('MS-631012-MCPEnableApiTools-20260603');    end;    local procedure GetRegisterMCPCapabilityUpgradeTag(): Text[250]    begin        exit('MS-641612-RegisterMCPCapability-20260612');    end;    local procedure GetMCPUpdateCapabilityBillingUpgradeTag(): Text[250]    begin        exit('MS-652515-MCPUpdateCapabilityBilling-20261001');    end;#if not CLEAN27    local procedure GetMCPDisableDataQueryToolsUpgradeTag(): Text[250]    begin        exit('MS-652515-MCPDisableDataQueryTools-20261001');    end;#endif}