Delete "old" attachments

Hi All,

I have uploaded an image several times to the same Wiki page and I now what to remove “old revisions” of this attachment to keep / store only the last image. How can I perform this cleaning operation?

Thanks for your help,

PS: I searched but didn’t find any help, even in this page: https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Attachments which may be updated.

2 information to handle my request:

  • I don’t want to disable “attachment history feature” for the whole Wiki
  • the Wiki is hosted on myxwiki.org.

First, you shouldn’t… :slight_smile: the wiki is meant to be a history and this history is not supposed to be removed.

Now, it’s possible for admins to delete page revisions, see https://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/VersionControl and the “delete” action.

However due to Loading... this won’t remove associated attachment revisions…

You should be able to delete attachments using a script but I couldn’t find any example on snippets.xwiki.org or elsewhere. I tried looking at our API and didn’t find anything straightforward either. There’s XWikiAttachmentStoreInterface#deleteXWikiAttachment(XWikiAttachment attachment, ...)-.

@tmortagne might know better.

Not the right store :slight_smile:

I guess AttachmentVersioningStore#deleteArchive should do it according to the javadoc.

Right :slight_smile:

Won’t this remove all revisions of the passed attachment? I think @xrichard’s question was about removing some revisions only. Do we have an API to remove some revs from an attachment?

That’s not what I understand from

I have uploaded an image several times to the same Wiki page and I now what to remove “old revisions” of this attachment to keep / store only the last image.

@tmortagne Removing “old revisions” seems clear to me, it’s about removing old revisions and I understand “keep / store only the last image.” as keeping the last revision only. Anyway @xrichard will confirm.

My question still stands:

Do we have an API to remove some revs from an attachment?

You don’t loose the current version when you clean the archive.

Thanks for your answers guys,

I’m used to clean some page revisions (through Page history), my initial request is “can we do the same for attachments”?

You can imagine the following case: some pages with a big file (zip) stored several times and only the last version should be kept. The easy workaround I see from my “end-user” point of view is:

  • delete attachment (and thus all its revisions)
  • upload again the last attachment only
  • Clean “Deleted Attachments view” (using All pages Index as admin).

By doing so I should both gain “space” and keep existing links to the attachment (the URL should not change if the last attachment keeps its original name).

It looks like this manual way to proceed is the only solution.

That does not exist no. You do have a history UI similar to the page one but it does not have the remove revision feature and this feature is not implemented in the attachment archive either.

Without writing any script that’s the easiest yes.

Ok, does it make sense, from your point of view, to request this new feature “Edit attachment history”?

A jira would be good yes (if it doesn’t already exist), thanks.

Yes definitely.

Hi,

Jira improvment created, see Loading...