I noticed that if the Document Vault gets disabled for a given project, the files uploaded through it disappears, but come back upon re-activation. This means the files themselves exist somewhere, but are placed at a different location than regular issue attachments. I wanted to know if there is a way to convert such files into regular JIRA issue attachments? If it can be done in a bulk for the entire project, that would be great as well.
Hi Rei
Normal attachments are stored in the JIRA application data directory under data/attachments. The document vault files are stored under data/attachments/DocumentVault (with each project in a directory under that and issues at the next level. There is no method of converting these from Document Vault attachments to normal attachments. They can not just be copied across to the attachments directory because normal JIRA attachments have accompanying database records for each attachment.
I actually was able to utilize the Script Runner add-on to perform this ask. I tested this on our Dev environment and was able to move re-upload attachments with success. Just in case, I wanted to run the code by you to see if you see any dangers in performing the task this way. Please let me know
import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.MutableIssue; // Create necessary objects def im = ComponentAccessor.getIssueManager(); def am = ComponentAccessor.getAttachmentManager(); def um = ComponentAccessor.getUserManager(); // Dive into the Document Vault directory (project specific) Path dir = Paths.get('Enter directory here'); // Loop through each issue directory dir.eachFile { if (Files.isDirectory(it) && im.isExistingIssueKey(it.fileName.toString())) { // Create issue object def currentIssue = im.getIssueByCurrentKey(it.fileName.toString()); // Append issue key to the Document Vault directory Path newDir = Paths.get('Enter Document Vault directory' + it.fileName.toString()); newDir.eachFile { am.createAttachment(it.toFile(), it.fileName.toString(), Files.probeContentType(it).toString(), um.getUserByName("enter username"), currentIssue); } } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rei
I'm not too sure what language you are using but with the comments I think I can follow it (although I think the comment "Create Issue Object" should be "Get Issue Object"). So I think you are:
That sounds about right. Would be good if you had a test instance of JIRA you could practise on. Copy the a project and a couple of issue (2 should be fine) directories from the Document Vault directory onto the test box. Make sure you have a project and issues with the same keys, then try your script.
Let me know how you go
Thanks
Paul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Paul,
I was able to run the script successfully on our Dev instance and the files indeed get uploaded as regular JIRA issue attachments. However, I noticed that the files inside the Document Vault directory disappeared afterwards. Also, clicking the attachment links under the Document Vault UI on the actual issue results in 500 error. Even still, I am able to delete the supposedly "non-existent" attachment from the Document Vault UI.
Let me know your thoughts
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rei
I am not completely sure why they are disappearing but it must have something to do with the attach to JIRA process you are running in script runner. Probably the simplist answer would be to take a copy of the Document Vault directory before you run script and then copy it back afterwards. That way all of the files removed will be put back and Document Vault will be able to find them
Thanks
Paul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.