/** * @return full name of document (ie: Main.WebHome) */ public String getFullName() { return this.deletedDoc.getFullName(); }
/** * @return id of deleted document. id is unique only for this document. */ public long getId() { return this.deletedDoc.getId(); }
/** * @return date of delete action */ public Date getDate() { return this.deletedDoc.getDate(); }
return false; deletedDocumentReference = deletedDocument.getDocumentReference(); deletedDocument.getFullName(), deletedDocumentId); } else if (request.isCheckAuthorRights() && !canRestoreDeletedDocument(deletedDocument, context.getAuthorReference())) { } else { xwiki.restoreFromRecycleBin(deletedDocument.getId(), "Restored from recycle bin", context);
public XWikiDocument doInHibernate(Session session) throws HibernateException, XWikiException { XWikiDeletedDocument trashdoc = (XWikiDeletedDocument) session.load(XWikiDeletedDocument.class, Long.valueOf(index)); return trashdoc.restoreDocument(null, context); } });
/** * @return language of document */ public String getLanguage() { return this.deletedDoc.getLanguage(); }
/** * @return user which delete document */ public String getDeleter() { return this.deletedDoc.getDeleter(); }
/** * {@inheritDoc} */ public void saveToRecycleBin(XWikiDocument doc, String deleter, Date date, XWikiContext context, boolean bTransaction) throws XWikiException { final XWikiDeletedDocument trashdoc = new XWikiDeletedDocument(doc, deleter, date, context); executeWrite(context, bTransaction, new HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException { session.save(trashdoc); return null; } }); }
/** * @return restored document * @param doc - restore to this document, if not null * @param context - may be useful in future * @throws XWikiException if error in {@link XWikiDocument#fromXML(String)} */ public XWikiDocument restoreDocument(XWikiDocument doc, XWikiContext context) throws XWikiException { XWikiDocument result = doc; if (result == null) { result = new XWikiDocument(); } result.fromXML(getXml(), true); return result; } }
/** * @param doc - deleted document * @param deleter - user which delete document * @param deleteDate - date of delete action * @param context - used for environment * @throws XWikiException if any error */ public XWikiDeletedDocument(XWikiDocument doc, String deleter, Date deleteDate, XWikiContext context) throws XWikiException { this.fullName = doc.getFullName(); this.language = doc.getLanguage(); this.deleter = deleter; this.date = deleteDate; setDocument(doc, context); }
return false; deletedDocumentReference = deletedDocument.getDocumentReference();
/** * @return the document as it is in the recycle bin */ public Document getDocument() { try { return new Document(this.deletedDoc.restoreDocument(null, this.context), this.context); } catch (XWikiException e) { LOG.warn("Failed to parse deleted document: " + e.getMessage()); return null; } } }
@Override public List<Long> getDeletedDocumentIds(String batchId) { XWikiContext context = this.xcontextProvider.get(); XWiki xwiki = context.getWiki(); List<Long> result = new ArrayList<>(); try { XWikiDeletedDocument[] deletedDocuments = xwiki.getRecycleBinStore().getAllDeletedDocuments(batchId, false, context, true); for (XWikiDeletedDocument deletedDocument : deletedDocuments) { result.add(deletedDocument.getId()); } } catch (Exception e) { logger.error("Failed to get deleted document IDs for batch [{}]", batchId); } return result; }
+ "immediately after it has been deleted from the wiki"); if (!dd.getFullName().equals(doc.getFullName())) { throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_URL_EXCEPTION,
protected boolean canRestoreDeletedDocument(XWikiDeletedDocument deletedDocument, DocumentReference userReference) { boolean result = false; XWikiContext context = this.xcontextProvider.get(); // Remember the context user. DocumentReference currentUserReference = context.getUserReference(); try { // Reuse the DeletedDocument API to check rights. DeletedDocument deletedDocumentApi = new DeletedDocument(deletedDocument, context); // Note: DeletedDocument API works with the current context user. context.setUserReference(userReference); result = deletedDocumentApi.canUndelete(); } catch (Exception e) { logger.error("Failed to check restore rights on deleted document [{}] for user [{}]", deletedDocument.getId(), userReference, e); } finally { // Restore the context user; context.setUserReference(currentUserReference); } return result; }
protected boolean canPermanentlyDeleteDocument(XWikiDeletedDocument deletedDocument, DocumentReference userReference) { boolean result = false; XWikiContext context = this.xcontextProvider.get(); XWiki xwiki = context.getWiki(); // Remember the context user. DocumentReference currentUserReference = context.getUserReference(); try { // Reuse the DeletedDocument API to check rights. DeletedDocument deletedDocumentApi = new DeletedDocument(deletedDocument, context); // Note: DeletedDocument API works with the current context user. context.setUserReference(userReference); result = deletedDocumentApi.canDelete(); } catch (Exception e) { logger.error("Failed to check delete rights on deleted document [{}] for user [{}]", deletedDocument.getId(), userReference, e); } finally { // Restore the context user; context.setUserReference(currentUserReference); } return result; }