Skip to content

Commit

Permalink
fix: Fix import featured images - EXO-74718 - Meeds-io/meeds#2499 (#1171
Browse files Browse the repository at this point in the history
)

Prior to this change, when import notes with featured images, the
featured image are not correctly imported due to wrong extraction of
featuredId from exported fileName beside a wrong handle of different
conflict actions.
This PR makes sure to correctly extarct the export featured image id to
correctly import featured images.
  • Loading branch information
hakermi authored and exo-swf committed Oct 16, 2024
1 parent 86920ee commit bc0abe8
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;

Expand Down Expand Up @@ -1341,7 +1342,8 @@ public void importNotes(List<String> files, Page parent, String conflict, Identi
notesFilePath = file;
}
if (file.contains("/" + FEATURED_IMAGE_FOLDER + "/")) {
String imageId = file.substring(file.lastIndexOf("/") + 1);
String fileName = file.substring(file.lastIndexOf("/") + 1);
String imageId = fileName.substring(0, fileName.lastIndexOf("."));
featuredImages.put(imageId, file);
}
}
Expand Down Expand Up @@ -1975,6 +1977,7 @@ private void importNote(Page note,
String conflict,
Identity userIdentity) throws Exception {

Page targetNote = null;
File featuredImageFile = extractNoteFeaturedImageFileToImport(note, featuredImages);
Page parent_ = getNoteOfNoteBookByName(wiki.getType(), wiki.getOwner(), parent.getName());
if (parent_ == null) {
Expand All @@ -1991,6 +1994,7 @@ private void importNote(Page note,
imagesSubLocationPath);
note.setContent(processedContent);
note_ = createNote(wiki, parent_.getName(), note, userIdentity, false);
targetNote = note_;
} else {
if (StringUtils.isNotEmpty(conflict)) {
if (conflict.equals("overwrite") || conflict.equals("replaceAll")) {
Expand All @@ -2000,24 +2004,27 @@ private void importNote(Page note,
imagesSubLocationPath);
note.setContent(processedContent);
note_ = createNote(wiki, parent_.getName(), note, userIdentity, false);

targetNote = note_;
}
if (conflict.equals("duplicate")) {
String processedContent = htmlUploadImageProcessor.processSpaceImages(note.getContent(),
wiki.getOwner(),
imagesSubLocationPath);
note.setContent(processedContent);
note_ = createNote(wiki, parent_.getName(), note, userIdentity);
targetNote = note_;
}
if (conflict.equals("update")) {
if (!note_2.getTitle().equals(note.getTitle()) || !note_2.getContent().equals(note.getContent())) {
if (!note_2.getTitle().equals(note.getTitle()) || !note_2.getContent().equals(note.getContent())
|| !Objects.equals(note_2.getProperties(), note.getProperties())) {
note_2.setTitle(note.getTitle());
String processedContent = htmlUploadImageProcessor.processSpaceImages(note.getContent(),
wiki.getOwner(),
imagesSubLocationPath);
note_2.setContent(processedContent);
note_2 = updateNote(note_2, PageUpdateType.EDIT_PAGE_CONTENT, userIdentity);
createVersionOfNote(note_2, userIdentity.getUserId());
targetNote = note_2;
}
}
}
Expand All @@ -2026,20 +2033,21 @@ private void importNote(Page note,
if (StringUtils.isNotEmpty(conflict)
&& (conflict.equals("update") || conflict.equals("overwrite") || conflict.equals("replaceAll"))) {
Page note_1 = getNoteOfNoteBookByName(wiki.getType(), wiki.getOwner(), note.getName());
if (!note.getContent().equals(note_1.getContent())) {
if (!note.getContent().equals(note_1.getContent()) || !Objects.equals(note_1.getProperties(), note.getProperties())) {
String processedContent = htmlUploadImageProcessor.processSpaceImages(note.getContent(),
wiki.getOwner(),
imagesSubLocationPath);
note.setContent(processedContent);
note_1.setContent(processedContent);
note_1 = updateNote(note_1, PageUpdateType.EDIT_PAGE_CONTENT, userIdentity);
createVersionOfNote(note_1, userIdentity.getUserId());
targetNote = note_1;
}
}
}
if (featuredImageFile != null) {
saveImportedFeaturedImage(featuredImageFile,
note,
targetNote,
Long.parseLong(identityManager.getOrCreateUserIdentity(userIdentity.getUserId()).getId()));
}
if (note.getChildren() != null) {
Expand Down

0 comments on commit bc0abe8

Please sign in to comment.