Check missing filesystem attachments
Check filesystem attachments that are missing from disk and can not be downloaded |
Type | XAR |
Category | Application |
Developed by | |
Active Installs | 1 |
Rating | |
License | GNU Lesser General Public License 2.1 |
Table of contents
Description
In some rare cases, some page attachments can be displayed on a wiki page, but when trying to view or download them, you get an error that they can not be found. For some reason, the files were deleted from the filesystem, but the metadata is still present on the database.
This application helps you identify such compromised attachments on the main wiki and all subwikis.
Programming rights are needed to run this app.
Source
In case you just want this as a snippet and can't/won't install it with Extension Manager or with XAR import, you can examine the source below:
{{groovy}}
def fsAttachmentTool = services.component.getInstance(org.xwiki.store.filesystem.internal.FilesystemStoreTools);
def currentWiki = xcontext.getDatabase();
def count = 0;
println "|=Attachment File Name|=Document|=Wiki|=Attachment file Path"
for (def wiki in services.wiki.getAllIds()) {
// Chance the context wiki.
xcontext.setDatabase(wiki);
def attachmentReferences = services.query.hql("select doc.fullName, attachment.filename from XWikiDocument doc, XWikiAttachment attachment where doc.id=attachment.docId and attachment.contentStore='file'").execute();
for (def ref in attachmentReferences) {
def docFullName = ref[0];
def attachmentName = ref[1];
def attachmentStringRef = "${docFullName}@${attachmentName}"
def attachmentRef = services.model.resolveAttachment(attachmentStringRef)
def attachmentFile = fsAttachmentTool.getAttachmentFileProvider(attachmentRef).getAttachmentContentFile();
if (!attachmentFile.exists()) {
println "|{{{${attachmentName}}}}|[[${docFullName}]]|${wiki}|{{{${attachmentFile}}}}"
count++;
}
}
}
// Restore the context wiki.
xcontext.setDatabase(currentWiki);
println ""
println "Total: **${count}**";
{{/groovy}}
Prerequisites & Installation Instructions
We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.
You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:
- Log in the wiki with a user having Administration rights
- Go to the Administration page and select the Import category
- Follow the on-screen instructions to upload the downloaded XAR
- Click on the uploaded XAR and follow the instructions
- You'll also need to install all dependent Extensions that are not already installed in your wiki