Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public boolean updateProperty(String docname, String className, String propertyn
bobject.setName(doc.getFullName());
bobject.setClassName(className);
bobject.set(propertyname, value, context);
doc.setContentDirty(true);
doc.setMetaDataDirty(true);
doc.setAuthor(context.getUser());
context.getWiki().saveDocument(doc, localizePlainOrKey("core.comment.updateProperty"),
context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ privileged public aspect XWikiDocumentCompatibilityAspect
bobject.setName(getFullName());
bobject.setClassName(className);
bobject.setListValue(fieldName, value);
setContentDirty(true);
setMetaDataDirty(true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void setContentDirty(boolean contentDirty)
{
this.isContentDirty = contentDirty;
if (contentDirty && this.ownerDocument != null) {
this.ownerDocument.setContentDirty(contentDirty);
this.ownerDocument.setMetaDataDirty(contentDirty);
}
}

Expand Down Expand Up @@ -332,7 +332,7 @@ public void setOwnerDocument(XWikiDocument ownerDocument)
{
this.ownerDocument = ownerDocument;
if (this.isContentDirty && ownerDocument != null) {
ownerDocument.setContentDirty(true);
ownerDocument.setMetaDataDirty(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ private static ObjectReferenceResolver<EntityReference> getCurrentReferenceObjec
@Override
public void onUpdate()
{
setContentDirty(true);
setMetaDataDirty(true);
}
};

Expand Down Expand Up @@ -1505,6 +1505,8 @@ public String getRenderedTitle(XWikiContext context)
public void setTitle(String title)
{
if (title != null && !title.equals(this.title)) {
// Document titles usually contain velocity script, so it is not enough to set the metadata dirty, since we
// want to content author to be updated for programming or script rights to be updated.
setContentDirty(true);
}
this.title = title;
Expand Down Expand Up @@ -2226,12 +2228,26 @@ public Map<DocumentReference, List<BaseObject>> getXObjects()
*/
public void setXObjects(Map<DocumentReference, List<BaseObject>> objects)
{
if (objects == null) {
// Make sure we don`t set a null objects map since we assume everywhere that it is not null when using it.
objects = new HashMap<>();
}

boolean isDirty = false;

for (List<BaseObject> objList : objects.values()) {
for (BaseObject obj : objList) {
obj.setOwnerDocument(this);
isDirty = true;
}
}
setContentDirty(true);

// This operation resulted in marking the current document dirty.
if (isDirty) {
setMetaDataDirty(true);
}

// Replace the current objects with the provided ones.
this.xObjects = objects;
}

Expand Down Expand Up @@ -2304,7 +2320,7 @@ public int createXObject(EntityReference classReference, XWikiContext context) t
objects.add(object);
int nb = objects.size() - 1;
object.setNumber(nb);
setContentDirty(true);
setMetaDataDirty(true);
return nb;
}

Expand Down Expand Up @@ -2402,7 +2418,7 @@ public void setXObjects(DocumentReference classReference, List<BaseObject> objec
}
}

setContentDirty(true);
setMetaDataDirty(true);
}

/**
Expand Down Expand Up @@ -2672,11 +2688,11 @@ public void setXObject(DocumentReference classReference, int nb, BaseObject obje
objects.add(null);
}
objects.set(nb, object);
setContentDirty(true);
setMetaDataDirty(true);
}

/**
* Replaces the object at the specified position and for the specified object xclass.
* Replaces the object at the specified position and for the specified object's xclass.
*
* @param nb index of the element to replace
* @param object the xobject to insert
Expand All @@ -2698,7 +2714,7 @@ public void setXObject(int nb, BaseObject object)
objects.add(null);
}
objects.set(nb, object);
setContentDirty(true);
setMetaDataDirty(true);
}

/**
Expand Down Expand Up @@ -2737,7 +2753,7 @@ public void mergeXClass(XWikiDocument templatedoc)
getXClass().merge(tbclass.clone());
}
}
setContentDirty(true);
setMetaDataDirty(true);
}

/**
Expand Down Expand Up @@ -2769,7 +2785,6 @@ public void mergeXObjects(XWikiDocument templateDoc)
}
}
}
setContentDirty(true);
}

/**
Expand Down Expand Up @@ -3930,24 +3945,25 @@ private void cloneAttachments(final XWikiDocument sourceDocument)
*/
public void copyAttachments(XWikiDocument sourceDocument)
{
// Note: when clearing the attachment list, we automatically mark the document's metadata as dirty.
getAttachmentList().clear();

Iterator<XWikiAttachment> attit = sourceDocument.getAttachmentList().iterator();
while (attit.hasNext()) {
XWikiAttachment attachment = attit.next();
XWikiAttachment newattachment = (XWikiAttachment) attachment.clone();
newattachment.setDoc(this);

// We need to set the content of the attachment to be dirty because the dirty bit
// is used to signal that there is a reason to save the attachment and while the
// old attachment has already been saved so there is not, the copy has not been
// saved so it should be.
// is used to signal that there is a reason to save the copied attachment, otherwise
// the copied attachment will be empty since the original attachment content is not
// modified in this operation.
if (newattachment.getAttachment_content() != null) {
newattachment.getAttachment_content().setContentDirty(true);
}

getAttachmentList().add(newattachment);
}
setContentDirty(true);
}

/**
Expand Down Expand Up @@ -5237,6 +5253,7 @@ public void renameProperties(DocumentReference classReference, Map<String, Strin
return;
}

boolean isDirty = false;
for (BaseObject bobject : objects) {
if (bobject == null) {
continue;
Expand All @@ -5250,11 +5267,16 @@ public void renameProperties(DocumentReference classReference, Map<String, Strin
bobject.removeField(origname);
prop.setName(newname);
bobject.addField(newname, prop);

isDirty = true;
}
}
}

setContentDirty(true);
// If at least one property was renamed, mark the document dirty.
if (isDirty) {
setMetaDataDirty(true);
}
}

/**
Expand All @@ -5273,7 +5295,7 @@ public void addXObjectToRemove(BaseObject object)
{
getXObjectsToRemove().add(object);
object.setOwnerDocument(null);
setContentDirty(true);
setMetaDataDirty(true);
}

/**
Expand All @@ -5294,8 +5316,7 @@ public void addXObjectsToRemoveFromVersion(XWikiDocument previousVersion)
BaseObject newObj = getXObject(originalObj.getXClassReference(), originalObj.getNumber());
if (newObj == null) {
// The object was deleted.
getXObjectsToRemove().add(originalObj);
setContentDirty(true);
this.addXObjectToRemove(originalObj);
}
}
}
Expand Down Expand Up @@ -5334,7 +5355,7 @@ public ArrayList<BaseObject> getObjectsToRemove()
public void setXObjectsToRemove(List<BaseObject> objectsToRemove)
{
this.xObjectsToRemove = objectsToRemove;
setContentDirty(true);
setMetaDataDirty(true);
}

public List<String> getIncludedPages(XWikiContext context)
Expand Down Expand Up @@ -8530,7 +8551,7 @@ private BaseObject prepareXObject(EntityReference classReference)
addXObject(bobject);
}
bobject.setDocumentReference(getDocumentReference());
setContentDirty(true);
setMetaDataDirty(true);
return bobject;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ public void setOwnerDocument(XWikiDocument ownerDocument)
}

if (ownerDocument != null && this.isDirty) {
ownerDocument.setContentDirty(true);
ownerDocument.setMetaDataDirty(true);
}
}

Expand All @@ -1345,7 +1345,7 @@ public void setDirty(boolean isDirty)
{
this.isDirty = isDirty;
if (isDirty && this.ownerDocument != null) {
this.ownerDocument.setContentDirty(true);
this.ownerDocument.setMetaDataDirty(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public boolean action(XWikiContext context) throws XWikiException
} else {
// className = XWiki.XWikiComments
String className = baseclass.getName();
// Create a new comment object and mark the document as dirty.
BaseObject object = doc.newObject(className, context);
// TODO The map should be pre-filled with empty strings for all class properties, just like in
// ObjectAddAction, so that properties missing from the request are still added to the database.
Expand All @@ -88,10 +89,8 @@ public boolean action(XWikiContext context) throws XWikiException
object.set(AUTHOR_PROPERTY_NAME, context.getUser(), context);
}
doc.setAuthorReference(context.getUserReference());
// Consider comments not being content.
doc.setContentDirty(false);
// if contentDirty is false, in order for the change to create a new version metaDataDirty must be true.
doc.setMetaDataDirty(true);

// Save the new comment.
xwiki.saveDocument(doc, localizePlainOrKey("core.comment.addComment"), true, context);
}
// If xpage is specified then allow the specified template to be parsed.
Expand Down
Loading