You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yacy_search_server/htroot/ContentIntegrationPHPBB3_p....

160 lines
7.2 KiB

// ContentIntegrationPHPBB3_p.java
// (C) 2009 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
// first published 27.05.2009 on http://yacy.net
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
//
// LICENSE
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import java.io.File;
import de.anomic.content.dao.Dao;
import de.anomic.content.dao.ImportDump;
import de.anomic.content.dao.PhpBB3Dao;
import de.anomic.http.metadata.RequestHeader;
import de.anomic.kelondro.util.DateFormatter;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
public class ContentIntegrationPHPBB3_p {
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
final serverObjects prop = new serverObjects();
final Switchboard sb = (Switchboard) env;
prop.put("check", 0);
prop.put("export", 0);
prop.put("import", 0);
if (post != null) {
String urlstub = post.get("content.phpbb3.urlstub", "");
String dbtype = post.get("content.phpbb3.dbtype", "");
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);
String dumpfile = post.get("content.phpbb3.dumpfile", "");
sb.setConfig("content.phpbb3.urlstub", urlstub);
sb.setConfig("content.phpbb3.dbtype", dbtype);
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);
sb.setConfig("content.phpbb3.dumpfile", dumpfile);
if (post.containsKey("check")) {
try {
Dao db = new PhpBB3Dao(
urlstub,
dbtype,
dbhost,
dbport,
dbname,
prefix,
dbuser,
dbpw
);
prop.put("check", 1);
prop.put("check_posts", db.size());
prop.putHTML("check_first", db.first().toString());
prop.putHTML("check_last", db.latest().toString());
db.close();
} catch (Exception e) {
e.printStackTrace();
prop.put("check", 2);
prop.put("check_error", e.getMessage());
}
}
if (post.containsKey("export")) {
try {
Dao db = new PhpBB3Dao(
urlstub,
dbtype,
dbhost,
dbport,
dbname,
prefix,
dbuser,
dbpw
);
int files = db.writeSurrogates(db.query(0, -1, 100), sb.surrogatesInPath, "fullexport-" + DateFormatter.formatShortSecond(), ppf);
prop.put("export", 1);
prop.put("export_files", files);
db.close();
} catch (Exception e) {
e.printStackTrace();
prop.put("export", 2);
prop.put("export_error", e.getMessage());
}
}
if (post.containsKey("import")) {
File f = new File(dumpfile);
if (!f.exists()) {
prop.put("import", 2);
prop.put("import_error", "file " + dumpfile + " does not exist");
} else try {
ImportDump importer = new ImportDump(
dbtype,
dbhost,
dbport,
dbname,
dbuser,
dbpw
);
importer.imp(f);
prop.put("import", 1);
importer.close();
} catch (Exception e) {
e.printStackTrace();
prop.put("import", 2);
prop.put("import_error", e.getMessage());
}
}
}
prop.putHTML("content.phpbb3.urlstub", sb.getConfig("content.phpbb3.urlstub", ""));
prop.putHTML("content.phpbb3.dbtype", sb.getConfig("content.phpbb3.dbtype", ""));
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", ""));
prop.putHTML("content.phpbb3.dumpfile", sb.getConfig("content.phpbb3.dumpfile", ""));
return prop;
}
}