Skip to content
Snippets Groups Projects
Commit 69e05df6 authored by Goik Martin's avatar Goik Martin
Browse files

Correcting post's content (UTF-8 related)

parent 4064b808
No related branches found
No related tags found
No related merge requests found
......@@ -155,7 +155,7 @@ public class Id2Topic {
} else {
log.info ("Found topic (hdmId = " + hdmId + ", tid = " + tid + ")");
if (updateTopicTitles) {
db.updateTopicTitle(tid, title);
db.updateTopicTitle(tid, title, content);
}
return tid;
// Possibly aligning title and content with lecture notes?
......
......@@ -6,17 +6,18 @@ import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
import static com.mongodb.client.model.Filters.exists;
import static com.mongodb.client.model.Filters.eq;
import static com.mongodb.client.model.Filters.*;
import static com.mongodb.client.model.Updates.combine;
import static com.mongodb.client.model.Updates.set;
import com.mongodb.client.model.Projections;
import com.mongodb.client.result.UpdateResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bson.Document;
import org.bson.conversions.Bson;
import javax.management.Query;
import java.util.HashMap;
import java.util.Map;
......@@ -92,15 +93,35 @@ class ModifyNodebbTopic {
* @param tidKey A topic's _key value.
* @param title Update current topic's title.
*/
void updateTopicTitle(final int tidKey, final String title) {
void updateTopicTitle(final int tidKey, final String title, final String content) {
final String searchKey = "topic:" + tidKey;
final Document topic = objectCollection.find(eq("_key", searchKey)).first();
if (null != topic) {
objectCollection.updateOne(
{
final String searchKey = "topic:" + tidKey;
final UpdateResult updateResult = objectCollection.updateOne(
eq("_key", searchKey),
combine(set("title", title)));
log.info("Updated title to new value '" + title + "'");
final long matchedCount = updateResult.getMatchedCount();
if (0 < matchedCount) {
log.info("Matched topic " + matchedCount +
", updated " + updateResult.getModifiedCount() + " title(s) to new value '" + title + "'");
} else {
log.info("No topic update for '" + title + "'");
}
}
{
final UpdateResult updateResult = objectCollection.updateOne(
eq("pid", tidKey),
combine(set("content", content)));
final long matchedCount = updateResult.getMatchedCount();
if (0 < matchedCount) {
log.info("Matched post " + matchedCount +
", updated " + updateResult.getModifiedCount() + " content(s) to new value '" + content + "'");
} else {
log.info("No post update for '" + content + "'");
}
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment