feat: implement page/post duplication, add event layout, auto-extract featured images, and include HTML escaping for templates.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class FixPosts {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/sisvietnam", "sisvietnam", "sisvietnam");
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT id, content FROM sis_post WHERE featured_image IS NULL");
|
||||
Pattern p = Pattern.compile("<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>");
|
||||
int count = 0;
|
||||
while (rs.next()) {
|
||||
String content = rs.getString("content");
|
||||
if (content != null) {
|
||||
Matcher m = p.matcher(content);
|
||||
if (m.find()) {
|
||||
String imgUrl = m.group(1);
|
||||
Statement updateStmt = conn.createStatement();
|
||||
updateStmt.executeUpdate("UPDATE sis_post SET featured_image = '" + imgUrl + "' WHERE id = " + rs.getLong("id"));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("Updated " + count + " posts with featured images from content.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user