Skip to content

Commit

Permalink
Critical bug fix: Delete files when deleting the db values.
Browse files Browse the repository at this point in the history
  • Loading branch information
gumbarros committed Dec 18, 2024
1 parent d9f7f0d commit 89c1480
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
17 changes: 9 additions & 8 deletions src/Core/DataManager/IO/FormFilePathBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,28 @@ public string GetFolderPath(FormElementField field, Dictionary<string, object> f
throw new ArgumentException(@$"{nameof(FormElementField.DataFile)} not defined.", field.Name);

//Pks concat with underline
string pkval = DataHelper.ParsePkValues(formElement, formValues, '_');
var pkValues = DataHelper.ParsePkValues(formElement, formValues, '_');

//Path configured in the dictionary
string path = field.DataFile.FolderPath;
var path = field.DataFile.FolderPath;

if (string.IsNullOrEmpty(path))
throw new ArgumentException(@$"{nameof(FormElementField.DataFile.FolderPath)} cannot be empty.", field.Name);

var separator = Path.DirectorySeparatorChar;

string appPath = FileIO.GetApplicationPath().TrimEnd(separator);
if (path.Contains("{app.path}"))
{
var appPath = FileIO.GetApplicationPath().TrimEnd(separator);

path = path.Replace("{app.path}", appPath);
path = Path.Combine(path, pkval);
path = path.Replace("{app.path}", appPath);
}

path = Path.Combine(path, pkValues);

if (!path.EndsWith(separator.ToString()))
path += separator;

return path;
}



}
9 changes: 5 additions & 4 deletions src/Core/DataManager/IO/FormFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ public void SaveFormMemoryFiles(FormElement formElement, Dictionary<string, obje
var pathBuilder = new FormFilePathBuilder(formElement);
foreach (var field in uploadFields)
{
string folderPath = pathBuilder.GetFolderPath(field, primaryKeys);
var folderPath = pathBuilder.GetFolderPath(field, primaryKeys);
var manager = formFileManagerFactory.Create($"{field.Name}-upload-view-files");
manager.SaveMemoryFiles(folderPath);
}
}

public void DeleteFiles(FormElement formElement, Dictionary<string, object> primaryKeys)
{
var uploadFields = formElement.Fields.FindAll(x => x.Component == FormComponent.File);
if (uploadFields.Count == 0)
var fileFields = formElement.Fields.FindAll(x => x.Component == FormComponent.File);
if (fileFields.Count == 0)
return;

foreach (var field in uploadFields)
foreach (var field in fileFields)
{
var manager = formFileManagerFactory.Create($"{field.Name}-upload-view-files");
manager.FolderPath = new FormFilePathBuilder(formElement).GetFolderPath(field, primaryKeys);
manager.DeleteAll();
}
}
Expand Down

0 comments on commit 89c1480

Please sign in to comment.