File: create_missing_add_histories_sql.php

package info (click to toggle)
nag2 2.3.4%2Bdebian0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 6,256 kB
  • ctags: 1,719
  • sloc: php: 6,797; xml: 589; sql: 335; makefile: 75; sh: 26
file content (61 lines) | stat: -rwxr-xr-x 1,849 bytes parent folder | download
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
#!/usr/bin/php
<?php
/**
 * $Horde: nag/scripts/upgrades/create_missing_add_histories_sql.php,v 1.8.2.3 2009-01-06 15:25:09 jan Exp $
 *
 * Copyright 2005-2009 The Horde Project (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
 *
 * @author Chuck Hagenbuch <chuck@horde.org>
 */

@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.
$cli = &Horde_CLI::singleton();
$cli->init();

@define('NAG_BASE', dirname(__FILE__) . '/../..');
require_once NAG_BASE . '/lib/base.php';

$history = &Horde_History::singleton();

// Run through every tasklist.
$tasklists = $nag_shares->listAllShares();
foreach ($tasklists as $tasklist => $share) {
    echo "Creating default histories for $tasklist ...\n";

    // List all tasks.
    $storage = Nag_Driver::singleton($tasklist);
    $storage->retrieve();
    $tasks = $storage->listTasks();

    foreach ($tasks as $taskId => $task) {
        $log = $history->getHistory('nag:' . $tasklist . ':' . $task['uid']);
        $created = false;
        foreach ($log->getData() as $entry) {
            if ($entry['action'] == 'add') {
                $created = true;
                break;
            }
        }
        if (!$created) {
            $history->log('nag:' . $tasklist . ':' . $task['uid'], array('action' => 'add'), true);
        }
    }
}

echo "\n** Default histories successfully created ***\n";