update pre-requisites
[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;
d2473dc2 7use BSE::API qw(bse_init bse_cfg bse_make_product bse_encoding);
3709451d 8use BSE::Importer;
97469012
TC
9use Carp qw(confess);
10
d2473dc2 11bse_init("../cgi-bin");
97469012
TC
12
13my $verbose;
14my $delete;
bf87e97c 15my @file_path;
97469012 16GetOptions("v", \$verbose,
bf87e97c
TC
17 "d", \$delete,
18 "path|p=s", \@file_path);
97469012
TC
19$verbose = defined $verbose;
20
21my $cfg = bse_cfg();
22
23my $profile = shift;
24my $filename = shift
25 or die "Usage: $0 profile filename\n";
26
97469012
TC
27my $callback;
28$verbose
29 and $callback = sub { print "@_\n" };
30
3709451d
TC
31my $importer = BSE::Importer->new
32 (
33 cfg => $cfg,
34 profile => $profile,
35 file_path => \@file_path,
36 callback => $callback,
37 );
38
39$importer->process($filename);
97469012
TC
40
41if ($delete) {
3709451d
TC
42 my @products = $importer->leaves;
43 my @catalogs = $importer->parents;
97469012
TC
44 for my $product (@products) {
45 print "Removing product $product->{id}: $product->{title}\n";
46 $product->remove($cfg);
47 }
48 require BSE::Permissions;
49 my $perms = BSE::Permissions->new($cfg);
50 for my $catalog (reverse @catalogs) {
51 my $msg;
52 if ($perms->check_edit_delete_article({}, $catalog, '', \$msg)) {
53 print "Removing catalog $catalog->{id}: $catalog->{title}\n";
54 $catalog->remove($cfg);
55 }
56 else {
57 print "Cannot remove $catalog->{id}: $msg\n";
58 }
59 }
60}
61
62my @errors = $importer->errors;
63unless ($verbose) { # unless we already reported them
64 print STDERR $_, "\n" for @errors;
65}
66@errors
67 and exit 1;
68
69exit;