2c361483fc61e64549c3946efbd829e913446622
[kivitendo-erp.git] / scripts / sync_files_from_backend.pl
1 #!/usr/bin/perl
2
3 BEGIN {
4   if (! -d "bin" || ! -d "SL") {
5     print("This tool must be run from the kivitendo ERP base directory.\n");
6     exit(1);
7   }
8
9   unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
10   push    @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
11 }
12
13
14 use strict;
15 use warnings;
16 use utf8;
17 use English '-no_match_vars';
18 use POSIX qw(setuid setgid);
19 use Text::CSV_XS;
20
21 use Config::Std;
22 use DBI;
23 use SL::LXDebug;
24 use SL::LxOfficeConf;
25
26 use SL::DBUtils;
27 use SL::Auth;
28 use SL::Form;
29 use SL::User;
30 use SL::Locale;
31 use SL::File;
32 use SL::InstanceConfiguration;
33 use Getopt::Long;
34 use Pod::Usage;
35 use Term::ANSIColor;
36
37 my %config;
38
39 sub parse_args {
40   my ($options) = @_;
41   GetOptions(
42     'client=s'          => \ my $client,
43   );
44
45   $options->{client}   = $client;
46 }
47
48 sub setup {
49
50   SL::LxOfficeConf->read;
51
52   my $client = $config{client} || $::lx_office_conf{devel}{client};
53
54   if (!$client) {
55     error("No client found in config. Please provide a client:");
56     usage();
57   }
58
59   $::lxdebug      = LXDebug->new();
60   $::locale       = Locale->new("de");
61   $::form         = new Form;
62   $::auth         = SL::Auth->new();
63
64   if (!$::auth->set_client($client)) {
65     error("No client with ID or name '$client' found in config. Please provide a client:");
66     usage();
67   }
68   $::instance_conf = SL::InstanceConfiguration->new;
69   $::instance_conf->init;
70 }
71
72 sub error {
73   print STDERR colored(shift, 'red'), $/;
74 }
75
76 sub usage {
77   print STDERR "scripts/sync_files_from_backend.pl --client name-or-id\n" ;
78   exit 1;
79 }
80
81 parse_args(\%config);
82 setup();
83
84 SL::File->sync_from_backend( file_type => 'document');
85 SL::File->sync_from_backend( file_type => 'attachment');
86 SL::File->sync_from_backend( file_type => 'image');
87
88 1;