Skip to content

Commit

Permalink
Specifies every temp table usage as temp record
Browse files Browse the repository at this point in the history
  • Loading branch information
IceOnly committed Dec 19, 2024
1 parent 6e6db59 commit 8137379
Show file tree
Hide file tree
Showing 17 changed files with 385 additions and 388 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ codeunit 9451 "File Account Impl."

procedure GetAllAccounts(LoadLogos: Boolean; var TempFileAccount: Record "File Account" temporary)
var
FileAccounts: Record "File Account";
TempFileFileAccounts: Record "File Account" temporary;
FileSystemConnector: Interface "External File Storage Connector";
Connector: Enum "Ext. File Storage Connector";
begin
Expand All @@ -28,28 +28,28 @@ codeunit 9451 "File Account Impl."
foreach Connector in Connector.Ordinals do begin
FileSystemConnector := Connector;

FileAccounts.DeleteAll();
FileSystemConnector.GetAccounts(FileAccounts);
TempFileFileAccounts.DeleteAll();
FileSystemConnector.GetAccounts(TempFileFileAccounts);

if FileAccounts.FindSet() then
if TempFileFileAccounts.FindSet() then
repeat
TempFileAccount := FileAccounts;
TempFileAccount := TempFileFileAccounts;
TempFileAccount.Connector := Connector;

if LoadLogos then
ImportLogo(TempFileAccount, Connector);

TempFileAccount.Insert();
until FileAccounts.Next() = 0;
until TempFileFileAccounts.Next() = 0;
end;

// Sort by account name
TempFileAccount.SetCurrentKey(Name);
end;

procedure DeleteAccounts(var FileAccountsToDelete: Record "File Account")
procedure DeleteAccounts(var TempFileAccountsToDelete: Record "File Account" temporary)
var
CurrentDefaultFileAccount: Record "File Account";
TempCurrentDefaultFileAccount: Record "File Account" temporary;
ConfirmManagement: Codeunit "Confirm Management";
FileScenario: Codeunit "File Scenario";
FileSystemConnector: Interface "External File Storage Connector";
Expand All @@ -59,53 +59,53 @@ codeunit 9451 "File Account Impl."
if not ConfirmManagement.GetResponseOrDefault(ConfirmDeleteQst, true) then
exit;

if not FileAccountsToDelete.FindSet() then
if not TempFileAccountsToDelete.FindSet() then
exit;

// Get the current default account to track if it was deleted
FileScenario.GetDefaultFileAccount(CurrentDefaultFileAccount);
FileScenario.GetDefaultFileAccount(TempCurrentDefaultFileAccount);

// Delete all selected accounts
repeat
// Check to validate that the connector is still installed
// The connector could have been uninstalled by another user/session
if IsValidConnector(FileAccountsToDelete.Connector) then begin
FileSystemConnector := FileAccountsToDelete.Connector;
FileSystemConnector.DeleteAccount(FileAccountsToDelete."Account Id");
if IsValidConnector(TempFileAccountsToDelete.Connector) then begin
FileSystemConnector := TempFileAccountsToDelete.Connector;
FileSystemConnector.DeleteAccount(TempFileAccountsToDelete."Account Id");
end;
until FileAccountsToDelete.Next() = 0;
until TempFileAccountsToDelete.Next() = 0;

DefaultAccountDeletion(CurrentDefaultFileAccount."Account Id", CurrentDefaultFileAccount.Connector);
DefaultAccountDeletion(TempCurrentDefaultFileAccount."Account Id", TempCurrentDefaultFileAccount.Connector);
end;

local procedure DefaultAccountDeletion(CurrentDefaultAccountId: Guid; Connector: Enum "Ext. File Storage Connector")
var
AllFileAccounts: Record "File Account";
NewDefaultFileAccount: Record "File Account";
TempAllFileAccounts: Record "File Account" temporary;
TempNewDefaultFileAccount: Record "File Account" temporary;
FileScenario: Codeunit "File Scenario";
begin
GetAllAccounts(false, AllFileAccounts);
GetAllAccounts(false, TempAllFileAccounts);

if AllFileAccounts.IsEmpty() then
if TempAllFileAccounts.IsEmpty() then
exit; //All of the accounts were deleted, nothing to do

