Skip to content

Commit 9075668

Browse files
committed
XWIKI-19948: Bad diff information when xobject is deleted (#2439)
* Ensure to retrieve the xclass even when the xobject has been deleted * Ensure the BaseObject contains an XClass reference when creating it in XWikiDocument#getObjectDiff (cherry picked from commit f1eaec1)
1 parent 422a240 commit 9075668

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7120,7 +7120,10 @@ public List<List<ObjectDiff>> getObjectDiff(XWikiDocument fromDoc, XWikiDocument
71207120
List<ObjectDiff> dlist;
71217121
if (newObj == null) {
71227122
// The object was deleted.
7123-
dlist = new BaseObject().getDiff(originalObj, context);
7123+
newObj = new BaseObject();
7124+
// We want the xclass reference to be set so that it can resolve the xclass properties.
7125+
newObj.setXClassReference(originalObj.getXClassReference());
7126+
dlist = newObj.getDiff(originalObj, context);
71247127
ObjectDiff deleteMarker =
71257128
new ObjectDiff(originalObj.getXClassReference(), originalObj.getNumber(),
71267129
originalObj.getGuid(), ObjectDiff.ACTION_OBJECTREMOVED, "", "", "", "");

xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/objects/BaseObject.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ public List<ObjectDiff> getDiff(Object oldEntity, XWikiContext context)
308308
BaseProperty newProperty = (BaseProperty) this.getField(propertyName);
309309
BaseProperty oldProperty = (BaseProperty) oldObject.getField(propertyName);
310310
BaseClass bclass = getXClass(context);
311+
// Bulletproofing: in theory the BaseObject is defined with a xclass reference allowing to resolve it
312+
// however, it's possible that the reference is not set, in which case we might still find the info
313+
// in the old object.
314+
if (bclass == null) {
315+
bclass = oldObject.getXClass(context);
316+
}
311317
PropertyClass pclass = (PropertyClass) ((bclass == null) ? null : bclass.getField(propertyName));
312318
String propertyType = (pclass == null) ? "" : pclass.getClassType();
313319

0 commit comments

Comments
 (0)