6.0.0-beta13
4/12/26
  • 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.

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 = '';
$cli->writeln('Remove user data of ' . $value);
$registry->removeUserData($value);

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

++ Using the removeUserData APIs

From dom.lalot at gmail com

#!/usr/bin/env php 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.\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\n"; exit; } echo "$valides valid users found\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\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";
Auth::removeUserData($value);
$supp++;
}
}
echo "suppressed $supp\n";
?>