[horde] Question about removing userdata from horde (mysql)

Daniel Ritter daniel at daniel-ritter.de
Thu Oct 26 12:02:36 PDT 2006


Hi,
i scribbled down a quick PHP-Version of that bash-script as requested in 
the wiki (leaving the counting-part out)
Didn't have the time to test it yet, but it should work!?

Greets
Daniel

<?
#
#
#  Original (bash Version) From Beaudoin <jacques-beaudoin at cspi.qc.ca>
#  made it a little more flexible  Bill Graham <grahamcw at hurleybulldogs.com>
#  PHP version from Daniel Ritter <daniel at daniel-ritter.de>
#
#  From the Horde Wiki: http://wiki.horde.org/DatabaseCleanup?referrer=HowTo
# 
#  This PHP version is UNTESTED! Use at your own risk.



$dbname="horde";
$dbuser="youruser";
$dbpw="yourpw";
$dbhost="yourhost";

$user_to_del="username";


function sql_single($query)
{
global $dbname;
global $dbuser;
global $dbpw;
global $dbhost;

$connection = mysql_pconnect($dbhost,$dbuser,$dbpw);
echo mysql_error();
$feld = mysql_db_query($dbname,$query,$connection);
echo mysql_error();
$r = @mysql_fetch_row($feld);
echo mysql_error();
mysql_close($connection);
return($r[0]);
}


function sql_multi($query)
{
global $dbname;
global $dbuser;
global $dbpw;
global $dbhost;


$connection = mysql_pconnect($dbhost,$dbuser,$dbpw);
echo mysql_error();
$feld = mysql_db_query($dbname,$query,$connection);
echo mysql_error();
$r = @mysql_fetch_row($feld);
echo mysql_error();
mysql_close($connection);
return($r[0]);
}


#Lets get the datatree ID's
$get_datatree_ids = sql_multi("SELECT datatree_id from 
$dbname.horde_datatree WHERE user_uid='$user_to_del'");

while ($row = mysql_fetch_array($get_datatree_ids))
{
  $datatree_ids[] = $row["datatree_id"];
}

# We have array $datatree_ids now, filled with the id's of our $user_to_del


# Lets delete stuff that doesn't need that datatree_ids first

$del = sql_single("DELETE from $dbname.horde_prefs WHERE 
pref_uid='$user_to_del'");
$del = sql_single("DELETE from $dbname.kronolith_events WHERE 
calendar_id='$user_to_del'");
$del = sql_single("DELETE from $dbname.mnemo_memos WHERE 
memo_owner='$user_to_del'");
$del = sql_single("DELETE from $dbname.turba_objects WHERE 
owner_id='$user_to_del'");
$del = sql_single("DELETE from $dbname.nag_tasks WHERE 
task_owner='$user_to_del'");
$del = sql_single("DELETE from $dbname.horde_datatree WHERE 
user_uid='$user_to_del'");

# Delete records for our user from the datatree

foreach ($datatree_ids as $thisid)
{
sql_single("DELETE from $dbname.horde_datatree_attributes WHERE 
datatree_id='$this_id'");
}

echo "Deleted data for user $user_to_del";


?>



















More information about the horde mailing list