\documentclass{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{hyperref}
\pagestyle{headings}
\begin{document}
Syntax: horde\_cleanup.php [-vf] <user><br />
<user> can be regex

<pre><code class="language-php">
\#!/usr/bin/env php
<?php

function verbose(\$msg, \$type = 'cli.message')
\{
  if (!\$GLOBALS['verbose'])
    return false;
  \$prefix = (!empty(\$GLOBALS['vprefix'])) ? \$GLOBALS['vprefix'] . ' ' : '';
  return \$GLOBALS['cli']->message(\$prefix . \$msg, \$type);
\}

\# initialize horde
require\_once 'PEAR/Config.php';
\$baseDir = PEAR\_Config::singleton()->get('horde\_dir', null, 'pear.horde.org');

\# initialize kronolith instead of horde as we need the tagger instance
require\_once \$baseDir . '/kronolith/lib/Application.php';
Horde\_Registry::appInit('kronolith', array(
  'cli' => true,
  'authentication' => 'none',
  'user\_admin' => true
));

require\_once \$baseDir . '/content/lib/Application.php';
Horde\_Registry::appInit('content', array(
  'cli' => true,
  'user\_admin' => true
));
require CONTENT\_BASE . '/lib/Tags/Tag.php';
require CONTENT\_BASE . '/lib/Tags/TagMapper.php';
require CONTENT\_BASE . '/lib/Objects/ObjectMapper.php';

\# parse commandline options
\$c = new Console\_Getopt();
\$argv = \$c->readPHPArgv();
array\_shift(\$argv);
if (empty(\$argv) || empty(\$argv[0]))
\{
  \$cli->writeln(
    \$cli->bold('Syntax: ') .
    \$cli->blue(\$\_SERVER['argv'][0]) .
    \$cli->green(' [-vf]') .
    \$cli->red(' <user>')
  );
  exit(1);
\}
\$options = \$c->getopt2(\$argv, 'fv');
if (PEAR::isError(\$options))
  \$cli->fatal(\$options->getMessage());
\$user      = \$options[1][0];
\$regexp    = '\^{}'.\$user.'\$';
\$doremove  = false;
\$GLOBALS['verbose'] = false;
foreach (\$options[0] as \$val)
\{
  switch(\$val[0])
  \{
    case 'f':
      \$doremove = true;
      break;
    case 'v':
      \$GLOBALS['verbose'] = true;
      break;
  \}
\}

if (!\$doremove)
\{
  \$cli->message('DO\_NOT\_REMOVE-flag is set!', 'cli.warning');
  if (!\$GLOBALS['verbose'])
  \{
    \$cli->message('Enabling verbose mode...');
    \$GLOBALS['verbose'] = true;
  \}
\}

\# connect to database
try
\{
  \$db = \$GLOBALS['injector']->getInstance('Horde\_Core\_Factory\_Db')->create('horde', 'removeUser');
\}
catch(Horde\_Db\_Exception \$e)
\{
  \$cli->fatal('Unable to connect to the database: ' . \$e);
\}

\# fetch users from horde\_prefs
try
\{
  \$result = \$db->selectValues(
    'SELECT ' . \$db->distinct('pref\_uid') . ' ' .
    'FROM horde\_prefs');
  \$users = array();
  foreach(\$result as \$u)
  \{
    if (preg\_match('/'.\$regexp.'/', \$u))
      \$users[] = \$u;
  \}
\}
catch (Horde\_Db\_Exception \$e)
\{
  \$cli->fatal('Unable to select from table \textbackslash\{\}'horde\_prefs\textbackslash\{\}': ' . \$e);
\}

if (empty(\$users))
\{
  verbose('No users with syntax "' . \$regexp . '" found (no prefs exist)', 'cli.error');
  exit(0);
\}

\# fetch and check active sessions
try
\{
  \$sessionHandler = \$GLOBALS['injector']->createInstance('Horde\_SessionHandler');
  \$sessions = \$sessionHandler->getSessionsInfo();
  \$loggedin = array();
  foreach (\$sessions as \$sid => \$data)
  \{
    if (preg\_match('/'.\$regexp.'/', \$data['userid']))
    \{
      \# we're unable to delete sessions from phps builtin sessionhandler
      \#\$session->sessionHandler->destroy(\$sid);
      \$loggedin[\$data['userid']] = true;
    \}
  \}
\}
catch(Horde\_SessionHandler\_Exception \$e)
\{
  \$cli->fatal('Session counting is not supported with the current session handler.');
\}
if (!empty(\$loggedin))
  \$cli->fatal('The following users cannot be removed as they are currently logged in: ' . join(' ', array\_keys(\$loggedin)));

\# list users which will be removed
verbose('I\textbackslash\{\}'ll delete the following users:');
foreach(\$users as \$u)
  verbose('  ' . \$u);

\# get tagger
\$tagger = \$GLOBALS['injector']->getInstance('Content\_Tagger');

\# finally remove the data
\# NOTE: we're unable to remove every object references especially in rampage
\# thus we take care of that in a separate cron: cleanup\_rampage.php
if (\$doremove)
\{
  foreach(\$users as \$user)
  \{
    \$cli->message(str\_repeat('-', 30), 'cli.success');
    \$cli->message('Processing ' . \$user . '...', 'cli.success');

    \# remove tags
    try
    \{
      \$GLOBALS['vprefix'] = \$cli->yellow('[ Content ]');
      \$tUserId = current(\$GLOBALS['injector']->getInstance('Content\_Users\_Manager')->ensureUsers(\$user));
      \$tTags = \$tagger->getTags(array('userId' => \$tUserId));
      foreach(\$tTags as \$tTagId => \$tTag)
      \{
        \$tObjects = \$tagger->getObjects(array('tagId' => \$tTagId, 'userId' => \$tUserId));
        foreach(\$tObjects as \$tObjectId => \$tObject)
        \{
          verbose(sprintf('Removing tag "\%s/\%d" from object "\%s/\#\%d"...', \$tTag, \$tTagId, \$tObject, \$tObjectId), 'cli.none');
          \$tagger->untag(\$tUserId, \$tObjectId, \$tTagId);

          \# housekeeping: check if objects are used anymore
          verbose(sprintf('Removing object "\%s/\#\%d"...', \$tObject, \$tObjectId), 'cli.none');
          \$mapper = new Content\_ObjectMapper(\$injector->getInstance('Horde\_Db\_Adapter'));
          \$mapper->delete(\$tObjectId);
        \}

        \# housekeeping: check if tags are used anymore
        \$tObjects = \$tagger->getObjects(array('tagId' => \$tTagId));
        if (empty(\$tObjects))
        \{
          verbose(sprintf('Removing tag "\%s/\#\%d" as it isn\textbackslash\{\}'t used any more...', \$tTag, \$tTagId), 'cli.none');
          \$mapper = new Content\_TagMapper(\$injector->getInstance('Horde\_Db\_Adapter'));
          \$mapper->delete(\$tTagId);
        \}
      \}
    \}
    catch(Horde\_Db\_Exception \$e)
    \{
      \# fatal/exit is safe here as we don't care much
      \# about a consistent content database
      \$cli->fatal('Error while removing tags: ' . \$e);
    \}

    \# remove SyncML anchors and maps
    try
    \{
      \$GLOBALS['vprefix'] = \$cli->yellow('[ SyncML  ]');
      \$syncml = Horde\_SyncMl\_Backend::factory('Horde');
      \$devices = \$syncml->getUserAnchors(\$user);
      if (!empty(\$devices))
      \{
        verbose('Removing session...', 'cli.none');
        \$syncml->removeAnchor(\$user);
        \$syncml->removeMaps(\$user);
      \}
    \}
    catch(Horde\_Exception \$e)
    \{
      \# fatal/exit is safe here as we don't care much
      \# about a consistent syncml database
      \$cli->fatal('Error while removing SyncML session: ' . \$e);
    \}

    \# remove ActiveSync devices
    try
    \{
      \$GLOBALS['vprefix'] = \$cli->yellow('[ ActSync ]');
      \$activesync = \$GLOBALS['injector']->getInstance('Horde\_ActiveSyncState');
      \$activesync->setLogger(\$GLOBALS['injector']->getInstance('Horde\_Log\_Logger'));
      \$devices = \$activesync->listDevices(\$user);
      if (!empty(\$devices))
        verbose('Removing devices...', 'cli.none');
      foreach (\$devices as \$device)
        \$activesync->removeState(null, \$device['device\_id'], \$user);
    \}
    catch(Horde\_ActiveSync\_Exception \$e)
    \{
      \# fatal/exit is safe here as we don't care much
      \# about a consistent activesync database
      \$cli->fatal('Error while removing ActiveSync devices: ' . \$e);
    \}

    \# remove history
    try
    \{
      \$GLOBALS['vprefix'] = \$cli->yellow('[ History ]');
      verbose('Removing data...', 'cli.none');
      \$db->delete('DELETE FROM horde\_histories WHERE history\_who = ?', array(\$user));
    \}
    catch(Horde\_Db\_Exception \$e)
    \{
      \# fatal/exit is safe here as we don't care much
      \# about a consistent history database
      \$cli->fatal('Error while removing history: ' . \$e);
    \}

    \# remove user data
    \# NOTE: this will leave/add an delete-entry in horde\_histories
    \# belonging to/referencing the admin user
    try
    \{
      \$GLOBALS['vprefix'] = \$cli->yellow('[ Data ]');
      verbose('Removing user data...', 'cli.none');
      \$GLOBALS['registry']->removeUserData(\$user);
    \}
    catch(Horde\_Exception \$e)
    \{
      \$cli->message('  Error while removing ' . \$user . ': ' . \$e, 'cli.error');
      continue;
    \}

    \# remove history
    try
    \{
      \$GLOBALS['vprefix'] = \$cli->yellow('[ History ]');
      verbose('Removing data...', 'cli.none');
      \$db->delete('DELETE FROM horde\_histories WHERE history\_who = ?', array(\$user));
    \}
    catch(Horde\_Db\_Exception \$e)
    \{
      \# fatal/exit is safe here as we don't care much
      \# about a consistent history database
      \$cli->fatal('Error while removing history: ' . \$e);
    \}

    \# clear horde prefs cache
    \# otherwise the shutdown function will store the default value of all dirty
    \# cache entries (= everything removed during removeUserData(\$user)) again
    try
    \{
      \$GLOBALS['vprefix'] = \$cli->yellow('[ Prefs ]');
      verbose('Clear prefs cache...', 'cli.none');
      \$prefs\_ob = \$GLOBALS['injector']
        ->getInstance('Horde\_Core\_Factory\_Prefs')
        ->create('horde', array(
          'user' => \$user
        ));
    \}
    catch(Horde\_Exception \$e)
    \{
      \$cli->message('  Error while clearing prefs cache: ' . \$e, 'cli.error');
      continue;
    \}

    \# finally remove the user from rampage
    try
    \{
      \# this should be the last as we might recreate the user during deletion
      \$GLOBALS['vprefix'] = \$cli->yellow('[ Content ]');
      verbose(sprintf('Removing user "\%s/\#\%d"...', \$user, \$tUserId), 'cli.none');
      \$usermanager = \$GLOBALS['injector']->getInstance('Content\_Users\_Manager');
      \$meth = new ReflectionMethod(get\_class(\$usermanager), '\_t');
      \$meth->setAccessible(true);
      \$db->delete('DELETE FROM ' . \$meth->invoke(\$usermanager, 'users') . ' WHERE user\_id = ?', array(\$tUserId));
    \}
    catch(Horde\_Db\_Exception \$e)
    \{
      \$cli->message('Error while removing user: ' . \$e, 'cli.error');
      continue;
    \}

    \$cli->message('  ' . \$user . ' removed', 'cli.success');
  \}
\}

\$db->disconnect();

?>
</code></pre>
cleanup\_rampage.php cron

<pre><code class="language-php">
\#!/usr/bin/env php
<?php

require\_once 'PEAR/Config.php';
require\_once PEAR\_Config::singleton()
  ->get('horde\_dir', null, 'pear.horde.org') . '/lib/Application.php';
Horde\_Registry::appInit('horde', array('cli' => true, 'user\_admin' => true));

try
\{
  \$db = \$GLOBALS['injector']->getInstance('Horde\_Core\_Factory\_Db')->create('horde', 'removeUser');
\}
catch(Horde\_Db\_Exception \$e)
\{
  \$cli->fatal('Unable to connect to the database: ' . \$e);
\}

try
\{
  \# delete objects that don't have any tags
  \# this will delete A LOT of objects that still exists
  \# but we've no other way to remove orphans and existing
  \# objects will be created again anyway
  \$db->execute(
    'DELETE FROM ro USING rampage\_objects ro ' .
    'LEFT OUTER JOIN rampage\_tagged rtd ' .
    '  ON (ro.object\_id = rtd.object\_id) ' .
    'WHERE rtd.object\_id IS NULL'
  );
\}
catch (Horde\_Db\_Exception \$e)
\{
  \$cli->fatal('Unable to execute query: ' . \$e);
\}

\$db->disconnect();

?>
</code></pre>

\noindent\rule{\textwidth}{1pt}
January 12th 2009<br />
Another script in PHP using API removeUserData from dom.lalot à gmail.com<br />
Sorry for my poor coding, I'm a Perl programmer not a PHP one. The purpose of this script is to remove data from non existent users. Your auth driver should be able to listusers. The prefs are analyzed to get all current entries by checking uid. Then we compare to the list of all current users.<br />
You have to change the script to get it working. There an exit before doing the bad job.

Save you data if you have some fears.

<pre><code>
\#!/usr/bin/env php
<?php
@define('AUTH\_HANDLER', true);
@define('HORDE\_BASE', dirname(\_\_FILE\_\_));
\# require\_once HORDE\_BASE . '/lib/base.php';
// Do CLI checks and environment setup first.
require\_once HORDE\_BASE . '/lib/core.php';
require\_once 'Horde/CLI.php';
// Make sure no one runs this from the web.
if (!Horde\_CLI::runningFromCLI()) \{
    exit("Must be run from the command line\textbackslash\{\}n");
\}
// Load the CLI environment - make sure there's no time limit, init some
// variables, etc.
\$cli = \&Horde\_CLI::singleton();
\$cli->init();
// Include needed libraries.
require\_once HORDE\_BASE . '/lib/base.php';
// Authenticate as administrator.
if (!count(\$conf['auth']['admins'])) \{
    exit("You must have at least one administrator configured to run the alarms.php script.\textbackslash\{\}n");
\}
\$auth = \&Auth::singleton(\$conf['auth']['driver']);
\$auth->setAuth(\$conf['auth']['admins'][0], array());
require\_once HORDE\_BASE . '/lib/Horde/Auth.php';
global \$conf;
require\_once 'DB.php';
\$db = \&DB::connect(\$conf['sql']);
if (is\_a(\$db, 'PEAR\_Error')) \{
    Horde::fatal(\$db, \_\_FILE\_\_, \_\_LINE\_\_);
\}
\$validusers=\$auth->listUsers();
\$valides=count(\$validusers);
if (\$valides==0)\{
   echo "Can't list users, your auth driver has no listusers capability\textbackslash\{\}n";
   exit;
\}
echo "\$valides valid users found\textbackslash\{\}n";
\$valides=array();
foreach(\$validusers as \$value)\{
   \$valides[\$value]=1;
\}
// Looking at prefs to get most of old user data
\$db->setOption('portability', DB\_PORTABILITY\_LOWERCASE | DB\_PORTABILITY\_ERRORS);
\$result = \$db->query('SELECT pref\_uid FROM horde\_prefs WHERE 1');
if (is\_a(\$result, 'PEAR\_Error')) \{
   \$cli->message(\$result->toString(), 'cli.error');
   exit;
\}

\$uid = array();
while (\$row = \$result->fetchRow(DB\_FETCHMODE\_ASSOC)) \{
   \$login=\$row['pref\_uid'];
    \$uid[\$login] = \$login;
\}
\$total=count(\$uid);
echo "\$total data user found\textbackslash\{\}n";
echo "Exit without removing data, change the script please\textbackslash\{\}n";
exit; \# Drop this line if you want to remove data

//now compare valid and data found and purge
foreach (\$uid as \$value) \{
   if (!array\_key\_exists(\$value,\$valides))\{
      echo "Not Found \$value\textbackslash\{\}n";
      Auth::removeUserData(\$value);
      \$supp++;
   \}
\}
echo "suppressed \$supp\textbackslash\{\}n";
?>
</code></pre>
\section{Here is a  database cleanup script that was first  posted on the Horde list by Jacques Beaudoin <<a href="https://wiki.horde.org/mailto:jacques-beaudoin@cspi.qc.ca">jacques-beaudoin@cspi.qc.ca</a>>}
I changed it a little.<br />
It really should be PHP-ized and get the database information from the configs<br />
I think it needs the history database in it - for horde 3.1 and later


\noindent\rule{\textwidth}{1pt}
--------- hordedel

<pre><code>
\#!/bin/bash
\#
\#  Origional From Beaudoin <jacques-beaudoin@cspi.qc.ca>
\# made it a little more flexible  Bill Graham <grahamcw@hurleybulldogs.com>
\#
\# hordedel 
\#  cleanup of horde databases after user deletion.
\#
\#  Exemple usage  hordedel "useridname""
\#

USER="\$1"
\# horde database
DB="yourhordedatabase"
\# horde mysql userid
SQLUSER="yourhordeuserid"
\# horde mysql passwd
SQLPWD="yourdatabasepassword"

\#
\#  Count records before delete
\#
HP\_B=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.horde\_prefs WHERE pref\_uid='\$USER'"`
KE\_B=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.kronolith\_events WHERE calendar\_id='\$USER'"`
MM\_B=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.mnemo\_memos WHERE memo\_owner='\$USER'"`
TO\_B=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.turba\_objects WHERE owner\_id='\$USER'"`
NT\_B=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.nag\_tasks WHERE task\_owner='\$USER'"`
HD\_B=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.horde\_datatree WHERE user\_uid='\$USER'"`
HDA\_B=0
COUNT=0
mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT datatree\_id from \$DB.horde\_datatree WHERE user\_uid='\$USER'" > /tmp/01
while read I
do
  COUNT=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.horde\_datatree\_attributes WHERE datatree\_id='\$I'"`
  HDA\_B=`expr \$HDA\_B + \$COUNT`
done  </tmp/01

\#
\#  Delete records (Comments out these lines for testing)
\#
mysql -s -u \$SQLUSER --password=\$SQLPWD -e "DELETE from \$DB.horde\_prefs WHERE pref\_uid='\$USER'"
mysql -s -u \$SQLUSER --password=\$SQLPWD -e "DELETE from \$DB.kronolith\_events WHERE calendar\_id='\$USER'" 
mysql -s -u \$SQLUSER --password=\$SQLPWD -e "DELETE from \$DB.mnemo\_memos WHERE memo\_owner='\$USER'"
mysql -s -u \$SQLUSER --password=\$SQLPWD -e "DELETE from \$DB.turba\_objects WHERE owner\_id='\$USER'"
mysql -s -u \$SQLUSER --password=\$SQLPWD -e "DELETE from \$DB.nag\_tasks WHERE task\_owner='\$USER'"
mysql -s -u \$SQLUSER --password=\$SQLPWD -e "DELETE from \$DB.horde\_datatree WHERE user\_uid='\$USER'"
while read I
do
  mysql -s -u \$SQLUSER --password=\$SQLPWD -e "DELETE from \$DB.horde\_datatree\_attributes WHERE datatree\_id='\$I'"
done</tmp/01

\#
\#  Count records after delete (Should always give zero)
\#
HP\_A=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.horde\_prefs WHERE pref\_uid='\$USER'"`
KE\_A=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.kronolith\_events WHERE calendar\_id='\$USER'"`
MM\_A=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.mnemo\_memos WHERE memo\_owner='\$USER'"`
TO\_A=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.turba\_objects WHERE owner\_id='\$USER'"`
NT\_A=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.nag\_tasks WHERE task\_owner='\$USER'"`
HD\_A=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.horde\_datatree WHERE user\_uid='\$USER'"`
HDA\_A=0
COUNT=0
mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT datatree\_id from \$DB.horde\_datatree WHERE user\_uid='\$USER'" > /tmp/01
while read I
do
  COUNT=`mysql -s -u \$SQLUSER --password=\$SQLPWD -e "SELECT count(*) from \$DB.horde\_datatree\_attributes WHERE datatree\_id='\$I'"`
  HDA\_A=`expr \$HDA\_A + \$COUNT`
done</tmp/01

\#
\#  Display tables record counts after delete operation
\#
echo "Before and after records count for user \$USER'"
echo "==========================================================================="
echo "horde\_prefs: \$HP\_B / \$HP\_A"
echo "kronolith\_events: \$KE\_B / \$KE\_A"
echo "mnemo\_memos: \$MM\_B / \$MM\_A"
echo "turba\_objects: \$TO\_B / \$TO\_A"
echo "nag\_tasks: \$NT\_B / \$NT\_A"
echo "horde\_datatree: \$HD\_B / \$HD\_A"
echo "horde\_datatree\_attributes: \$HDA\_B / \$HDA\_A"

exit 0
</code></pre>

\noindent\rule{\textwidth}{1pt}
---- modified hordel

<pre><code>
\#!/bin/bash
\#
\# Cleanup of horde databases after user deletion from ldap
\#
\# Origional From Beaudoin <jacques-beaudoin@cspi.qc.ca>
\# made it a little more flexible  Bill Graham <grahamcw@hurleybulldogs.com>
\# H4 patch by Greg Pascal <ngombe at gmail dot com>
\#

if [ \$\# = 2 ]
 then

	USER="\$2"

	\# \# \# \# \# \# \# \# \#
	\# Global config \#
	\# \# \# \# \# \# \# \# \#

	\# horde database
	DB="horde\_4"
	\# horde mysql userid
	\_USER="mysql\_user"
	\# horde mysql passwd
	\_PWD="mysql\_user\_passwd"
	\# horde mysql host
	\_HOST="localhost"
	\# horde mysql port 
	\_PORT="3306"

	\# \# \# \# \# \# \# \# \#
	\# Count records \#
	\# \# \# \# \# \# \# \# \#

	\#\# imp
	IM\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.imp\_sentmail WHERE sentmail\_who='\$USER'"`

	\#\# ingo
	IF\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.ingo\_forwards WHERE forward\_owner='\$USER'"`
	IL\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.ingo\_lists WHERE list\_owner='\$USER'"`
	IR\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.ingo\_rules WHERE rule\_owner='\$USER'"`
	IS\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.ingo\_shares WHERE share\_owner='\$USER'"`
	II\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.ingo\_shares\_users WHERE user\_uid='\$USER'"`
	IN\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.ingo\_sharesng WHERE share\_owner='\$USER'"`
	IU\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.ingo\_sharesng\_users WHERE user\_uid='\$USER'"`
	IP\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.ingo\_spam WHERE spam\_owner='\$USER'"`
	IV\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.ingo\_vacations WHERE vacation\_owner='\$USER'"`

	\#\# kronolith
	KE\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.kronolith\_events WHERE calendar\_id='\$USER'"`
	KS\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.kronolith\_shares WHERE share\_owner='\$USER'"`
	KI\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.kronolith\_shares\_users WHERE user\_uid='\$USER'"`
	KN\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.kronolith\_sharesng WHERE share\_owner='\$USER'"`
	KU\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.kronolith\_sharesng\_users WHERE user\_uid='\$USER'"`
	KT\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.kronolith\_storage WHERE vfb\_owner='\$USER'"`

	\#\# mnemo
	MM\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.mnemo\_memos WHERE memo\_owner='\$USER'"`
	MS\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.mnemo\_shares WHERE share\_owner='\$USER'"`
	MI\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.mnemo\_shares\_users WHERE user\_uid='\$USER'"`
	MN\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.mnemo\_sharesng WHERE share\_owner='\$USER'"`
	MU\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.mnemo\_sharesng\_users WHERE user\_uid='\$USER'"`

	\#\# nag
	NT\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.nag\_tasks WHERE task\_owner='\$USER'"`
	NS\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.nag\_shares WHERE share\_owner='\$USER'"`
	NI\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.nag\_shares\_users WHERE user\_uid='\$USER'"`
	NN\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.nag\_sharesng WHERE share\_owner='\$USER'"`
	NU\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.nag\_sharesng\_users WHERE user\_uid='\$USER'"`

	\#\# turba
	TO\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.turba\_objects WHERE owner\_id='\$USER'"`
	TS\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.turba\_shares WHERE share\_owner='\$USER'"`
	TI\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.turba\_shares\_users WHERE user\_uid='\$USER'"`
	TN\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.turba\_sharesng WHERE share\_owner='\$USER'"`
	TU\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.turba\_sharesng\_users WHERE user\_uid='\$USER'"`

	\#\# rampage
	RU\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.rampage\_users WHERE user\_name='\$USER'"`
	USER\_ID=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT user\_id from \$DB.rampage\_users WHERE user\_name='\$USER'"`
	RT\_B=0
	RO\_B=0
	COUNT=0
	if [ \$USER\_ID ]
	then
		RT\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(tag\_id) from \$DB.rampage\_tagged WHERE user\_id='\$USER\_ID'"`
		RO\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(DISTINCT object\_id) from \$DB.rampage\_tagged WHERE user\_id='\$USER\_ID'"`
	fi

	\#\# Horde
	HA\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.horde\_alarms WHERE alarm\_uid='\$USER'"`
	HM\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.horde\_muvfs WHERE vfs\_owner='\$USER'"`
	HV\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.horde\_vfs WHERE vfs\_owner='\$USER'"`
	HY\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.horde\_syncml\_anchors WHERE syncml\_uid='\$USER'"`
	HZ\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.horde\_syncml\_map WHERE syncml\_uid='\$USER'"`
	HG\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.horde\_groups\_members WHERE user\_uid='\$USER'"`
	HP\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.horde\_prefs WHERE pref\_uid='\$USER'"`
	HS\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.horde\_histories WHERE history\_who='\$USER'"`
	HL\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.horde\_locks WHERE lock\_owner='\$USER'"`
	AM\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.horde\_activesync\_map WHERE sync\_user='\$USER'"`
	AS\_B=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.horde\_activesync\_device\_users WHERE device\_user='\$USER'"`

	ASD\_B=0
	ASS\_B=0
	COUNT=0
	mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT device\_id from \$DB.horde\_activesync\_device\_users WHERE device\_user='\$USER'" > /tmp/01
	while read I
	do
	  COUNT=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.horde\_activesync\_device WHERE device\_id='\$I'"`
	  ASD\_B=`expr \$ASD\_B + \$COUNT`
	  COUNT=`mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT count(*) from \$DB.horde\_activesync\_state WHERE sync\_devid='\$I'"`
	  ASS\_B=`expr \$ASS\_B + \$COUNT`
	done</tmp/01

	\# \# \# \# \# \# \# \# \# \# \# \# \#
	\# Display records count \#
	\# \# \# \# \# \# \# \# \# \# \# \# \#

	echo "====================================================="
	echo " Records informations for user '\$USER'"
	echo "====================================================="

	echo "horde\_prefs: \$HP\_B"
	echo "horde\_groups\_members: \$HG\_B"
	echo "horde\_histories: \$HS\_B"
	echo "horde\_locks: \$HL\_B"
	echo "horde\_alarms: \$HA\_B"
	echo "horde\_vfs: \$HV\_B"
	echo "horde\_muvfs: \$HM\_B"
	echo "horde\_syncml\_anchors: \$HY\_B"
	echo "horde\_syncml\_map: \$HZ\_B"
	echo "horde\_activesync\_device\_users: \$AS\_B"
	echo "horde\_activesync\_device: \$ASD\_B"
	echo "horde\_activesync\_map: \$AM\_B"
	echo "horde\_activesync\_state: \$ASS\_B"

	echo "rampage\_users: \$RU\_B"
	echo "rampage\_tagged: \$RT\_B"
	echo "rampage\_object: \$RO\_B"

	echo "imp\_sentmail: \$IM\_B"

	echo "ingo\_forwards: \$IF\_B"
	echo "ingo\_spam: \$IP\_B"
	echo "ingo\_vacations: \$IV\_B"
	echo "ingo\_lists: \$IL\_B"
	echo "ingo\_rules: \$IR\_B"
	echo "ingo\_shares: \$IS\_B"
	echo "ingo\_shares\_users: \$II\_B"
	echo "ingo\_sharesng: \$IN\_B"
	echo "ingo\_sharesng\_users: \$IU\_B"

	echo "kronolith\_events: \$KE\_B"
	echo "kronolith\_shares: \$KS\_B"
	echo "kronolith\_shares\_user: \$KI\_B"
	echo "kronolith\_sharesng: \$KN\_B"
	echo "kronolith\_sharesng\_users: \$KU\_B"
	echo "kronolith\_storage: \$KT\_B"

	echo "mnemo\_memos: \$MM\_B"
	echo "mnemo\_shares: \$MS\_B"
	echo "mnemo\_shares\_users: \$MI\_B"
	echo "mnemo\_sharesng: \$MN\_B"
	echo "mnemo\_sharesng\_users: \$MU\_B"

	echo "nag\_tasks: \$NT\_B"
	echo "nag\_shares: \$NS\_B"
	echo "nag\_shares\_users: \$NI\_B"
	echo "nag\_sharesng: \$NN\_B"
	echo "nag\_sharesng\_users: \$NU\_B"

	echo "turba\_objects: \$TO\_B"
	echo "turba\_shares: \$TS\_B"
	echo "turba\_shares\_users: \$TI\_B"
	echo "turba\_sharesng: \$TN\_B"
	echo "turba\_sharesng\_users: \$TU\_B"

	echo "====================================================="

	if [ \$1 = "remove" ]
	 then

		\# \# \# \# \# \# \# \# \# \#
		\#  Delete records \#
		\# \# \# \# \# \# \# \# \# \#

		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.imp\_sentmail WHERE sentmail\_who='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.ingo\_forwards WHERE forward\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.ingo\_lists WHERE list\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.ingo\_rules WHERE rule\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.ingo\_shares WHERE share\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.ingo\_shares\_users WHERE user\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.ingo\_sharesng WHERE share\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.ingo\_sharesng\_users WHERE user\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.ingo\_spam WHERE spam\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.ingo\_vacations WHERE vacation\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.kronolith\_events WHERE calendar\_id='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.kronolith\_shares WHERE share\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.kronolith\_shares\_users WHERE user\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.kronolith\_sharesng WHERE share\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.kronolith\_sharesng\_users WHERE user\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.kronolith\_storage WHERE vfb\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.mnemo\_memos WHERE memo\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.mnemo\_shares WHERE share\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.mnemo\_shares\_users WHERE user\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.mnemo\_sharesng WHERE share\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.mnemo\_sharesng\_users WHERE user\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.nag\_tasks WHERE task\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.nag\_shares WHERE share\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.nag\_shares\_users WHERE user\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.nag\_sharesng WHERE share\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.nag\_sharesng\_users WHERE user\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.turba\_objects WHERE owner\_id='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.turba\_shares WHERE share\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.turba\_shares\_users WHERE user\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.turba\_sharesng WHERE share\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.turba\_sharesng\_users WHERE user\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.horde\_alarms WHERE alarm\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.horde\_muvfs WHERE vfs\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.horde\_vfs WHERE vfs\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.horde\_syncml\_anchors WHERE syncml\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.horde\_syncml\_map WHERE syncml\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.horde\_groups\_members WHERE user\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.horde\_prefs WHERE pref\_uid='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.horde\_histories WHERE history\_who='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.horde\_locks WHERE lock\_owner='\$USER'"
		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.horde\_activesync\_map WHERE sync\_user='\$USER'"

		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT device\_id from \$DB.horde\_activesync\_device\_users WHERE device\_user='\$USER'" > /tmp/01
		while read I
		do
		  mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.horde\_activesync\_device WHERE device\_id='\$I'"
		  mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.horde\_activesync\_state WHERE sync\_devid='\$I'"
		done</tmp/01

		mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.horde\_activesync\_device\_users WHERE device\_user='\$USER'"

		if [ \$USER\_ID ]
		then
			mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "SELECT DISTINCT object\_id FROM \$DB.rampage\_tagged WHERE user\_id='\$USER\_ID'" > /tmp/01
			while read I
			do
			  mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.rampage\_objects WHERE object\_id='\$I'"
			done</tmp/01
			mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.rampage\_tagged WHERE user\_id='\$USER\_ID'"
			mysql -s -u \$\_USER --password=\$\_PWD --host=\$\_HOST --port=\$\_PORT -e "DELETE from \$DB.rampage\_users WHERE user\_name='\$USER'"
		fi

		echo "Datas removed from \$DB@\$\_HOST:\$\_PORT ...";

	fi

else
	echo "Syntaxe : \$0 [test|remove] [uid]";
fi

exit 0
</code></pre>
\end{document}
