View Issue Details

IDProjectCategoryView StatusLast Update
0032898mantisbtattachmentspublic2024-08-30 11:08
ReporterMarnix Assigned To 
PrioritylowSeverityminorReproducibilityalways
Status acknowledgedResolutionopen 
Product Version2.25.7 
Summary0032898: attachment location is based from project table instead of bug_file table
Description

Attachment information is stored in bug_file table including folder location. Column 'folder'.
The folder information is based on input from the project settings, the project table, column 'file_path'.
all good here.

Where it goes wrong is when changing the folder location within the (same) project.
When changing the folder within project settings;
1) new attachments will be from now on stored within the new location. --> good
2) new folder location is also stored within bug_file table. --> good
3) bet when i'm trying to open a previous attachment, located in the previous location, the attachment can't be found. --> Wrong!

The correct location is stored within the bug_file table.
Why is the project table 'file_path' information used instead of the 'folder' information from the bug_file table?

Reason of my question;
I have a project with over 10.000 attachments.
Due to FTP limitations, which can handle only maximum of 10.000 files within a folder, i need to change folder from time to time.
I don't want any attachment folder to go over the 10.000 files. That's why i want to change the folder location from time to time.

TagsNo tags attached.

Relationships

related to 0009905 closedvboctor Simplify the process of moving the attachments folder 
related to 0014718 closeddregad Clone cannot find attachments 

Activities

Marnix

Marnix

2024-08-06 08:11

reporter   ~0069076

Last edited: 2024-08-06 08:12

Can anyone please have a look at this issue?
Why is the folder of project table 'file_path' used instead of the 'folder' information from the bug_file table? That would make a lot more sense to me.

Marnix

Marnix

2024-08-06 09:04

reporter   ~0069078

Last edited: 2024-08-06 09:06


function file_normalize_attachment_path( $p_diskfile, $p_project_id ) {
    // Check if the disk file exists at the given path
    if (file_exists($p_diskfile)) {
            return $p_diskfile;
    }

    // Retrieve the base name of the file
    $t_basename = basename($p_diskfile);

    // Priority 1: Retrieve the folder directly from the bug_file table
    $query = 'SELECT folder FROM {bug_file} WHERE diskfile = ' . db_param();
    $result = db_query($query, [$p_diskfile]);

    // Initialize the expected file path
    $t_expected_file_path = '';

    // Check if we have a result and use the folder path from the bug_file table
        if ($row = db_fetch_array($result)) {
                $t_path = $row['folder'];

                if (!is_blank($t_path)) {
                        $t_diskfile = file_path_combine($t_path, $t_basename);

                        if (file_exists($t_diskfile)) {
                                return $t_diskfile;
                        }

                        // If the file is not found, this becomes the expected path
                        $t_expected_file_path = $t_diskfile;
                }
        }

    // Priority 2: Check the project-specific path
    if ($p_project_id != ALL_PROJECTS) {
            $t_path = project_get_field($p_project_id, 'file_path');
            if (!is_blank($t_path)) {
                    $t_diskfile = file_path_combine($t_path, $t_basename);

                    // Debug Log: Check project path
                    error_log("Checking project path: $t_diskfile");

                    if (file_exists($t_diskfile)) {
                            return $t_diskfile;
                    }

                    // If we don't find the file, then this is the path we want to return.
                    $t_expected_file_path = $t_diskfile;
            }
    }

    // Priority 3: Check the default global upload folder
    $t_path = config_get_global('absolute_path_default_upload_folder');
    if (!is_blank($t_path)) {
            $t_diskfile = file_path_combine($t_path, $t_basename);

            // Debug Log: Check global upload path
            error_log("Checking global upload path: $t_diskfile");

            if (file_exists($t_diskfile)) {
                    return $t_diskfile;
            }

            // If the expected path not set to project directory, then set it to the default directory.
            if (is_blank($t_expected_file_path)) {
                    $t_expected_file_path = $t_diskfile;
            }
    }

    // If diskfile doesn't include a path, then use the expected filename.
    if ((strstr($p_diskfile, DIRECTORY_SEPARATOR) === false ||
            strstr($p_diskfile, '\\') === false) &&
            !is_blank($t_expected_file_path)) {
            return $t_expected_file_path;
    }

    // Otherwise, return as is.
    return $p_diskfile;
}
dregad

dregad

2024-08-06 11:21

developer   ~0069082

Why is the folder of project table 'file_path' used instead of the 'folder' information from the bug_file table? That would make a lot more sense to me.

According to 0009905:0020243 the folder field was meant to be removed at some point in the past. I guess it was assumed back then, that all attachments were expected to be stored in the same directory.

This does not make much sense to me, particularly in a context such as yours where the directory changes over time.

Marnix

Marnix

2024-08-28 10:26

reporter   ~0069127

due to FTP limitations and for backup reasons its convenient to have them a little bit more organised then just all attachments in one folder. Over several years i get over 100.000 files.

juan alejandro suarez

juan alejandro suarez

2024-08-28 12:42

reporter   ~0069130

can you test with 1 file?, keep same path as per previous server/config. work ok? "moving the file with FTP transfer".