Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 321 lines (254 sloc) 7.727 kb
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
1 #!/usr/bin/perl
2 ##!~_~perlpath~_~
3 #
2a14b06 testing
Eric Zarko authored
4 # Interchange database updater
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
5 #
43d511c Peter Ajamian * Updated copyright headers to 2007 (closes bug #102)
pajamian authored
6 # $Id: update.PL,v 2.7 2007-08-09 13:40:57 pajamian Exp $
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
7 #
43d511c Peter Ajamian * Updated copyright headers to 2007 (closes bug #102)
pajamian authored
8 # Copyright (C) 2002-2007 Interchange Development Group
3397adc Jon Jensen The great copyright, email address, URL, and version update.
jonjensen authored
9 # Copyright (C) 1996-2002 Red Hat, Inc.
2a14b06 testing
Eric Zarko authored
10 #
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public
22 # License along with this program; if not, write to the Free
07f71a7 Peter Ajamian New Free Software Foundation Address in headers of various files
pajamian authored
23 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
24 # MA 02110-1301 USA.
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
25
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
26 use lib '/usr/local/interchange/lib';
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
27 #use lib '~_~INSTALLPRIVLIB~_~';
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
28 use lib '/usr/local/interchange';
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
29 #use lib '~_~INSTALLARCHLIB~_~';
30
2a14b06 testing
Eric Zarko authored
31 use strict;
32 use Fcntl;
33 use Vend::Config;
34 use Vend::Data;
35 use Vend::Util;
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
36
2a14b06 testing
Eric Zarko authored
37 BEGIN {
38 eval {
39 require 5.004;
40 require FindBin;
41 1 and $Global::VendRoot = "$FindBin::RealBin";
42 1 and $Global::VendRoot =~ s/.bin$//;
43 };
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
44 ($Global::VendRoot = $ENV{MINIVEND_ROOT})
45 if defined $ENV{MINIVEND_ROOT};
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
46 $Global::VendRoot = $Global::VendRoot || '/usr/local/interchange';
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
47 # $Global::VendRoot = $Global::VendRoot || '~_~INSTALLARCHLIB~_~';
a71f111 perusionmike Updated to find either interchange.cfg or minivend.cfg
perusionmike authored
48
49 if(-f "$Global::VendRoot/interchange.cfg") {
50 $Global::ExeName = 'interchange';
51 $Global::ConfigFile = 'interchange.cfg';
52 }
53 elsif(-f "$Global::VendRoot/minivend.cfg") {
54 $Global::ExeName = 'minivend';
55 $Global::ConfigFile = 'minivend.cfg';
56 }
57 elsif(-f "$Global::VendRoot/interchange.cfg.dist") {
58 $Global::ExeName = 'interchange';
59 $Global::ConfigFile = 'interchange.cfg';
60 }
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
61 }
2a14b06 testing
Eric Zarko authored
62
63 ### END CONFIGURATION VARIABLES
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
64
65 sub dontwarn { $FindBin::RealBin; }
66
67 $Global::ErrorFile = "$Global::VendRoot/error.log";
68 $Vend::ExternalProgram = 1;
69
70 my $DEBUG = 0;
71
72 #select a DBM
73
74 BEGIN {
75 $Global::GDBM = $Global::DB_File = 0;
76 AUTO: {
77 last AUTO if
78 (defined $ENV{MINIVEND_DBFILE} and $Global::DB_File = 1);
79 last AUTO if
80 (defined $ENV{MINIVEND_NODBM});
81 eval {require GDBM_File and $Global::GDBM = 1};
82 eval {require DB_File and $Global::DB_File = 1};
83 }
84 if($Global::GDBM) {
85 require Vend::Table::GDBM;
86 import GDBM_File;
87 $Global::GDBM = 1;
88 $Global::Default_database = 'GDBM';
89 }
90 if($Global::DB_File) {
91 require Vend::Table::DB_File;
92 import DB_File;
93 $Global::DB_File = 1;
94 $Global::Default_database = 'DB_FILE'
95 unless defined $Global::Default_database;
96 }
97 if(! $Global::GDBM and ! $Global::DB_File) {
98 die "No DBM defined! Update not designed to work with DBI or memory databases.\n";
99 }
100 }
101
102 $Vend::Cfg = {};
103
104 my $Name = 'products';
105 my $Directory;
106
107 my $USAGE = <<EOF;
108 usage: update -c catalog [-n name] \\
109 -f field [-f field1 -f field2 ...] -k key value [value1 value2 ...]
110 or
111
112 usage: update -c catalog -i inputfile [-n name]
113
114 Options:
115
a71f111 perusionmike Updated to find either interchange.cfg or minivend.cfg
perusionmike authored
116 -c catalog Catalog name as defined in interchange.cfg.
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
117 -f field Field name(s) in database. If multiple fields are specified,
118 multiple corresponding values must be supplied. Use '' to
119 set to the empty string.
120 -i file Input file to add entries to an existing database. (Must
121 be in same format/order as existing database.)
122 -k key Key (item code) to be updated.
123 -n name Database name as defined in catalog.cfg (default products).
124
125 If specifying a subcatalog database, make sure it is defined in the
126 subcatalog definition. If it is in the base catalog, use that catalog
127 as the parameter for the -c directive.
128 EOF
129
130 my ($Inputfile, $Key, @Fields, @Values);
131 my ($Catalog,$delimiter,$db);
132
133 GETOPT: {
134
135 if($ARGV[0] eq '-c') {
136 shift(@ARGV);
137 $Catalog = shift(@ARGV);
138 redo GETOPT;
139 }
140 elsif($ARGV[0] eq '-d') {
141 shift(@ARGV);
142 $Directory = shift(@ARGV);
143 redo GETOPT;
144 }
145 elsif($ARGV[0] eq '-n') {
146 shift(@ARGV);
147 $Name = shift(@ARGV);
148 redo GETOPT;
149 }
150 elsif($ARGV[0] eq '-k') {
151 shift(@ARGV);
152 $Key = shift(@ARGV);
153 redo GETOPT;
154 }
155 elsif($ARGV[0] eq '-i') {
156 shift(@ARGV);
157 $Inputfile = shift(@ARGV);
158 redo GETOPT;
159 }
160 elsif($ARGV[0] eq '-f') {
161 shift(@ARGV);
162 push(@Fields, shift @ARGV);
163 redo GETOPT;
164 }
165
166 } # END GETOPT
167
168 die $USAGE unless defined $Catalog;
169
170 push @Values, @ARGV;
171
172 if(@Fields and ! @Values) {
173 die $USAGE . "\n";
174 }
175 elsif (scalar(@Fields) != scalar(@Values) ) {
176 die "Number of fields and number of values don't match.\n" . $USAGE . "\n";
177 }
178 elsif ((@Fields or @Values) and defined $Inputfile) {
179 die "No field or value arguments accepted when inputting from a file.\n" .
180 $USAGE . "\n";
181 }
182 elsif (@Fields and ! $Key) {
183 die $USAGE . "\n";
184 }
185 elsif (!defined $Inputfile and ! @Fields and !@Values) {
186 die $USAGE . "\n";
187 }
188
189 my($name,$dir,$param,$subcat,$subconfig);
190 chdir $Global::VendRoot;
56f620a perusionmike Multiple security fixes, tightening up opens with explicit "< $filename"...
perusionmike authored
191 open(GLOBAL, "< $Global::ConfigFile") or
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
192 die "No global configuration file? Aborting.\n";
193 while(<GLOBAL>) {
194 next unless /^\s*(sub)?catalog\s+$Catalog\s+/i;
195 $subcat = $1 || '';
196 chomp;
197 s/^\s+//;
198 unless($subcat) {
199 (undef,$name,$dir,$param) = split /\s+/, $_, 4;
200 }
201 else {
202 (undef,$name,$subconfig,$dir,$param) = split /\s+/, $_, 5;
203 }
204 last;
205
206 }
207 close GLOBAL;
208
209 global_config();
210
211 chdir $dir or die "Couldn't change directory to $dir: $!\n";
212
a36ac8f perusionmike * Add general purpose survey and mailed-form creator for the UI.
perusionmike authored
213 $Vend::ExternalProgram = $Vend::Quiet = 1;
214
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
215 $Vend::Cfg = config($name, $dir, "$dir/etc", ($subconfig || undef));
216 $::Variable = $Vend::Cfg->{Variable};
217
218 die "Problems with config.\n" unless defined $Vend::Cfg;
219
220 $Vend::Cfg->{ProductDir} = $Directory
221 if defined $Directory;
222
223 die "Bad data directory $Vend::Cfg->{ProductDir} -- doesn't exist.\n$USAGE\n"
224 unless -d $Vend::Cfg->{ProductDir};
225
226 open_database(1);
227
228 $Vend::WriteDatabase{$Name} = 1;
229
230 die "Bad database $Name -- doesn't exist.\n\n$USAGE\n"
231 unless $db = database_exists_ref($Name);
232
233 my $ref;
234 eval {
235 $ref = $db->ref();
236 };
237
238 die "Bad open of database $Name from catalog $Catalog ($!): $@\n"
239 unless $ref and ! $@;
240
241 unless($ref->record_exists($Key)) {
242 die "Key $Key not found in database $Name.\n";
243 }
244
245 my ($key,$field,@fields);
246
247 my $key_col = $Vend::Table::Common::KEY_IDX;
248
249 if (! defined $Inputfile ) {
250 foreach $field (@Fields) {
251 unless ( defined $ref->test_column($field) ) {
252 die "$field is not a column in the database.\n";
253 }
254 my $val = shift @Values;
255 print "setting ${Name}::${field}::$Key=$val\n";
256 $ref->set_field($Key, $field, $val);
257 }
258 }
259 else {
56f620a perusionmike Multiple security fixes, tightening up opens with explicit "< $filename"...
perusionmike authored
260 open (INPUT, "< $Inputfile") or die "Couldn't open input file $Inputfile: $!\n";
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
261 while(<INPUT>) {
262 chomp;
263 s/[\r\cZ]+//;
264 (@fields) = split /\t/, $_;
265 $key = $fields[$key_col];
266 $ref->set_row($key, @fields);
267 }
268 close INPUT;
269 }
270
271 close_database();
272
273 =head1 NAME
274
d6dc450 perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
275 update -- command line setting of Interchange databases
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
276
277 =head1 VERSION
278
279 1.0
280
281 =head1 SYNOPSIS
282
283 update -c catalog [-f field -k key [-t table] value]
284
285 =head1 DESCRIPTION
286
d6dc450 perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
287 Interchange's C<update> is a rudimentary method of directly setting the
288 DBM files (not the ASCII files) of a Interchange DBM database.
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
289
290 NOTE: This command DOES NOT APPLY TO SQL databases. They have their own
291 command line monitors that are more flexible.
292
293 =head1 OPTIONS
294
295 =over 4
296
297 =item -c name
298
299 Sets the catalog for which C<update> operates. It reads the
300 catalog.cfg file to retrieve database settings.
301
302 =item -f field
303
304 The name of the field to set.
305
306 =item -n name
307
308 The name of the table to set. If the table is not a DBM database the
309 C<update> program will terminate with an error.
310
311 =back
312
313 =head1 SEE ALSO
314
3397adc Jon Jensen The great copyright, email address, URL, and version update.
jonjensen authored
315 http://www.icdevgroup.org/
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
316
317 =head1 AUTHOR
318
3397adc Jon Jensen The great copyright, email address, URL, and version update.
jonjensen authored
319 Mike Heins
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
320
Something went wrong with that request. Please try again.