Index: comment.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/comment.inc,v retrieving revision 1.149 diff -u -F^f -u -F^f -r1.149 comment.inc --- comment.inc 18 Feb 2009 19:53:32 -0000 1.149 +++ comment.inc 19 Feb 2009 07:02:17 -0000 @@ -554,19 +554,10 @@ function project_issue_update_by_comment function project_issue_change_comment_upload_path(&$comment) { static $run = NULL; - $node = node_load($comment['nid']); - if (isset($comment['files']) && !isset($run)) { + // Only for new comments with attachments. + if (empty($comment['cid']) && isset($comment['files']) && !isset($run)) { $run = TRUE; // Make sure this only gets run once. - $issue_dir = variable_get('project_directory_issues', 'issues'); - foreach ($comment['files'] as $key => $file) { - if ($issue_dir && 0 === strpos($key, 'upload_')) { // Only rewrite the name when adding the file, not when updating it - // Change where the file will be saved to the specified directory. - // Since changes to the comment aren't carried to submit, we have - // to adjust $form_values here. - $filename = $issue_dir .'/'. $comment['files'][$key]['filename']; - form_set_value(array('#parents' => array('files', $key, 'filename')), $filename, $form_state); - } - } + project_issue_rewrite_issue_filepath($comment['files']); } } Index: project_issue.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.module,v retrieving revision 1.137 diff -u -F^f -u -F^f -r1.137 project_issue.module --- project_issue.module 19 Feb 2009 01:17:39 -0000 1.137 +++ project_issue.module 19 Feb 2009 07:02:18 -0000 @@ -912,16 +912,9 @@ function project_issue_issue_nodeapi(&$n project_issue_comment_view($node); break; case 'presave': - if (isset($node->files)) { - $issue_dir = variable_get('project_directory_issues', 'issues'); - foreach ($node->files as $key => $file) { - // Only rewrite the name when an issues directory exists, and when - // adding the file, not when updating it. - if ($issue_dir && 0 === strpos($key, 'upload_')) { - // Change where the file will be saved to the specified directory. - $node->files[$key]['filename'] = $issue_dir .'/'. $node->files[$key]['filename']; - } - } + // Only for new nodes with files set. + if (empty($node->nid) && isset($node->files)) { + project_issue_rewrite_issue_filepath($node->files); } break; case 'insert': @@ -976,6 +969,26 @@ function project_issue_exit() { } } +/** + * Rewrites the file information to move files to the issues directory. + * + * @param $files + * An array of file objects, keyed by file ID. + */ +function project_issue_rewrite_issue_filepath($files) { + if ($issue_dir = variable_get('project_directory_issues', 'issues') ) { + foreach ($files as $key => $file) { + $file = (object) $file; + $old_path = $file->filepath; + $final_dir = file_directory_path() .'/'. $issue_dir; + $move_path = $old_path; + file_move($move_path, $final_dir .'/'. basename($file->filepath)); + $new_basename = basename($move_path); + db_query("UPDATE {files} SET filepath = '%s' WHERE fid = %d", $final_dir .'/'. $new_basename, $file->fid); + } + } +} + function project_issue_my_projects_table() { $uid = 0; $display = views_get_page_view();