Skip to content

Commit

Permalink
added option for a table prefix when importing phpbb3
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5996 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed May 29, 2009
1 parent 1c69d9b commit 4522c13
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions defaults/yacy.init
Expand Up @@ -906,6 +906,7 @@ content.phpbb3.dbtype = mysql
content.phpbb3.dbhost = localhost
content.phpbb3.dbport = 3306
content.phpbb3.dbname = forum
content.phpbb3.tableprefix = phpbb_
content.phpbb3.dbuser = notroot
content.phpbb3.dbpw = joshua
content.phpbb3.ppf = 1000
3 changes: 3 additions & 0 deletions htroot/ContentIntegrationPHPBB3_p.html
Expand Up @@ -36,6 +36,9 @@ <h2>Content Integration: Retrieval from phpBB3 Databases</h2>
<dt><b>Name of the database</b> on the host</dt>
<dd><input type="text" name="content.phpbb3.dbname" value="#[content.phpbb3.dbname]#" size="20" /></dd>

<dt><b>Table prefix string</b> for table names</dt>
<dd><input type="text" name="content.phpbb3.tableprefix" value="#[content.phpbb3.tableprefix]#" size="20" /></dd>

<dt><b>User</b> that can access the database</dt>
<dd><input type="text" name="content.phpbb3.dbuser" value="#[content.phpbb3.dbuser]#" size="20" /></dd>

Expand Down
5 changes: 5 additions & 0 deletions htroot/ContentIntegrationPHPBB3_p.java
Expand Up @@ -46,6 +46,7 @@ public static serverObjects respond(final httpRequestHeader header, final server
String dbhost = post.get("content.phpbb3.dbhost", "");
int dbport = post.getInt("content.phpbb3.dbport", 3306);
String dbname = post.get("content.phpbb3.dbname", "");
String prefix = post.get("content.phpbb3.tableprefix", "");
String dbuser = post.get("content.phpbb3.dbuser", "");
String dbpw = post.get("content.phpbb3.dbpw", "");
int ppf = post.getInt("content.phpbb3.ppf", 1000);
Expand All @@ -56,6 +57,7 @@ public static serverObjects respond(final httpRequestHeader header, final server
sb.setConfig("content.phpbb3.dbhost", dbhost);
sb.setConfig("content.phpbb3.dbport", dbport);
sb.setConfig("content.phpbb3.dbname", dbname);
sb.setConfig("content.phpbb3.tableprefix", prefix);
sb.setConfig("content.phpbb3.dbuser", dbuser);
sb.setConfig("content.phpbb3.dbpw", dbpw);
sb.setConfig("content.phpbb3.ppf", ppf);
Expand All @@ -68,6 +70,7 @@ public static serverObjects respond(final httpRequestHeader header, final server
dbhost,
dbport,
dbname,
prefix,
dbuser,
dbpw
);
Expand All @@ -92,6 +95,7 @@ public static serverObjects respond(final httpRequestHeader header, final server
dbhost,
dbport,
dbname,
prefix,
dbuser,
dbpw
);
Expand All @@ -114,6 +118,7 @@ public static serverObjects respond(final httpRequestHeader header, final server
prop.putHTML("content.phpbb3.dbhost", sb.getConfig("content.phpbb3.dbhost", ""));
prop.putHTML("content.phpbb3.dbport", sb.getConfig("content.phpbb3.dbport", ""));
prop.putHTML("content.phpbb3.dbname", sb.getConfig("content.phpbb3.dbname", ""));
prop.putHTML("content.phpbb3.tableprefix", sb.getConfig("content.phpbb3.tableprefix", ""));
prop.putHTML("content.phpbb3.dbuser", sb.getConfig("content.phpbb3.dbuser", ""));
prop.putHTML("content.phpbb3.dbpw", sb.getConfig("content.phpbb3.dbpw", ""));
prop.putHTML("content.phpbb3.ppf", sb.getConfig("content.phpbb3.ppf", ""));
Expand Down
19 changes: 11 additions & 8 deletions source/de/anomic/content/dao/PhpBB3Dao.java
Expand Up @@ -47,7 +47,7 @@
public class PhpBB3Dao implements Dao {

private Connection conn = null;
private String urlstub;
private String urlstub, prefix;
private HashMap<Integer, String> users;

public PhpBB3Dao(
Expand All @@ -56,10 +56,12 @@ public PhpBB3Dao(
String host,
int port,
String dbname,
String prefix,
String user,
String pw) throws Exception {
this.conn = getConnection(dbType, host, port, dbname, user, pw);
this.urlstub = urlstub;
this.prefix = prefix;
this.users = new HashMap<Integer, String>();
}

Expand Down Expand Up @@ -103,7 +105,7 @@ public void closeConnection() {

public Date first() {
StringBuilder sql = new StringBuilder(256);
sql.append("select min(post_time) from phpbb_posts");
sql.append("select min(post_time) from " + prefix + "posts");
Statement stmt = null;
ResultSet rs = null;
try {
Expand All @@ -124,7 +126,7 @@ public Date first() {

public Date latest() {
StringBuilder sql = new StringBuilder(256);
sql.append("select max(post_time) from phpbb_posts");
sql.append("select max(post_time) from " + prefix + "posts");
Statement stmt = null;
ResultSet rs = null;
try {
Expand All @@ -148,7 +150,7 @@ public int size() {
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery("select count(*) from phpbb_posts");
rs = stmt.executeQuery("select count(*) from " + prefix + "posts");
if (rs.next()) {
return rs.getInt(1);
}
Expand All @@ -164,15 +166,15 @@ public int size() {

public DCEntry get(int item) {
StringBuilder sql = new StringBuilder(256);
sql.append("select * from phpbb_posts where post_id = ");
sql.append("select * from " + prefix + "posts where post_id = ");
sql.append(item);
return getOne(sql);
}

public BlockingQueue<DCEntry> query(int from, int until, int queueSize) {
// define the sql query
final StringBuilder sql = new StringBuilder(256);
sql.append("select * from phpbb_posts where post_id >= ");
sql.append("select * from " + prefix + "posts where post_id >= ");
sql.append(from);
if (until > from) {
sql.append(" and post_id < ");
Expand All @@ -187,7 +189,7 @@ public BlockingQueue<DCEntry> query(int from, int until, int queueSize) {
public BlockingQueue<DCEntry> query(Date from, int queueSize) {
// define the sql query
final StringBuilder sql = new StringBuilder(256);
sql.append("select * from phpbb_posts where post_time >= ");
sql.append("select * from " + prefix + "posts where post_time >= ");
sql.append(from.getTime() / 1000);
sql.append(" order by post_id");

Expand Down Expand Up @@ -286,7 +288,7 @@ private String getUser(int poster_id) {
if (nick != null) return nick;

StringBuilder sql = new StringBuilder(256);
sql.append("select * from phpbb_users where user_id = ");
sql.append("select * from " + prefix + "users where user_id = ");
sql.append(poster_id);
Statement stmt = null;
ResultSet rs = null;
Expand Down Expand Up @@ -375,6 +377,7 @@ public static void main(String[] args) {
"localhost",
3306,
"forum",
"forum_",
"root",
""
);
Expand Down

0 comments on commit 4522c13

Please sign in to comment.