View Issue Details

IDProjectCategoryView StatusLast Update
0021994mantisbtattachmentspublic2017-06-04 14:58
Reportertk Assigned Todregad  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version1.3.1 
Target Version2.5.0Fixed in Version2.5.0 
Summary0021994: issue with attachments cannot be moved between projects with different upload directories (uploads saved in file system)
Description

I use file system based attachment uploads.

When attempting to move an issue with attachments between projects with different upload directories I see:
<pre>
APPLICATION ERROR 0000401
Database query failed. Error received from database was 0001064: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4 for the query:
UPDATE mantis_bug_file_table
SET folder=?
WHERE bug_id=?
AND id =?.
</pre>
After pressing the back button,
a) the bug still resides in the source project
b) the first attachment of the issue is displayed strike through and marked "(Attachment missing)"
c) the stored attachment file on the file system has actually been moved to the upload Folder of the destination project

[EDIT: breaking long line to avoid scrolling]

Additional Information

I see the same effect in version 1.3.1.
My last 1.2.x release ( 1.2.18 ) worked correctly.

TagsNo tags attached.

Relationships

has duplicate 0022264 closedatrol APPLICATION ERROR 0000401 while moving issue with attachments to different project 

Activities

dregad

dregad

2016-11-30 11:24

developer   ~0054646

Updating product version since you mentioned it's also not working in 1.3.1

petergruenbeck

petergruenbeck

2017-02-09 19:21

reporter   ~0055626

Tracing through the code, I find this. I added 2 log_events:

2017-02-09 15:04 PST FILE file_api.php:1075 file_move_bug_attachments() Moving attachment /var/mantis/attachments/4/39998f17602597954629f59cc6bcf97b to /var/mantis/attachments/84/39998f17602597954629f59cc6bcf97b
2017-02-09 15:04 PST FILE file_api.php:1076 file_move_bug_attachments() Query path=/var/mantis/attachments/84/ c_bug_id=11290 file row=1988

2017-02-09 15:04 PST DB file_api.php:1087 file_move_bug_attachments() array (
0 => 'UPDATE mantis_bug_file_table
SET folder=\'/var/mantis/attachments/84/\'
WHERE bug_id=11290
AND id =1988',
1 => '0.0003',
)

log_event(LOG_FILE,'Moving attachment ' . $t_disk_file_name_from . ' to ' . $t_disk_file_name_to);
log_event(LOG_FILE,'Query path=' . db_prepare_string($t_path_to) . ' c_bug_id=' . $c_bug_id . ' file row=' . $t_row['id'] );

The relevant code bits near mantis/htdocs/core/file_api.php:1060

db_param_push();
$t_query_disk_attachment_update = 'UPDATE {bug_file}
                                 SET folder=' . db_param() . '
                                 WHERE bug_id=' . db_param() . '
                                 AND id =' . db_param();

and

        # Don't pop the parameters after query execution since we're in a loop
        db_query( $t_query_disk_attachment_update, array( db_prepare_string( $t_path_to ), $c_bug_id, (int)$t_row['id'] ), false );
petergruenbeck

petergruenbeck

2017-02-09 19:46

reporter   ~0055627

I think just leave off the 'false' at the end of the db_query should fix it.

db_query( $t_query_disk_attachment_update, array( db_prepare_string( $t_path_to ), $c_bug_id, (int)$t_row['id'] ));

tk

tk

2017-02-14 04:20

reporter   ~0055668

I've applied the patch proposed in 0021994:0055627 to my mantis 1.3.4 installation ( line no. 1085 in core/file_api.php of that release).
==> After that I was able to move an issue with two attachments repeatedly between two projects without problems.

Notably the comment in the line preceeding the offending line points to a wrong conclusion drawn during programming that section:
"# Don't pop the parameters after query execution since we're in a Loop"

tk

tk

2017-03-17 08:17

reporter   ~0056102

Hi all,

is there any chance to get the bug fixed (resp. to get the proposed patch accepted) in 1.3.x ?
To me, it's really a pain.

jbarker

jbarker

2017-05-04 17:56

reporter   ~0056775

I am having this exact same issue in v2.3.1
Can confirm line 1087 in core/file_api.php has been unchanged :
db_query( $t_query_disk_attachment_update, array( db_prepare_string( $t_path_to ), $c_bug_id, (int)$t_row['id'] ), false );

I am going to try dropping the 'false' at the end of db_query tonight after hours per peter's earlier post as a temporary solution.

dregad

dregad

2017-05-16 06:17

developer   ~0056862

Please note that the proposed workaround of dropping the false at the end of the db_query() call is an incorrect fix that will cause issues when file_move_bug_attachments() is used in a context where another database query is being built, and the bug being moved has more than one attachment.

The fix proposed in PR https://github.com/mantisbt/mantisbt/pull/1110 follows the correct approach of providing the default values for $p_limit and $p_offset.

tk

tk

2017-05-16 08:52

reporter   ~0056864

Positively tested the patch in 0021994:0056862 in a mantis 1.3.1 and 1.3.4 environment.

In the meantime I had also seen problems with the removed "false", but I was so sure I had written that as a note to that bug that I didn't check it, sorry.

jbarker

jbarker

2017-05-16 15:58

reporter   ~0056870

Thanks for the update. I've tested on 2.3.1 and it seems to be working fine now.

Related Changesets

MantisBT: master 33e1230b

2017-05-20 04:16

MS-Astra

Committer: dregad


Details Diff
Fix moving issues with attachments

Issues with attachments cannot be moved between projects with different
upload directories when files are stored in file system.

Add missing parameters to db_query() call in file_move_bug_attachments().

Fixes 0021994
Affected Issues
0021994
mod - core/file_api.php Diff File