/** * Get a TransactionRunnable for deleting an attachment. * * @param attachment the XWikiAttachment to delete. * @param updateDocument whether or not to update the document at the same time. * @param context the XWikiContext for the request. * @return a TransactionRunnable for deleting the attachment which must be run inside of an * XWikiHibernateTransaction * @throws XWikiException if unable to load the attachment archive to delete. */ private TransactionRunnable<XWikiHibernateTransaction> getAttachmentDeleteRunnable( final XWikiAttachment attachment, final boolean updateDocument, final XWikiContext context) throws XWikiException { final File attachFile = getFilesystemStoreTools().getAttachmentFileProvider(attachment).getAttachmentContentFile(); final FilesystemStoreTools ft = getFilesystemStoreTools(); return new AttachmentDeleteTransactionRunnable( attachment, updateDocument, context, attachFile, ft.getBackupFile(attachFile), ft.getLockForFile(attachFile)); }
/** * Get a TransactionRunnable for saving the attachment content. If {@link * XWikiAttachment#getAttachment_content()} yields null, this runnable will do nothing. * * @param attachment the XWikiAttachment whose content should be saved. * @param updateDocument whether or not to update the document at the same time. * @param context the XWikiContext for the request. * @return a TransactionRunnable for saving the attachment content in an * XWikiHibernateTransaction. * @throws XWikiException if thrown by AttachmentSaveTransactionRunnable() */ private TransactionRunnable<XWikiHibernateTransaction> getAttachmentContentSaveRunnable( final XWikiAttachment attachment, final boolean updateDocument, final XWikiContext context) throws XWikiException { final XWikiAttachmentContent content = attachment.getAttachment_content(); if (content == null) { // If content does not exist we should not blank the attachment. return new TransactionRunnable<XWikiHibernateTransaction>(); } // This is the permanent location where the attachment content will go. final File attachFile = getFilesystemStoreTools().getAttachmentFileProvider(attachment).getAttachmentContentFile(); final FilesystemStoreTools ft = getFilesystemStoreTools(); return new AttachmentSaveTransactionRunnable( attachment, updateDocument, context, attachFile, ft.getTempFile(attachFile), ft.getBackupFile(attachFile), ft.getLockForFile(attachFile)); }