Skip to content

Commit

Permalink
fix: Fix featured image is deleted in case of creating new page - EXO…
Browse files Browse the repository at this point in the history
…-75508 - Meeds-io/meeds#2614

Prior to this change, when create new page from draft with featured image and try to delete the draft after saving the new page, the featured image is deleted with the draft,
which shoudl not be the case when the featured image is linked to the original saved page, this due to wrong condition handling on the removeFeaturedImage function in case of
draft of new page.
This PR treats the case by updating the condition to not delete the featured image in case of draft of new page.
  • Loading branch information
hakermi committed Nov 25, 2024
1 parent 55b05b1 commit 339b5eb
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1711,8 +1711,8 @@ public void removeNoteFeaturedImage(Long noteId,
if (isDraft) {
DraftPage draftPage = getDraftNoteById(String.valueOf(noteId),
identityManager.getIdentity(String.valueOf(userIdentityId)).getRemoteId());
if (draftPage != null && draftPage.getTargetPageId() != null
&& isOriginalFeaturedImage(draftPage, getNoteByIdAndLang(Long.valueOf(draftPage.getTargetPageId()), lang))) {
if (draftPage != null && (draftPage.getTargetPageId() == null
|| isOriginalFeaturedImage(draftPage, getNoteByIdAndLang(Long.valueOf(draftPage.getTargetPageId()), lang)))) {
removeFeaturedImageFile = false;
}
note = draftPage;
Expand Down Expand Up @@ -1997,6 +1997,20 @@ private void deleteNoteMetadataProperties(Page note, String lang, String objectT
lang,
true,
Long.parseLong(identityManager.getOrCreateUserIdentity(note.getOwner()).getId()));
} else if(note.isDraftPage()) {
// When delete a draft of non-existing page
// check if its featured image was linked to a saved page
List<MetadataItem> metadataItems =
metadataService.getMetadataItemsByMetadataNameAndTypeAndObjectAndMetadataItemProperty(NOTES_METADATA_TYPE.getName(),
NOTES_METADATA_TYPE.getName(),
NOTE_METADATA_PAGE_OBJECT_TYPE,
FEATURED_IMAGE_ID,
featuredImageId,
0,
0);
if (metadataItems == null || metadataItems.isEmpty()) {
fileService.deleteFile(Long.parseLong(featuredImageId));
}
} else {
fileService.deleteFile(Long.parseLong(featuredImageId));
}
Expand Down

0 comments on commit 339b5eb

Please sign in to comment.