Search in sources :

Example 1 with StartableTransactionRunnable

use of org.xwiki.store.StartableTransactionRunnable in project xwiki-platform by xwiki.

the class FilesystemAttachmentRecycleBinContentStore method getDeletedAttachmentPurgeRunnable.

/**
 * Get a TransactionRunnable for removing a deleted attachment from the filesystem entirely.
 *
 * @param provider the file provider for the deleted attachment to purge from the recycle bin.
 * @return a StartableTransactionRunnable for removing the attachment.
 */
private StartableTransactionRunnable getDeletedAttachmentPurgeRunnable(final DeletedAttachmentFileProvider provider) {
    final StartableTransactionRunnable out = new StartableTransactionRunnable();
    final File deletedAttachDir = provider.getDeletedAttachmentMetaFile().getParentFile();
    if (!deletedAttachDir.exists()) {
        // No such dir, return a do-nothing runnable.
        return out;
    }
    // Easy thing to do is just delete everything in the deleted-attachment directory.
    for (File toDelete : deletedAttachDir.listFiles()) {
        new FileDeleteTransactionRunnable(toDelete, this.fileTools.getBackupFile(toDelete), this.fileTools.getLockForFile(toDelete)).runIn(out);
    }
    return out;
}
Also used : FileDeleteTransactionRunnable(org.xwiki.store.FileDeleteTransactionRunnable) StartableTransactionRunnable(org.xwiki.store.StartableTransactionRunnable) File(java.io.File)

Example 2 with StartableTransactionRunnable

use of org.xwiki.store.StartableTransactionRunnable in project xwiki-platform by xwiki.

the class FilesystemAttachmentRecycleBinContentStore method delete.

@Override
public void delete(AttachmentReference reference, Date deleteDate, long index, boolean bTransaction) throws XWikiException {
    DeletedAttachmentFileProvider provider = this.fileTools.getDeletedAttachmentFileProvider(reference, index);
    StartableTransactionRunnable tr = getDeletedAttachmentPurgeRunnable(provider);
    try {
        tr.start();
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.MODULE_XWIKI, "Failed to delete deleted attachment [" + reference + "]", e);
    }
}
Also used : DeletedAttachmentFileProvider(org.xwiki.store.filesystem.internal.DeletedAttachmentFileProvider) StartableTransactionRunnable(org.xwiki.store.StartableTransactionRunnable) XWikiException(com.xpn.xwiki.XWikiException) InitializationException(org.xwiki.component.phase.InitializationException) IOException(java.io.IOException) XWikiException(com.xpn.xwiki.XWikiException)

Example 3 with StartableTransactionRunnable

use of org.xwiki.store.StartableTransactionRunnable in project xwiki-platform by xwiki.

the class FilesystemAttachmentRecycleBinContentStore method save.

@Override
public void save(XWikiAttachment attachment, Date deleteDate, long index, boolean bTransaction) throws XWikiException {
    XWikiContext xcontext = this.xcontextProvider.get();
    final StartableTransactionRunnable tr = getSaveTrashAttachmentRunnable(attachment, index, xcontext);
    new StartableTransactionRunnable().runIn(tr);
    try {
        tr.start();
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.MODULE_XWIKI, "Failed to store deleted attachment [" + attachment.getReference() + "]", e);
    }
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) StartableTransactionRunnable(org.xwiki.store.StartableTransactionRunnable) XWikiException(com.xpn.xwiki.XWikiException) InitializationException(org.xwiki.component.phase.InitializationException) IOException(java.io.IOException) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

StartableTransactionRunnable (org.xwiki.store.StartableTransactionRunnable)3 XWikiException (com.xpn.xwiki.XWikiException)2 IOException (java.io.IOException)2 InitializationException (org.xwiki.component.phase.InitializationException)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 File (java.io.File)1 FileDeleteTransactionRunnable (org.xwiki.store.FileDeleteTransactionRunnable)1 DeletedAttachmentFileProvider (org.xwiki.store.filesystem.internal.DeletedAttachmentFileProvider)1