aboutsummaryrefslogtreecommitdiff
path: root/mod/beechat/migrate.php
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2013-11-09 16:27:50 +0100
committerSem <sembrestels@riseup.net>2013-11-09 16:27:50 +0100
commit77f0367d454711f1d00e1fcfc5d31147055cc66a (patch)
treea6eaa77c11d74b5e9f245470ed7101a5f0133438 /mod/beechat/migrate.php
parent911d0021c374602c31e5bfd71b1cd8074f2c2293 (diff)
parent29be010b5837f36237216b187ad1d5988f98e8bc (diff)
downloadelgg-77f0367d454711f1d00e1fcfc5d31147055cc66a.tar.gz
elgg-77f0367d454711f1d00e1fcfc5d31147055cc66a.tar.bz2
Add 'mod/beechat/' from commit '29be010b5837f36237216b187ad1d5988f98e8bc'
git-subtree-dir: mod/beechat git-subtree-mainline: 911d0021c374602c31e5bfd71b1cd8074f2c2293 git-subtree-split: 29be010b5837f36237216b187ad1d5988f98e8bc
Diffstat (limited to 'mod/beechat/migrate.php')
-rw-r--r--mod/beechat/migrate.php88
1 files changed, 88 insertions, 0 deletions
diff --git a/mod/beechat/migrate.php b/mod/beechat/migrate.php
new file mode 100644
index 000000000..20bee7973
--- /dev/null
+++ b/mod/beechat/migrate.php
@@ -0,0 +1,88 @@
+<?php
+require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
+
+global $CONFIG;
+admin_gatekeeper();
+
+// It's possible large upgrades could exceed the max execution time.
+set_time_limit(0);
+
+// get ejabberd db settings from elgg.
+$domain = elgg_get_plugin_setting("domain", "beechat");
+$dbname = elgg_get_plugin_setting("dbname", "beechat");
+$dbhost = elgg_get_plugin_setting("dbhost", "beechat");
+$dbuser = elgg_get_plugin_setting("dbuser", "beechat");
+$dbpassword = elgg_get_plugin_setting("dbpassword", "beechat");
+
+$jabber_domain = $domain;
+
+$dbh_elgg = null;
+$dbh_ejabberd = null;
+
+$dsn_elgg = 'mysql:dbname='.$CONFIG->dbname.';host='.$CONFIG->dbhost;
+$dsn_ejabberd = 'mysql:dbname='.$dbname.';host='.$dbhost;
+
+$dbprefix = $CONFIG->dbprefix;
+
+$user = $dbuser;
+$password = $dbpassword;
+
+$relationship_type = 'friend';
+
+$counter = 0;
+
+try {
+ $dbh_elgg = new PDO($dsn_elgg, $CONFIG->dbuser, $CONFIG->dbpass);
+
+ $sql = 'SELECT guid, name, username FROM '.$dbprefix.'users_entity';
+ $sth = $dbh_elgg->prepare($sql);
+ $sth->execute();
+
+ $users = array();
+ while ($row = $sth->fetch(PDO::FETCH_ASSOC))
+ $users[$row['guid']] = $row;
+
+ $sql = 'SELECT guid_one, guid_two FROM '.$dbprefix.'entity_relationships ';
+ $sql .= 'WHERE relationship = ?;';
+ $sth = $dbh_elgg->prepare($sql);
+
+ $sth->bindParam(1, $relationship_type);
+ $sth->execute();
+
+ $dbh_ejabberd = new PDO($dsn_ejabberd, $user, $password);
+ $dbh_ejabberd->beginTransaction();
+
+ while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
+ $sql = 'INSERT INTO rosterusers (username, jid, nick, subscription, ask, server, type) VALUES (?, ?, ?, ?, ?, ?, ?);';
+ $sth_ejabberd = $dbh_ejabberd->prepare($sql);
+
+
+ $username = $users[$row['guid_one']]['username'];
+ $jid = $users[$row['guid_two']]['username'] . '@' . $jabber_domain;
+ $nick = $users[$row['guid_two']]['name'];
+ $subscription = 'B';
+ $ask = 'N';
+ $server = 'N';
+ $type = 'item';
+
+ $sth_ejabberd->execute(array($username, $jid, $nick, $subscription, $ask, $server, $type));
+
+ $counter += 1;
+ if ($counter % 1000 == 0) {
+ //error_log( $username . ' registered ' . $jid . ' as a friend in his roster.' . "\n");
+ error_log("importing relations into jabber: $counter");
+ }
+ }
+
+ $dbh_ejabberd->commit();
+
+ $dbh_elgg = null;
+ $dbh_ejabberd = null;
+} catch (PDOException $e) {
+ if ($dbh_ejabberd != null)
+ $dbh_ejabberd->rollBack();
+ echo $e->getMessage();
+}
+?>
+
+