1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
#!/usr/bin/php -q
<?php
/**
* $Horde: horde/scripts/migrate_user_categories.php,v 1.5 2004/09/23 01:41:11 chuck Exp $
*
* A script to update users preferences to combine their categories
* and category colors from Genie, Kronolith, Mnemo, and Nag into the
* new Horde-wide preferences. Expects to be given a list of users on
* STDIN, one username per line, to convert. Usernames need to match
* the values stored in the preferences backend.
*/
// Find the base file path of Horde.
@define('AUTH_HANDLER', true);
@define('HORDE_BASE', dirname(__FILE__) . '/..');
// 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.
Horde_CLI::init();
require_once HORDE_BASE . '/lib/base.php';
require_once 'Horde/Prefs/CategoryManager.php';
$cli = &Horde_CLI::singleton();
$auth = &Auth::singleton($conf['auth']['driver']);
$cManager = &new Prefs_CategoryManager();
$apps = $registry->listApps(array('hidden', 'notoolbar', 'active', 'admin'));
// Read in the list of usernames on STDIN.
$users = array();
while ($line = fgets(STDIN, 4096)) {
$line = trim($line);
if (!empty($line)) {
$users[] = $line;
}
}
// Loop through users and convert prefs for Genie, Mnemo, Nag, and
// Kronolith.
foreach ($users as $user) {
echo 'Migrating prefs for ' . $cli->bold($user);
// Set $user as the current user.
$auth->setAuth($user, array(), '');
// Fetch current categories and colors.
$colors = $cManager->colors();
// Genie.
if (in_array('genie', $apps)) {
echo ' . genie';
$result = $registry->pushApp('genie', false);
if (!is_a($result, 'PEAR_Error')) {
$g_categories = listCategories('wish_categories');
foreach ($g_categories as $category) {
$cManager->add($category);
}
}
}
// Mnemo.
if (in_array('mnemo', $apps)) {
echo ' . mnemo';
$result = $registry->pushApp('mnemo', false);
if (!is_a($result, 'PEAR_Error')) {
$m_categories = listCategories('memo_categories');
$m_colors = listColors('memo_colors');
foreach ($m_categories as $key => $category) {
if (isset($m_colors[$key])) {
$colors[$category] = $m_colors[$key];
}
$cManager->add($category);
}
}
}
// Nag.
if (in_array('nag', $apps)) {
echo ' . nag';
$result = $registry->pushApp('nag', false);
if (!is_a($result, 'PEAR_Error')) {
$n_categories = listCategories('task_categories');
foreach ($n_categories as $category) {
$cManager->add($category);
}
}
}
// Kronolith.
if (in_array('kronolith', $apps)) {
echo ' . kronolith';
$result = $registry->pushApp('kronolith', false);
if (!is_a($result, 'PEAR_Error')) {
$k_categories = listCategories('event_categories');
$k_colors = listColors('event_colors');
foreach ($k_categories as $key => $category) {
if (isset($k_colors[$key])) {
$colors[$category] = $k_colors[$key];
}
$cManager->add($category);
}
}
}
$cManager->setColors($colors);
$prefs->store();
$cli->writeln();
}
$cli->writeln();
$cli->writeln($cli->green('DONE'));
exit;
function listCategories($prefname)
{
global $prefs;
$string = $prefs->getValue($prefname);
if (empty($string)) {
return array();
}
$cats = explode('|', $string);
foreach ($cats as $cat) {
list($key, $val) = explode(':', $cat);
$categories[$key] = $val;
}
return $categories;
}
function listColors($prefname)
{
global $prefs;
$string = $prefs->getValue($prefname);
$cols = explode('|', $string);
$colors = array();
foreach ($cols as $col) {
list($key, $val) = explode(':', $col);
$colors[$key] = $val;
}
return $colors;
}
|