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

XWiki Store resets the original document causing problems to DocumentUpdateEvent listeners that want to modify the document.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Minor
    • None
    • 2.3
    • Old Core
    • None
    • store save original document event listeners
    • Unknown

    Description

      When saving an XWiki document in the XWikiStore, we set the original document to be a clone of the document that was just been saved. see: https://fisheye2.atlassian.com/browse/xwiki/platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/XWikiHibernateStore.java?r=HEAD#l648
      ... and then, when needing to notify event listeners, we do a hack like this: https://fisheye2.atlassian.com/browse/xwiki/platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java?r=HEAD#l1415

      The problem appears when trying to save the same document from an event listener that is listening to DocumentUpdateEvent events.
      When saving the document from the event listener, the save gets overridden by the "magic" done at https://fisheye2.atlassian.com/browse/xwiki/platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java?r=HEAD#l1468

      In the following use case:

      saveDocument1
       changeListener1
        saveDocument2
         changeListener2 (does nothing)
        end saveDocument2
       end changeListener1
      end saveDocument1 <-- sets the original document to something other than what 'saveDocument2' intended.
      

      ... and the loop could be deeper.

      Next time this use case occurs, changeListener will receive a different original document than expected.

      As a suggestion, this could [?] be fixed by making the clone() call at the beginning of the store.saveXWikiDocument() instead of at the end, when it's already modified, this way avoiding all the code done at https://fisheye2.atlassian.com/browse/xwiki/platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/store/XWikiHibernateStore.java?r=HEAD#l648 to re-establish the proper original document and allowing DocumentUpdateEvent listeners to correctly modify the document.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              enygma Eduard Moraru
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: