/dev/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/dev/trunk

« back to all changes in this revision

Viewing changes to system/cache.php

  • Committer: Suren A. Chilingaryan
  • Date: 2008-04-02 10:23:22 UTC
  • Revision ID: csa@dside.dyndns.org-20080402102322-okib92sicg2dx3o3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
$config = array (
 
4
    "db_server" => "katrin", 
 
5
    "db_name" => "hauptspektrometer"
 
6
);
 
7
*/
 
8
 
 
9
/*
 
10
function signal_handler($signal) {
 
11
    profilerDisplay();
 
12
    exit;
 
13
}
 
14
declare(ticks = 1);
 
15
pcntl_signal(SIGINT, "signal_handler");
 
16
*/
 
17
 
 
18
$res = exec('ps xa | grep "cache.php" | grep -v grep | wc -l');
 
19
if ($res > 1) exit;
 
20
 
 
21
if (preg_match("/(.*)cache.php$/", $_SERVER['SCRIPT_FILENAME'], $m)) @chdir($m[1]);
 
22
 
 
23
require("../adei.php");
 
24
 
 
25
function ROOTCache(&$cache, $rootdb, $app, $inq_app, $rootdb_name) {
 
26
    try {
 
27
 
 
28
        $desc = array(
 
29
            0 => array("pipe", "r"),
 
30
            1 => array("pipe", "w"),
 
31
            2 => array("pipe", "w")
 
32
        );
 
33
 
 
34
        $cmd = proc_open($inq_app, $desc, $pipes);
 
35
        if ($cmd) {
 
36
            if ($rootdb) {
 
37
                fwrite($pipes[0], $rootdb['user'] . "\n");
 
38
                fwrite($pipes[0], $rootdb['password'] . "\n");
 
39
            }
 
40
            fclose($pipes[0]);
 
41
 
 
42
            $start = stream_get_contents($pipes[1]);
 
43
            fclose($pipes[1]);
 
44
            
 
45
            $errors = stream_get_contents($pipes[2]);
 
46
            $ret = proc_close($cmd);
 
47
            if ($ret) throw new ADEIException("Execution of csv2root is finished with error code $ret");
 
48
 
 
49
        } else throw new ADEIException("Execution of csv2root is failed");
 
50
        
 
51
        if ($start < 0) $start = 0;
 
52
 
 
53
        $ivl = $cache->CreateInterval();
 
54
        $ivl->Limit($start);
 
55
 
 
56
        $cmd = popen($app, "w");
 
57
        if ($rootdb) {
 
58
            fwrite($cmd, $rootdb['user'] . "\n");
 
59
            fwrite($cmd, $rootdb['password'] . "\n");
 
60
        }
 
61
        $cache->ExportCSV(new DATAStreamHandler($cmd), $mask = NULL, $ivl);
 
62
        if ($err = pclose($cmd)) throw new ADEIException("csv2root is finished with error: $err");
 
63
    } catch(ADEIException $e) {
 
64
        echo "Problem processing ROOT database \"" . $rootdb_name . "\": " .  $e->getMessage() . "\n";
 
65
    }
 
66
}
 
67
 
 
68
function DoCache(&$req) {
 
69
    global $ROOT_DB;
 
70
 
 
71
    try {
 
72
        $reader = $req->CreateReader(REQUEST::READER_FORBID_CACHEREADER);
 
73
    } catch(ADEIException $e) {
 
74
        return $req->GetLocationString() . ", Error: " . $e->getMessage();
 
75
    }
 
76
 
 
77
    try {
 
78
        $opts = &$req->GetOptions();
 
79
        $rootdb = $opts->Get('root_database');
 
80
 
 
81
        $list = $req->GetGroupList($reader);
 
82
    } catch(ADEIException $e) {
 
83
        return $req->GetLocationString() . ", Error: " . $e->getMessage();
 
84
    }
 
85
 
 
86
    if ($rootdb) {
 
87
        if (strchr($rootdb, "/")) {
 
88
            $db_info = false;
 
89
            $inq_app = adei_app("csv2root", "--file " . $rootdb . " --inquiry-latest-data", true);
 
90
            $app = adei_app("csv2root", "--file " . $rootdb, true);
 
91
        } else {
 
92
            try {
 
93
                $db_info = $ROOT_DB;
 
94
                $db_info['database'] = $rootdb;
 
95
                $database = new DATABASE($db_info);
 
96
            } catch (ADEIException $e) {
 
97
                unset($db_info['database']);
 
98
                try {
 
99
                    $database = new DATABASE($ROOT_DB);
 
100
                    $database->CreateDatabase($rootdb);
 
101
                } catch(ADEIException $e) {
 
102
                    echo "Problem accessing ROOT database \"$rootdb\": " .  $e->getMessage() . "\n";
 
103
                    $rootdb = false;
 
104
                }
 
105
            }
 
106
 
 
107
            if ($rootdb) {
 
108
                $conprm = $db_info['driver'] . "://" . $db_info['host'] . ($db_info['port']?(":" . $db_info['port']):"") . "/" . $rootdb;
 
109
                $inq_app = adei_app("csv2root", "--db " . $conprm . " --inquiry-latest-data", true);
 
110
                $app = adei_app("csv2root", "--db " . $conprm, true);
 
111
            }
 
112
        }
 
113
        if ($rootdb) {
 
114
            if ((!$app)||(!$inq_app)) {
 
115
                echo("csv2root is not present");
 
116
                $rootdb = false;
 
117
            } else {
 
118
                $groups = $reader->GetGroupList(READER::NEED_INFO);
 
119
            }
 
120
        }
 
121
    }
 
122
 
 
123
    foreach ($list as $gid => $greq) {
 
124
        try {
 
125
            $cache = $greq->CreateCacheUpdater($reader);
 
126
            $cache->Update();
 
127
            if ($rootdb) {
 
128
                $grname = " --group " . $groups[$gid]["name"];
 
129
//              ROOTCache($cache, $db_info, $app . $grname, $inq_app . $grname, $conprm?$conprm:$rootdb);
 
130
            }
 
131
        } catch(ADEIException $e) {
 
132
            return $greq->GetLocationString() . ", Error: " . $e->getMessage();
 
133
        }
 
134
    }
 
135
    
 
136
    return 0;
 
137
}
 
138
 
 
139
$req = new REQUEST($config);
 
140
$list = $req->GetSourceList();
 
141
 
 
142
foreach ($list as $sreq) {
 
143
    $err = DoCache($sreq);
 
144
    if ($err) echo "$err\n\n\n";
 
145
}
 
146
?>
 
 
b'\\ No newline at end of file'