=== modified file 'sites/all/modules/project_issue/project_issue.module' --- sites/all/modules/project_issue/project_issue.module 2011-07-12 21:57:02 +0000 +++ sites/all/modules/project_issue/project_issue.module 2011-09-17 18:55:16 +0000 @@ -457,13 +457,19 @@ $form['attachments']['#weight'] = 2; // TODO: temporary hack until we decide how to deal with // editing attachments on issues overall. - if (!empty($form['cid']['#value'])) { + if (empty($form['cid']['#value'])) { + _project_issue_upload_list($form['attachments']['wrapper'], $form['#comment_upload_storage']); + } + else { $form['attachments']['#access'] = FALSE; } } // Add our own custom validation to the comment form for issue nodes. $form['#validate'][] = 'project_issue_form_comment_validate'; break; + case 'comment_upload_js': + _project_issue_upload_list($form); + break; case 'comment_confirm_delete': $type = db_result(db_query("SELECT type FROM {node} WHERE nid = %d", $form['#comment']->nid)); @@ -486,6 +492,36 @@ } } +/** + * Move the freshly uploaded files. + */ +function _project_issue_upload_list(&$file_wrapper_element, &$comment_upload_storage = array()) { + $cached_form_state = array(); + $cached_form = FALSE; + if ($issue_dir = variable_get('project_directory_issues', 'issues')) { + if (!$comment_upload_storage && ($cached_form = form_get_cache($_POST['form_build_id'], $cached_form_state)) && !empty($cached_form['#comment_upload_storage']) && isset($cached_form['attachments'])) { + $comment_upload_storage = &$cached_form['#comment_upload_storage']; + } + $directory = file_directory_path() . '/' . $issue_dir; + $move = array(); + foreach ($comment_upload_storage as $fid => $file) { + if (substr($file->filepath, 0, strlen($directory)) != $directory) { + $move[$fid] = (object) $file; + } + } + if ($move) { + project_issue_rewrite_issue_filepath($move); + foreach ($move as $fid => $file) { + $ccomment_upload_storage[$fid]['filepath'] = $file->filepath; + $file_wrapper_element['files'][$fid]['description']['#description'] = '' . file_create_url($file->filepath) . ''; + } + if ($cached_form) { + form_set_cache($_POST['form_build_id'], $cached_form, $cached_form_state); + } + } + } +} + function project_issue_node_info() { return array( 'project_issue' => array( @@ -1055,9 +1091,14 @@ $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); + if (file_exists($move_path)) { + file_move($move_path, $final_dir .'/'. basename($file->filepath)); + $new_basename = basename($move_path); + if (is_object($files[$key])) { + $files[$key]->filepath = $final_dir . '/'. $new_basename; + } + db_query("UPDATE {files} SET filepath = '%s' WHERE fid = %d", $final_dir .'/'. $new_basename, $file->fid); + } } } }