public XWikiAttachment doInHibernate(Session session) throws HibernateException, XWikiException { try { DeletedAttachment trashAttachment = (DeletedAttachment) session.load(DeletedAttachment.class, Long.valueOf(index)); return trashAttachment.restoreAttachment(attachment, context); } catch (Exception ex) { // Invalid recycle entry. return null; } } });
/** * {@inheritDoc} * <p> * bTransaction is ignored by this implementation. * </p> * * @see AttachmentRecycleBinStore#restoreFromRecycleBin(XWikiAttachment, long, XWikiContext, boolean) */ @Override public XWikiAttachment restoreFromRecycleBin(final XWikiAttachment attachment, final long index, final XWikiContext context, boolean bTransaction) throws XWikiException { final DeletedAttachment delAttach = getDeletedAttachment(index, context, false); return delAttach != null ? delAttach.restoreAttachment(attachment, context) : null; }
@Override public boolean storeEntity(DeletedAttachment entity) { if (entity == null) { return true; } try { XWikiAttachment attachment = entity.restoreAttachment(null, this.context.get()); this.store.saveToRecycleBin(attachment, entity.getDeleter(), entity.getDate(), this.context.get(), false); this.logger.debug("Imported deleted attachment [{}@{}#{}] into the filesystem trash store", entity.getDocName(), entity.getFilename(), entity.getId()); return true; } catch (XWikiException ex) { this.logger.error("Failed to store deleted attachment into the filesystem store: {}", ex.getMessage(), ex); return false; } } }
@Override public boolean storeEntity(DeletedAttachment entity) { if (entity == null) { return true; } try { XWikiAttachment attachment = entity.restoreAttachment(null, this.context.get()); this.store.saveToRecycleBin(attachment, entity.getDeleter(), entity.getDate(), this.context.get(), false); this.logger.debug("Imported deleted attachment [{}@{}#{}] into the filesystem trash store", entity.getDocName(), entity.getFilename(), entity.getId()); return true; } catch (XWikiException ex) { this.logger.error("Failed to store deleted attachment into the filesystem store: {}", ex.getMessage(), ex); return false; } } }
/** * Access to the real attachment object. * * @return the attachment as it was before being deleted, and as it currently is in the recycle bin */ public Attachment getAttachment() { try { Document doc = this.context.getWiki().getDocument(getDocName(), this.context).newDocument(this.context); return new Attachment(doc, this.deletedAttachment.restoreAttachment(null, this.context), this.context); } catch (XWikiException ex) { LOG.warn("Failed to parse deleted attachment: " + ex.getMessage(), ex); return null; } }
XWikiAttachment restoredAttachment = correctVariant.restoreAttachment(null, context); XWikiAttachment restoredAttachmentRevision = restoredAttachment.getAttachmentRevision(attachmentToRestore.getVersion(), context);