/** * Retrieve the internal entry index, used to uniquely identify this entity in the trash. This is needed because a * file can be attached and deleted multiple times, so the document name and filename are not enough to uniquely * identify a deleted attachment. * * @return internal identifier of the corresponding trash entry */ public long getId() { return this.deletedAttachment.getId(); }
@Override public DeletedAttachment next() { Long item = this.data.next(); try { DeletedAttachment result = HibernateDeletedAttachmentsReader.this.store.getDeletedAttachment( item, HibernateDeletedAttachmentsReader.this.context.get(), true); HibernateDeletedAttachmentsReader.this.logger.debug("Loaded [{}@{}#{}] from the database trash", result.getDocName(), result.getFilename(), result.getId()); return result; } catch (Exception ex) { HibernateDeletedAttachmentsReader.this.logger.error( "Failed to read deleted attachment from the database store: {}", ex.getMessage(), ex); } return null; }
@Override public DeletedAttachment next() { Long item = this.data.next(); try { DeletedAttachment result = HibernateDeletedAttachmentsReader.this.store.getDeletedAttachment( item, HibernateDeletedAttachmentsReader.this.context.get(), true); HibernateDeletedAttachmentsReader.this.logger.debug("Loaded [{}@{}#{}] from the database trash", result.getDocName(), result.getFilename(), result.getId()); return result; } catch (Exception ex) { HibernateDeletedAttachmentsReader.this.logger.error( "Failed to read deleted attachment from the database store: {}", ex.getMessage(), ex); } return null; }
@Override public boolean discardEntity(DeletedAttachment entity) { boolean transaction = false; try { transaction = ((XWikiHibernateBaseStore) this.store).beginTransaction(this.context.get()); Session session = ((XWikiHibernateBaseStore) this.store).getSession(this.context.get()); session.delete(entity); this.logger.debug("Deleted deleted attachment [{}@{}#{}] from the database trash", entity.getDocName(), entity.getFilename(), entity.getId()); } catch (XWikiException ex) { this.logger.warn("Failed to cleanup attachment from the database trash: {}", ex.getMessage()); return false; } finally { if (transaction) { ((XWikiHibernateBaseStore) this.store).endTransaction(this.context.get(), transaction); } } return true; }
@Override public boolean discardEntity(DeletedAttachment entity) { boolean transaction = false; try { transaction = ((XWikiHibernateBaseStore) this.store).beginTransaction(this.context.get()); Session session = ((XWikiHibernateBaseStore) this.store).getSession(this.context.get()); session.delete(entity); this.logger.debug("Deleted deleted attachment [{}@{}#{}] from the database trash", entity.getDocName(), entity.getFilename(), entity.getId()); } catch (XWikiException ex) { this.logger.warn("Failed to cleanup attachment from the database trash: {}", ex.getMessage()); return false; } finally { if (transaction) { ((XWikiHibernateBaseStore) this.store).endTransaction(this.context.get(), transaction); } } return true; }
@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; } } }
public long findDeletedAttachmentForDocRevision(XWikiDocument doc, String docRevision, String filename, XWikiContext context) throws XWikiException { XWikiAttachment attachment = null; XWikiDocument rdoc = context.getWiki().getDocument(doc, docRevision, context); if (context.getWiki().hasAttachmentRecycleBin(context) && filename != null) { attachment = rdoc.getAttachment(filename); if (attachment != null) { List<DeletedAttachment> deleted = context.getWiki().getAttachmentRecycleBinStore() .getAllDeletedAttachments(attachment, context, true); Collections.reverse(deleted); for (DeletedAttachment entry : deleted) { if (entry.getDate().after(rdoc.getDate())) { return entry.getId(); } } } } return -1; } }