/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
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
<?php

header("Content-type: text/xml");
header("Cache-Control: no-cache, must-revalidate");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

class COMPARE {
  const EXTRA_ITEMS = 1;                // Fully OK, items added
  const MISSING_ITEMS = 2;              // OK. No problems if it is not mistake
  const EXTRA_UID = 4;                  // OK. We may have better description in the new archive.
  const MISSING_UID = 8;                // Probably not OK. I don't expect there is reason to drop uids. But report a error if names does not match.
  const UID_MISTMATCH = 16;             // Not OK.
  const NAME_MISTMATCH = 32;            // Probably OK, we may have renames if uids match.
  const MISSING_UID_NAME_MATCH = 64;    // OK?
  const MISSING_UID_NAME_MISTMATCH = 128;// Not OK
    
  var $code;
  
  function __construct($code) {
    $this->code = $code;
  }
  
  function Get() {
    $code = $this->code;
    $uid_mistmatch = $code&(COMPARE::UID_MISTMATCH|COMPARE::MISSING_UID_NAME_MISTMATCH);
    $name_mistmatch = $code&COMPARE::NAME_MISTMATCH;
    $uids_altered = $code&(COMPARE::EXTRA_UID|COMPARE::MISSING_UID_NAME_MATCH);
    
    if ($uid_mistmatch) $match = "error";
    elseif ($code) $match = "warning";
    else $match = "ok";
    
    return array(
        'match' => $match,
        'code' => $code,
        'uid_mismatch' => $uid_mistmatch?1:0,
        'name_mismatch' => $name_mistmatch?1:0,
        'uids_altered' => $uids_altered?1:0,
        'extra_items' => ($code&COMPARE::EXTRA_ITEMS)?1:0,
        'missing_items' => ($code&COMPARE::MISSING_ITEMS)?1:0,
    );
  }

  static function CompareGroups($new_req, $old_req, $flags = 0) {
    $olist = $old_req->GetItemList($flags);
    $nlist = $new_req->GetItemList($flags);
    
    $res = 0;
    foreach ($olist as $i => $info) {
        if (!isset($nlist[$i])) {
            $res |= COMPARE::MISSING_ITEMS;
            break;
        }

        if  (isset($info['uid'])||isset($nlist[$i]['uid'])) {
            if (!isset($info['uid'])) 
                $res |= COMPARE::EXTRA_UID;
            else if (!isset($nlist[$i]['uid'])) {
                $res |= COMPARE::MISSING_UID;
                if (strcmp($info['name'], $nlist[$i]['name']))
                    $res |= MISSING_UID_NAME_MISTMATCH;
                else
                    $res |= MISSING_UID_NAME_MATCH;
            } elseif (strcmp($info['uid'], $nlist[$i]['uid']))
                $res |= COMPARE::UID_MISTMATCH;
        }
        
        if (strcmp($info['name'], $nlist[$i]['name']))
            $res |= NAME_MISTMATCH;
    }
    
    if (sizeof($nlist) > sizeof($olist))
        $res |= COMPARE::EXTRA_ITEMS;
    
    return new COMPARE($res);
  }
}

try {
    switch($_GET['target']) {
        case "compare_archive":
	    if (!isset($_GET['archive'])) {
	        echo "here\n";
	        $error = translate("Archive is not specified");
	        break;
            }

            $props1 = $_GET;
            $props2 = $_GET; $props2['db_name'] = $_GET['archive'];
            
	    $cmp = COMPARE::CompareGroups(new GROUPRequest($props1), new GROUPRequest($props2));
	    $info = $cmp->Get();
            break;
//        case "compare_archvies":      two archives of the same database
//        case "compare_groups":        two arbitrary groups
	default:
	    if (isset($_GET['target'])) $error = translate("Unknown metadata target (%s) is specified", $_GET['target']);
	    else $error = translate("The metadata target is not specified");
    }
} catch (ADEIException $ex) {
    $ex->logInfo(NULL, $reader?$reader:new REQUEST());
    $error = xml_escape($ex->getInfo());
}

if ($error) echo "<result><Error>$error</Error></result>\n";
else {
    $extra = "";
    foreach ($info as $prop => $value) {
	$extra .= " $prop=\"" . xml_escape($value) . "\"";
    }
    echo "<result$extra/>\n";
}

?>