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

A document saved again by a listener of its save is compared with the version before the first save

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 18.10.0
    • Old Core
    • None
    • Unknown

    Description

      When a listener of the save of a document (e.g. of DocumentUpdatedEvent or DocumentCreatedEvent) saves the same document instance again, or a copy of it, the nested save is based on the version before the first save instead of the version that was just saved:

      • the listeners of the nested save compare it with the version before the first save, so they see the changes of both saves: e.g. the attachments added by the first save are notified again with AttachmentAddedEvent, and when the first save created the document, the nested save sends DocumentCreatingEvent/DocumentCreatedEvent again instead of DocumentUpdatingEvent/DocumentUpdatedEvent;
      • once the nested save is done, the first save resets the original document of the saved instance to the version it saved, which is older than the stored one, so saving this instance again compares it with an outdated version.

      In XWiki Standard, AttachmentsListener (attachment redirects) saves the document it is notified about when an attachment is uploaded with the name of an attachment that was moved with an automatic redirect, so the upload is recorded twice in the activity stream/notifications (addAttachment event) and indexed twice.

      STEPS TO REPRODUCE:

      1. Upload an attachment image.png to a page A.
      2. Move it to another page B, with "Create an automatic redirect" checked (A now has an XWiki.RedirectAttachmentClass object).
      3. Upload a new attachment image.png to page A.
      4. Look at the notifications / activity stream of page A (as a user watching it), or at the AttachmentAddedEvent events sent.

      EXPECTED RESULTS:
      The new attachment is notified once (AttachmentAddedEvent, "attachment added" event); the save that removes the redirect is only an update of the page.

      ACTUAL RESULTS:
      AttachmentAddedEvent is sent twice for image.png (once for the upload, once for the save that removes the redirect, whose listeners compare the page with the version before the upload), so the attachment addition is recorded twice.

      The double AttachmentAddedEvent is reproduced by a unit test; how the notifications UI displays the two events wasn't checked.

      Found while working on XWIKI-22643.

      Attachments

        Issue Links

          Activity

            People

              MichaelHamann Michael Hamann
              MichaelHamann Michael Hamann
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: