Skip to content
This repository
Newer
Older
100644 319 lines (254 sloc) 7.721 kb
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
1 #!/usr/bin/perl
2 ##!~_~perlpath~_~
3 #
2a14b06d » Eric Zarko
2000-09-25 testing
4 # Interchange database updater
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
5 #
3397adcb » jonjensen
2003-06-18 The great copyright, email address, URL, and version update.
6 # $Id: update.PL,v 2.4 2003-06-18 17:34:47 jon Exp $
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
7 #
3397adcb » jonjensen
2003-06-18 The great copyright, email address, URL, and version update.
8 # Copyright (C) 2002-2003 Interchange Development Group
9 # Copyright (C) 1996-2002 Red Hat, Inc.
2a14b06d » Eric Zarko
2000-09-25 testing
10 #
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
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
23 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 # MA 02111-1307 USA.
25
a30978f6 » Eric Zarko
2000-09-20 s:/usr/local/minivend:/usr/local/interchange:g;
26 use lib '/usr/local/interchange/lib';
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
27 #use lib '~_~INSTALLPRIVLIB~_~';
a30978f6 » Eric Zarko
2000-09-20 s:/usr/local/minivend:/usr/local/interchange:g;
28 use lib '/usr/local/interchange';
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
29 #use lib '~_~INSTALLARCHLIB~_~';
30
2a14b06d » Eric Zarko
2000-09-25 testing
31 use strict;
32 use Fcntl;
33 use Vend::Config;
34 use Vend::Data;
35 use Vend::Util;
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
36
2a14b06d » Eric Zarko
2000-09-25 testing
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 };
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
44 ($Global::VendRoot = $ENV{MINIVEND_ROOT})
45 if defined $ENV{MINIVEND_ROOT};
a30978f6 » Eric Zarko
2000-09-20 s:/usr/local/minivend:/usr/local/interchange:g;
46 $Global::VendRoot = $Global::VendRoot || '/usr/local/interchange';
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
47 # $Global::VendRoot = $Global::VendRoot || '~_~INSTALLARCHLIB~_~';
a71f1110 » perusionmike
2000-09-23 Updated to find either interchange.cfg or minivend.cfg
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 }
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
61 }
2a14b06d » Eric Zarko
2000-09-25 testing
62
63 ### END CONFIGURATION VARIABLES
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
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
a71f1110 » perusionmike
2000-09-23 Updated to find either interchange.cfg or minivend.cfg
116 -c catalog Catalog name as defined in interchange.cfg.
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
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;
56f620af » perusionmike
2000-07-20 Multiple security fixes, tightening up opens with explicit "< $filena…
191 open(GLOBAL, "< $Global::ConfigFile") or
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
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
a36ac8fe » perusionmike
2002-11-20 * Add general purpose survey and mailed-form creator for the UI.
213 $Vend::ExternalProgram = $Vend::Quiet = 1;
214
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
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 {
56f620af » perusionmike
2000-07-20 Multiple security fixes, tightening up opens with explicit "< $filena…
260 open (INPUT, "< $Inputfile") or die "Couldn't open input file $Inputfile: $!\n";
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
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
d6dc4509 » perusionmike
2000-07-12 Changed Interchange name all over, minor exceptions being mvfaq.pod and
275 update -- command line setting of Interchange databases
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
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
d6dc4509 » perusionmike
2000-07-12 Changed Interchange name all over, minor exceptions being mvfaq.pod and
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.
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
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
3397adcb » jonjensen
2003-06-18 The great copyright, email address, URL, and version update.
315 http://www.icdevgroup.org/
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
316
317 =head1 AUTHOR
318
3397adcb » jonjensen
2003-06-18 The great copyright, email address, URL, and version update.
319 Mike Heins
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
320
Something went wrong with that request. Please try again.