Last Modified 2014-01-03 by Guest

Removing User Data

Starting with version 5.1.5, Horde includes a horde-remove-user-data script that can be run on the command line.

Modifying the default script to remove interactivity

You may want to call the horde-remove-user-data script from another script, providing a user to delete as an argument.
In order to do this, you need to use a modified version of the script.

#!/usr/bin/env 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

$app = null;


try {
    $registry->removeUserData($user, $app);
    $cli->message('Data removed.', 'cli.success');
} catch (Horde_Exception $e) {

You would call the script like this:
horde-remove-user-data user@domain.com

The examples below are for older Horde versions.

Using the removeUserData APIs of Horde 5

#!/usr/bin/env 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);

// remove users on command line
for($i = 1; $i < $argc; ++$i) {
    $value = $argv[$i];
    $cli->writeln('Remove user data of ' . $value);

Using the removeUserData APIs

From dom.lalot at gmail com

#!/usr/bin/env 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\n");
// Load the CLI environment - make sure there's no time limit, init some
// variables, etc.
$cli = &Horde_CLI::singleton();
// 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.\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__);
if ($valides==0){
   echo "Can't list users, your auth driver has no listusers capability\n";
echo "$valides valid users found\n";
foreach($validusers as $value){
// Looking at prefs to get most of old user data
$result = $db->query('SELECT pref_uid FROM horde_prefs WHERE 1');
if (is_a($result, 'PEAR_Error')) {
   $cli->message($result->toString(), 'cli.error');

$uid = array();
while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
    $uid[$login] = $login;
echo "$total data user found\n";
echo "Exit without removing data, change the script please\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\n";
echo "suppressed $supp\n";