if AllFileAccounts.Get(CurrentDefaultAccountId, Connector) then
if TempAllFileAccounts.Get(CurrentDefaultAccountId, Connector) then
exit; // The default account was not deleted or it never existed

// In case there's only one account, set it as default
if AllFileAccounts.Count() = 1 then begin
MakeDefault(AllFileAccounts);
if TempAllFileAccounts.Count() = 1 then begin
MakeDefault(TempAllFileAccounts);
exit;
end;

Commit(); // Commit the accounts deletion in order to prompt for a new default account
if PromptNewDefaultAccountChoice(NewDefaultFileAccount) then
MakeDefault(NewDefaultFileAccount)
if PromptNewDefaultAccountChoice(TempNewDefaultFileAccount) then
MakeDefault(TempNewDefaultFileAccount)
else
FileScenario.UnassignScenario(Enum::"File Scenario"::Default); // remove the default scenario as it is pointing to a non-existent account
end;

local procedure PromptNewDefaultAccountChoice(var NewDefaultFileAccount: Record "File Account"): Boolean
local procedure PromptNewDefaultAccountChoice(var TempNewDefaultFileAccount: Record "File Account" temporary): Boolean
var
FileAccountsPage: Page "File Accounts";
begin
Expand All @@ -115,11 +115,11 @@ codeunit 9451 "File Account Impl."
if FileAccountsPage.RunModal() <> Action::LookupOK then
exit;

FileAccountsPage.GetAccount(NewDefaultFileAccount);
FileAccountsPage.GetAccount(TempNewDefaultFileAccount);
exit(true);
end;

local procedure ImportLogo(var FileAccount: Record "File Account"; FileSystemConnector: Interface "External File Storage Connector")
local procedure ImportLogo(var TempFileAccount: Record "File Account" temporary; FileSystemConnector: Interface "External File Storage Connector")
var
FileSystemConnectorLogo: Record "File Storage Connector Logo";
Base64Convert: Codeunit "Base64 Convert";
Expand All @@ -134,25 +134,25 @@ codeunit 9451 "File Account Impl."
if ConnectorLogoBase64 = '' then
exit;

if not FileSystemConnectorLogo.Get(FileAccount.Connector) then begin
if not FileSystemConnectorLogo.Get(TempFileAccount.Connector) then begin
TempBlob.CreateOutStream(OutStream);
Base64Convert.FromBase64(ConnectorLogoBase64, OutStream);
TempBlob.CreateInStream(InStream);
FileSystemConnectorLogo.Init();
FileSystemConnectorLogo.Connector := FileAccount.Connector;
FileSystemConnectorLogo.Logo.ImportStream(InStream, StrSubstNo(ConnectorLogoDescriptionTxt, FileAccount.Connector));
FileSystemConnectorLogo.Connector := TempFileAccount.Connector;
FileSystemConnectorLogo.Logo.ImportStream(InStream, StrSubstNo(ConnectorLogoDescriptionTxt, TempFileAccount.Connector));
if FileSystemConnectorLogo.Insert() then;
end;
FileAccount.Logo := FileSystemConnectorLogo.Logo;
TempFileAccount.Logo := FileSystemConnectorLogo.Logo;
end;

procedure IsAnyAccountRegistered(): Boolean
var
FileAccount: Record "File Account";
TempFileAccount: Record "File Account" temporary;
begin
GetAllAccounts(false, FileAccount);
GetAllAccounts(false, TempFileAccount);

exit(not FileAccount.IsEmpty());
exit(not TempFileAccount.IsEmpty());
end;

procedure IsUserFileAdmin(): Boolean
Expand All @@ -162,19 +162,19 @@ codeunit 9451 "File Account Impl."
exit(FileScenario.WritePermission());
end;

procedure FindAllConnectors(var FileConnector: Record "Ext. File Storage Connector")
procedure FindAllConnectors(var TempFileConnector: Record "Ext. File Storage Connector" temporary)
var
FileConnectorLogo: Record "File Storage Connector Logo";
ConnectorInterface: Interface "External File Storage Connector";
FileSystemConnector: Enum "Ext. File Storage Connector";
begin
foreach FileSystemConnector in Enum::"Ext. File Storage Connector".Ordinals() do begin
ConnectorInterface := FileSystemConnector;
FileConnector.Connector := FileSystemConnector;
FileConnector.Description := ConnectorInterface.GetDescription();
if FileConnectorLogo.Get(FileConnector.Connector) then
FileConnector.Logo := FileConnectorLogo.Logo;
FileConnector.Insert();
TempFileConnector.Connector := FileSystemConnector;
TempFileConnector.Description := ConnectorInterface.GetDescription();
if FileConnectorLogo.Get(TempFileConnector.Connector) then
TempFileConnector.Logo := FileConnectorLogo.Logo;
TempFileConnector.Insert();
end;
end;

