Revision cff4d333
Von Martin Helmling martin.helmling@octosoft.eu vor etwa 7 Jahren hinzugefügt
SL/File.pm | ||
---|---|---|
307 | 307 |
return unless $params{file_type}; |
308 | 308 |
my $file = SL::DB::File->new; |
309 | 309 |
$file->file_type($params{file_type}); |
310 |
my $backend = $self->_get_backend(dbfile => $file->backend);
|
|
310 |
my $backend = $self->_get_backend($self->_get_backend_by_file_type($file));
|
|
311 | 311 |
return unless $backend; |
312 | 312 |
$backend->sync_from_backend(%params); |
313 | 313 |
} |
SL/File/Backend/Filesystem.pm | ||
---|---|---|
111 | 111 |
return 1; |
112 | 112 |
} |
113 | 113 |
|
114 |
sub sync_from_backend { |
|
115 |
my ($self, %params) = @_; |
|
116 |
my @query = (file_type => $params{file_type}); |
|
117 |
push @query, (file_name => $params{file_name}) if $params{file_name}; |
|
118 |
push @query, (mime_type => $params{mime_type}) if $params{mime_type}; |
|
119 |
push @query, (source => $params{source}) if $params{source}; |
|
120 |
|
|
121 |
my $sortby = $params{sort_by} || 'itime DESC,file_name ASC'; |
|
122 |
|
|
123 |
my @files = @{ SL::DB::Manager::File->get_all(query => [@query], sort_by => $sortby) }; |
|
124 |
for (@files) { |
|
125 |
$main::lxdebug->message(LXDebug->DEBUG2(), "file id=" . $_->id." version=".$_->backend_data); |
|
126 |
my $newversion = $_->backend_data; |
|
127 |
for my $version ( reverse 1 .. $_->backend_data ) { |
|
128 |
my $path = $self->_filesystem_path($_, $version); |
|
129 |
$main::lxdebug->message(LXDebug->DEBUG2(), "path=".$path." exists=".( -f $path?1:0)); |
|
130 |
last if -f $path; |
|
131 |
$newversion = $version - 1; |
|
132 |
} |
|
133 |
$main::lxdebug->message(LXDebug->DEBUG2(), "newversion=".$newversion." version=".$_->backend_data); |
|
134 |
if ( $newversion < $_->backend_data ) { |
|
135 |
$_->backend_data($newversion); |
|
136 |
$_->save if $newversion > 0; |
|
137 |
$_->delete if $newversion <= 0; |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
} |
|
114 | 142 |
|
115 | 143 |
# |
116 | 144 |
# internals |
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 => 'attachments'); |
|
86 |
SL::File->sync_from_backend( file_type => 'images'); |
|
87 |
|
|
88 |
1; |
Auch abrufbar als: Unified diff
FileManagement: Konsistenzprüfung zwischen Backend und Datenbank, hier Backend Filesystem
Das script 'scripts/sync_files_from_backend.pl' prüft, ob die Dateien im Backend noch vorhanden sind.
Dabei wird nach der aktuellsten Version gesucht, ist diese vorhanden ist ok,
ist diese nicht vorhanden werden die Versionen davor gesucht und ggf. die Version in der DB heruntergesetzt.
Ist keine Dateimehr vorhanden wird der Datenbankrecord gelöscht.
fixt #275