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

Saving a synthetic XWikiDocument always results in a DocumentCreat(ing/ed)Event instead of DocumentUpdat(ing/ed)Event when the document already exists

    XMLWordPrintable

Details

    • save event update synthetic document
    • Unknown
    • N/A
    • N/A

    Description

      When trying to save an XWikiDocument instance that was created outside the API (thus, "synthetic"), like for example at XAR import (when each document is created from its XML representation), listeners to DocumentUpdat(ing/ed)Event will never be notified, even when a version of the imported document already exists in the database (overriding import).

      This is because in the saveDocument method, we always create an originalDocument for XWikiDocuments that have none (synthetic documents), but we never set the isNew flag on this originalDocument. This means that, below in the code when originalDocument.isNew() is checked, it will always return true and always notify listeners of DocumentCreat(ing/ed)Event.

      The right way would be that, when we create originalDocument for synthetic XWikiDocuments, we should also do:

      originalDocument.setNew(exists(doc.getDocumentReference(), context))
      

      However, it is quite costly to do an additional DB query, at each save.

      Attachments

        Issue Links

          Activity

            People

              tmortagne Thomas Mortagne
              enygma Eduard Moraru
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: