Author Topic: Horde address book migration  (Read 7686 times)

Offline TrecK

  • Newbie
  • *
  • Posts: 1
Horde address book migration
« on: December 28, 2006, 07:10:29 AM »
Does anybody have script, that imports horde address book (stored in MySQL) to roundcube address book (MySQL too) ? Thnx in advance!

Offline seansan

  • Jr. Member
  • **
  • Posts: 84
Re: Horde address book migration
« Reply #1 on: December 28, 2006, 08:36:36 AM »

a. You could download horde contents via phpmyadmin = table dump to txt file.

b. Then do the same for roundcube.

You then have a. the content and b. the format. Alter file a to match the format of file b and import into roundcube table via phpmyadmin

Offline jonsjava

  • Jr. Member
  • **
  • Posts: 11
RE: Horde Addressbook Migration
« Reply #2 on: October 08, 2008, 04:26:04 PM »
ugly script, but it does the job well. I named the file import.php, placed it in my install root, and added a link to it in my addressbook file (skins/default/templates/addressbook.html)

import.php
<?php
/* ************************************ */
/* Roundcube DB connection data         */
/* ************************************ */
$host "****"//edit this
$user "****"//edit this
$password "****"//edit this
$db "****"//edit this
/* ************************************ */
/* END Roundcube DB connection data     */
/* ************************************ */
$domain "@domain.com"//change this, and make sure to leave the "@"




$link mysql_connect($host$user$password);
mysql_select_db($db$link);
session_start();
$session $_COOKIE['roundcube_sessid'];
$sql "SELECT `vars` FROM `session` WHERE `sess_id`='$session' LIMIT 1;";
$result mysql_query($sql);
$row mysql_fetch_assoc($result);
$data $row['vars'];
$data_array explode(";"$data);
foreach (
$data_array as $value){
	
if (
strstr($value"username")){
	
	
$temp_array explode("\""$value);
	
	
$username2 $temp_array[1];
	
}
	
if (
strstr($value"user_id")){
	
	
$temp_array explode("\""$value);
	
	
$userid $temp_array[1]; 
	
}
}

mysql_close($link);
/* ************************************ */
/* Horde DB connection data             */
/* ************************************ */
$username "****"//edit this
$password "****"//edit this
$host "****"//edit this
$db "****"//edit this
/* ************************************ */
/* END Horde DB connection data         */
/* ************************************ */




$link2 mysql_connect($host$username$password) or die("connection error");
mysql_select_db($db$link2);
$user $username2;
if (
strstr($user$domain)){
	
$user str_replace($domain""$user);
}
$sql "select object_name, object_alias, object_email from turba_objects where owner_id = '$user';";
$result mysql_query($sql);
$sql2 "INSERT INTO `contacts`(`contact_id`, `user_id`, `email`, `firstname`, `surname`) VALUES";
$count 0;
while (
$row mysql_fetch_assoc($result)){
	
$name $row['object_name'];
	
if (
strstr($name" ")){
	
	
$temp_array explode(" "$name);
	
	
if (
count($temp_array) == 2){
	
	
	
$name $temp_array[0];
	
	
	
$last_name $temp_array[1];
	
	
}
	
	
else{
	
	
	
$name $temp_array[0];
	
	
	
$last_name array_pop($temp_array);
	
	
}
	
}
	
else{
	
	
$last_name "";
	
}
	
$alias $row['object_alias'];
	
$email $row['object_email'];
	
if (
$count == 0){
	
	
$sql2 .= "('', '$userid', '$email', '$name', '$last_name')";
	
	
$count++;
	
}
	
else{
	
	
$sql2 .= ", ('', '$userid', '$email', '$name', '$last_name')";
	
}
}
$sql2 .= ";";
mysql_close($link2);



/* ************************************ */
/* Roundcube DB connection data         */
/* ************************************ */
$host "****"//edit this
$user "****"//edit this
$password "****"//edit this
$db "*****"//edit this
/* ************************************ */
/* END Roundcube DB connection data     */
/* ************************************ */




$link mysql_connect($host$user$password);
mysql_select_db("roundcube"$link);
$sql3 "SELECT * FROM `users` WHERE `imported`!=1 AND `user_id`='$userid' LIMIT 1;";
$result3 mysql_query($sql3);
if (
mysql_num_rows($result3) != 1){
	
header("location:./?_task=addressbook");
	
exit();
}
mysql_query($sql2);
$sql "UPDATE `users` SET `imported`='1' WHERE `user_id`='$userid' LIMIT 1;";
mysql_query($sql);
header("location:./?_task=addressbook");
exit();
?>

oh, and run this SQL string on your users table:
Code: [Select]
ALTER TABLE `users` ADD `imported` TINYINT( 1 ) NOT NULL ;
« Last Edit: October 08, 2008, 04:28:23 PM by jonsjava »