\documentclass{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{hyperref}
\pagestyle{headings}
\begin{document}
\part{Removing User Data}
Starting with version 5.1.5, Horde includes a \texttt{horde-remove-user-data} script that can be run on the command line.

\section{Modifying the default script to remove interactivity}
You may want to call the \texttt{horde-remove-user-data} script from another script, providing a user to delete as an argument.<br />
In order to do this, you need to use a modified version of the script.

<pre><code>\#!/usr/bin/env php
<?php
/**
 * This script will delete all user data for a given user.
 *
 * Copyright 2013 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (LGPL-2). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl.
 *
 * @author    Michael Slusarz <slusarz@horde.org>
 * @category  Horde
 * @copyright 2013 Horde LLC
 * @license   http://www.horde.org/licenses/lgpl LGPL-2
 * @package   Horde
 */

\$baseFile = \_\_DIR\_\_ . '/../lib/Application.php';
if (file\_exists(\$baseFile)) \{
    require\_once \$baseFile;
\} else \{
    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(
    'authentication' => 'none',
    'cli' => true,
    'user\_admin' => true
));

\$config=getopt("u");
\$user=\$config["u"];
\$app = null;

\$cli->writeln();

try \{
    \$registry->removeUserData(\$user, \$app);
    \$cli->message('Data removed.', 'cli.success');
\} catch (Horde\_Exception \$e) \{
    \$cli->fatal(\$e->getMessage());
\}
</code></pre>
You would call the script like this:<br />
\texttt{horde-remove-user-data user@domain.com}

The examples below are for older Horde versions.

\section{Using the removeUserData APIs of Horde 5}
<pre><code>\#!/usr/bin/env php
<?php

if (file\_exists(\_\_DIR\_\_ . '/../lib/Application.php')) \{
    \$baseDir = \_\_DIR\_\_;
\} else \{
    require\_once 'PEAR/Config.php';
    \$baseDir = PEAR\_Config::singleton()
        ->get('horde\_dir', null, 'pear.horde.org') . '/kronolith/';
\}
require\_once  \$baseDir . '/lib/Application.php';

Horde\_Registry::appInit('horde', array('cli' => true, 'user\_admin' => true));

/* remove single user
\$value = '<user>';
\$cli->writeln('Remove user data of ' . \$value);
\$registry->removeUserData(\$value);*/

// remove users on command line
for(\$i = 1; \$i < \$argc; ++\$i) \{
	\$value = \$argv[\$i];
	\$cli->writeln('Remove user data of ' . \$value);
	\$registry->removeUserData(\$value);
\}
</code></pre>
\section{Using the removeUserData APIs}
From dom.lalot at gmail com

<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>
\end{document}
