* Add enclair_db option to UserDB.pm. Allows logging of enclair password
[interchange.git] / code / UI_Tag / diff.coretag
1 # Copyright 2002-2007 Interchange Development Group and others
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.  See the LICENSE file for details.
7
8 # $Id: diff.coretag,v 1.4 2007-03-30 23:40:54 pajamian Exp $
9
10 UserTag diff Order       current previous
11 UserTag diff attrAlias   curr current prev previous
12 UserTag diff addAttr
13 UserTag diff Version     $Revision: 1.4 $
14 UserTag diff Routine     <<EOR
15 sub {
16     my ($curr, $prev, $opt) = @_;
17
18         $opt->{flags} .= ' -c' if $opt->{context};
19         $opt->{flags} .= ' -u' if $opt->{unified};
20
21         my $data_opt = {};
22         $data_opt->{safe_data} = 1 if $opt->{safe_data};
23
24     unless($opt->{flags} =~ /^[-\s\w.]*$/) {
25         Log("diff tag: Security violation with flags: $opt->{flags}");
26         return "Security violation with flags: $opt->{flags}. Logged.";
27     }
28
29     my ($currfn, $prevfn);
30
31     if($curr =~ /^(\w+)::(.*?)::(.*)/) {
32         my ($table, $col, $key) = ($1, $2, $3);
33         $currfn = "tmp/$Vend::SessionName.current";
34                 my $data = tag_data($table, $col, $key, $data_opt);
35                 if ($opt->{ascii}) {
36                         $data =~ s/\r\n?/\n/g;
37                         $data .= "\n" unless substr($data, -1, 1) eq "\n";
38                 }
39         Vend::Util::writefile(">$currfn", $data);
40     }
41     else {
42         $currfn = $curr;
43     }
44
45     if($prev =~ /^(\w+)::(.*?)::(.*)/) {
46         my ($table, $col, $key) = ($1, $2, $3);
47         $prevfn = "tmp/$Vend::SessionName.previous";
48                 my $data = tag_data($table, $col, $key, $data_opt);
49                 if ($opt->{ascii}) {
50                         $data =~ s/\r\n?/\n/g;
51                         $data .= "\n" unless substr($data, -1, 1) eq "\n";
52                 }
53         Vend::Util::writefile(">$prevfn", $data);
54     }
55     else {
56         $prevfn = $prev;
57     }
58
59 #Debug("diff command: 'diff $opt->{flags} $prevfn $currfn'");
60     return `diff $opt->{flags} $prevfn $currfn`;
61 }
62 EOR