Expand All @@ -183,28 +183,28 @@ codeunit 9451 "File Account Impl."
exit("Ext. File Storage Connector".Ordinals().Contains(Connector.AsInteger()));
end;

procedure MakeDefault(var FileAccount: Record "File Account")
procedure MakeDefault(var TempFileAccount: Record "File Account" temporary)
var
FileScenario: Codeunit "File Scenario";
begin
CheckPermissions();

if IsNullGuid(FileAccount."Account Id") then
if IsNullGuid(TempFileAccount."Account Id") then
exit;

FileScenario.SetDefaultFileAccount(FileAccount);
FileScenario.SetDefaultFileAccount(TempFileAccount);
end;

procedure BrowseAccount(var FileAccount: Record "File Account")
procedure BrowseAccount(var TempFileAccount: Record "File Account" temporary)
var
StorageBrowser: Page "Storage Browser";
begin
CheckPermissions();

if IsNullGuid(FileAccount."Account Id") then
if IsNullGuid(TempFileAccount."Account Id") then
exit;

StorageBrowser.SetFileAccount(FileAccount);
StorageBrowser.SetFileAccount(TempFileAccount);
StorageBrowser.BrowseFileAccount('');
StorageBrowser.Run();
end;
Expand All @@ -216,7 +216,7 @@ codeunit 9451 "File Account Impl."
end;

