File: convert_vfolders.php

package info (click to toggle)
imp4 4.2-4lenny3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,252 kB
  • ctags: 5,316
  • sloc: php: 21,340; xml: 19,302; makefile: 68; sql: 14
file content (81 lines) | stat: -rwxr-xr-x 2,115 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/php -q
<?php
/**
 * $Horde: imp/scripts/upgrades/convert_vfolders.php,v 1.1.2.1 2007/12/20 14:00:36 jan Exp $
 *
 * A script to update Virtual Folders from IMP 4.0.x format to IMP 4.1+
 * format. 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('IMP_BASE', dirname(__FILE__) . '/../..');

// Do CLI checks and environment setup first.
require_once IMP_BASE . '/lib/base.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();

$cli = &Horde_CLI::singleton();
$auth = &Auth::singleton($conf['auth']['driver']);

// Read in the list of usernames on STDIN.
$users = array();
while (!feof(STDIN)) {
    $line = fgets(STDIN);
    $line = trim($line);
    if (!empty($line)) {
        $users[] = $line;
    }
}

// Loop through users.
foreach ($users as $user) {
    echo 'Converting Virtual Folders for ' . $cli->bold($user);

    // Set $user as the current user.
    $auth->setAuth($user, array(), '');

    $vfolder = $imp_search->_getVFolderList();
    if (empty($vfolder)) {
        $cli->writeln();
        continue;
    }

    $elt = reset($vfolder);
    if (!isset($elt['ob'])) {
        // Already in 4.1+ format.
        $cli->writeln();
        continue;
    }

    // Convert from 4.0 format to 4.1+ format
    $convert = array();
    foreach ($vfolder as $key => $val) {
        $convert[$key] = array(
            'query' => $val['ob'],
            'folders' => $val['search']['folders'],
            'uiinfo' => $val['search'],
            'label' => $val['search']['vfolder_label'],
            'vfolder' => true
        );
    }

    $imp_search->_saveVFolderList($convert);
    $prefs->store();
    $cli->writeln();
}

$cli->writeln();
$cli->writeln($cli->green('DONE'));
exit;