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