[InternalEvent(false)]
procedure OnAfterSetSelectionFilter(var FileAccount: Record "File Account")
procedure OnAfterSetSelectionFilter(var TempFileAccount: Record "File Account" temporary)
begin
end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ page 9451 "File Account Wizard"
group(Account)
{
Caption = 'Account';
field(NameField; RegisteredAccount.Name)
field(NameField; TempRegisteredAccount.Name)
{
Editable = false;
Caption = 'Name';
Expand Down Expand Up @@ -294,7 +294,7 @@ page 9451 "File Account Wizard"
FileAccountImpl: Codeunit "File Account Impl.";
begin
if SetAsDefault then
FileAccountImpl.MakeDefault(RegisteredAccount);
FileAccountImpl.MakeDefault(TempRegisteredAccount);

CurrPage.Close();
end;
Expand All @@ -320,7 +320,7 @@ page 9451 "File Account Wizard"

trigger OnInit()
var
DefaultAccount: Record "File Account";
TempDefaultAccount: Record "File Account" temporary;
FileAccountImpl: Codeunit "File Account Impl.";
FileScenario: Codeunit "File Scenario";
begin
Expand All @@ -334,7 +334,7 @@ page 9451 "File Account Wizard"

FileRateLimitDisplay := NoLimitTxt;

if not FileScenario.GetDefaultFileAccount(DefaultAccount) then
if not FileScenario.GetDefaultFileAccount(TempDefaultAccount) then
SetAsDefault := true;

ConnectorsAvailable := Rec.FindFirst(); // Set the focus on the first record
Expand Down Expand Up @@ -417,8 +417,8 @@ page 9451 "File Account Wizard"
FileConnector := Rec.Connector;

ClearLastError();
AccountWasRegistered := FileConnector.RegisterAccount(RegisteredAccount);
RegisteredAccount.Connector := Rec.Connector;
AccountWasRegistered := FileConnector.RegisterAccount(TempRegisteredAccount);
TempRegisteredAccount.Connector := Rec.Connector;
end;

local procedure ShowDoneStep()
Expand Down Expand Up @@ -457,7 +457,7 @@ page 9451 "File Account Wizard"
end;

var
RegisteredAccount: Record "File Account";
TempRegisteredAccount: Record "File Account" temporary;
MediaResourcesStandard: Record "Media Resources";
MediaResourcesDone: Record "Media Resources";
[RunOnClient]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ page 9450 "File Accounts"

DefaultTxt := '';

IsDefault := DefaultFileAccount."Account Id" = Rec."Account Id";
IsDefault := TempDefaultFileAccount."Account Id" = Rec."Account Id";
if IsDefault then
DefaultTxt := '';
end;
Expand All @@ -249,7 +249,7 @@ page 9450 "File Accounts"
IsSelected := not IsNullGuid(SelectedAccountId);

FileAccount.GetAllAccounts(true, Rec); // Refresh the file accounts
FileScenario.GetDefaultFileAccount(DefaultFileAccount); // Refresh the default file account
FileScenario.GetDefaultFileAccount(TempDefaultFileAccount); // Refresh the default file account

if IsSelected then begin
Rec."Account Id" := SelectedAccountId;
Expand All @@ -276,19 +276,19 @@ page 9450 "File Accounts"
/// <summary>
/// Gets the selected file account.
/// </summary>
/// <param name="FileAccount">The selected file account</param>
procedure GetAccount(var FileAccount: Record "File Account")
/// <param name="TempFileAccount">The selected file account</param>
procedure GetAccount(var TempFileAccount: Record "File Account" temporary)
begin
FileAccount := Rec;
TempFileAccount := Rec;
end;

/// <summary>
/// Sets a file account to be selected.
/// </summary>
/// <param name="FileAccount">The file account to be initially selected on the page</param>
procedure SetAccount(var FileAccount: Record "File Account")
/// <param name="TempFileAccount">The file account to be initially selected on the page</param>
procedure SetAccount(var TempFileAccount: Record "File Account" temporary)
begin
Rec := FileAccount;
Rec := TempFileAccount;
end;

/// <summary>
Expand All @@ -301,7 +301,7 @@ page 9450 "File Accounts"
end;

var
DefaultFileAccount: Record "File Account";
TempDefaultFileAccount: Record "File Account" temporary;
FileAccountImpl: Codeunit "File Account Impl.";
CanUserManageFileSetup: Boolean;
IsDefault: Boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface "External File Storage Connector"
/// <param name="Path">The file path to list.</param>
/// <param name="FilePaginationData">Defines the pagination data.</param>
/// <param name="Files">A list with all files stored in the path.</param>
procedure ListFiles(AccountId: Guid; Path: Text; FilePaginationData: Codeunit "File Pagination Data"; var FileAccountContent: Record "File Account Content" temporary);
procedure ListFiles(AccountId: Guid; Path: Text; FilePaginationData: Codeunit "File Pagination Data"; var TempFileAccountContent: Record "File Account Content" temporary);

/// <summary>
/// Gets a file from the provided account.
Expand Down Expand Up @@ -73,7 +73,7 @@ interface "External File Storage Connector"
/// <param name="Path">The file path to list.</param>
/// <param name="FilePaginationData">Defines the pagination data.</param>
/// <param name="Files">A list with all directories stored in the path.</param>
procedure ListDirectories(AccountId: Guid; Path: Text; FilePaginationData: Codeunit "File Pagination Data"; var FileAccountContent: Record "File Account Content" temporary);
procedure ListDirectories(AccountId: Guid; Path: Text; FilePaginationData: Codeunit "File Pagination Data"; var TempFileAccountContent: Record "File Account Content" temporary);

/// <summary>
/// Creates a directory on the provided account.
Expand Down Expand Up @@ -101,7 +101,7 @@ interface "External File Storage Connector"
/// Gets the file accounts registered for the connector.
/// </summary>
/// <param name="Accounts">Out variable that holds the registered file accounts for the connector.</param>
procedure GetAccounts(var Accounts: Record "File Account");
procedure GetAccounts(var TempAccounts: Record "File Account" temporary);

/// <summary>
/// Shows the information for a file account.
Expand All @@ -115,7 +115,7 @@ interface "External File Storage Connector"
/// <remarks>The out parameter must hold the account ID of the added account.</remarks>
/// <param name="Account">Out parameter with the details of the registered Account.</param>
/// <returns>True if an account was registered.</returns>
procedure RegisterAccount(var FileAccount: Record "File Account"): Boolean
procedure RegisterAccount(var TempFileAccount: Record "File Account" temporary): Boolean

/// <summary>
/// Deletes a file account for the connector.
Expand Down
Loading

0 comments on commit 8137379

Please sign in to comment.