add an ignore for test.cfg
[bse.git] / site / util / bsexlsprod.pl
CommitLineData
97469012
TC
1#!perl -w
2use strict;
3use Getopt::Long;
4use FindBin;
5use lib "$FindBin::Bin/../cgi-bin/modules";
6use BSE::Cfg;
7use BSE::API qw(bse_cfg bse_make_product bse_encoding);
8use BSE::ProductImportXLS;
9use Carp qw(confess);
10
11chdir "$FindBin::Bin/../cgi-bin"
12 or warn "Could not change to cgi-bin directory: $!\n";
13
14my $verbose;
15my $delete;
bf87e97c 16my @file_path;
97469012 17GetOptions("v", \$verbose,
bf87e97c
TC
18 "d", \$delete,
19 "path|p=s", \@file_path);
97469012
TC
20$verbose = defined $verbose;
21
22my $cfg = bse_cfg();
23
24my $profile = shift;
25my $filename = shift
26 or die "Usage: $0 profile filename\n";
27
bf87e97c
TC
28my $importer = BSE::ProductImportXLS->new
29 (
30 $cfg, $profile,
31 file_path => \@file_path
32 );
97469012
TC
33
34my $callback;
35$verbose
36 and $callback = sub { print "@_\n" };
37
38$importer->process($filename, $callback);
39
40if ($delete) {
41 my @products = $importer->products;
42 my @catalogs = $importer->catalogs;
43 for my $product (@products) {
44 print "Removing product $product->{id}: $product->{title}\n";
45 $product->remove($cfg);
46 }
47 require BSE::Permissions;
48 my $perms = BSE::Permissions->new($cfg);
49 for my $catalog (reverse @catalogs) {
50 my $msg;
51 if ($perms->check_edit_delete_article({}, $catalog, '', \$msg)) {
52 print "Removing catalog $catalog->{id}: $catalog->{title}\n";
53 $catalog->remove($cfg);
54 }
55 else {
56 print "Cannot remove $catalog->{id}: $msg\n";
57 }
58 }
59}
60
61my @errors = $importer->errors;
62unless ($verbose) { # unless we already reported them
63 print STDERR $_, "\n" for @errors;
64}
65@errors
66 and exit 1;
67
68exit;