Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-17409

XWikiAttachment#isMetaDataDirty() is not honored when saving an attachment

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 11.10.4
    • Fix Version/s: None
    • Component/s: Attachments, Old Core
    • Labels:
      None
    • Difficulty:
      Unknown
    • Similar issues:

      Description

      When programmatically creating a new attachment using the FS attachments store, there is no way to save the attachment with a specific date (as it can be done with XWikiDocuments) : even though a date can be set using XWikiAttachment#setDate(Date) along with XWikiAttachment#setMetaDataDirty(false) (so that metadatas do not get updated when saving the attachment), the date that has been set will overwritten with the current date at save time.

      Looking a bit more at the issue, this seems to come from https://github.com/xwiki/xwiki-platform/blob/eb0d7128deb7596f824d8e2f008dade8f54e6ba1/xwiki-platform-core/xwiki-platform-store/xwiki-platform-store-filesystem-oldcore/src/main/java/org/xwiki/store/legacy/doc/internal/ListAttachmentArchive.java#L299ListAttachmentArchive#update() is called during the save of the attachment and does not check for XWikiAttachment#isMetaDataDirty() before increasing the attachment version and updating the attachment date.

      To get this issue, here is an extract of the code used :

      {{groovy}}
      // pageDoc is a Document
      // attachmentIS is an InputStream
      
      def attach = pageDoc.addAttachment("MyAttachment.png", attachmentIS)
      attach.getAttachment().setAuthor("xwiki:XWiki.Admin")
      attach.getAttachment().setDate(myDate);
      attach.getAttachment().setMetaDataDirty(false);
      
      // Save the doc …
      {{/groovy}}
      

        Attachments

          Activity

            People

            • Assignee:
              ludovic Ludovic Dubost
              Reporter:
              caubin Clément Aubin
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: