Revision 6ca31307
Von Tamino Steinert vor 6 Monaten hinzugefügt
sql/Pg-upgrade2/add_file_version.pl | ||
---|---|---|
8 | 8 |
|
9 | 9 |
use SL::DB::File; |
10 | 10 |
|
11 |
use SL::System::Process; |
|
12 |
|
|
11 | 13 |
use UUID::Tiny ':std'; |
12 | 14 |
|
13 | 15 |
use parent qw(SL::DBUpgrade2::Base); |
... | ... | |
15 | 17 |
sub run { |
16 | 18 |
my ($self) = @_; |
17 | 19 |
|
18 |
my $doc_path = $::lx_office_conf{paths}->{document_path}; |
|
19 |
|
|
20 |
my $all_dbfiles = SL::DB::Manager::File->get_all; |
|
21 |
my $dbfile; |
|
22 |
foreach $dbfile (@$all_dbfiles) { |
|
23 |
my @versions = SL::File->get_all_versions(dbfile => $dbfile); |
|
24 |
|
|
25 |
foreach my $version (@versions) { |
|
26 |
my $tofile = $version->get_file(); |
|
27 |
my $rel_file = $tofile; |
|
28 |
$rel_file =~ s/$doc_path//; |
|
29 |
|
|
30 |
my $fv = SL::DB::FileVersion->new( |
|
31 |
file_id => $dbfile->id, |
|
32 |
version => $version->version, |
|
33 |
file_location => $rel_file, |
|
34 |
doc_path => $doc_path, |
|
35 |
backend => $dbfile->backend, |
|
36 |
guid => create_uuid_as_string(UUID_V4), |
|
37 |
)->save; |
|
20 |
SL::DB->client->with_transaction(sub { |
|
21 |
my $all_dbfiles = SL::DB::Manager::File->get_all; |
|
22 |
foreach my $dbfile (@$all_dbfiles) { |
|
23 |
my $file_id = $dbfile->id; |
|
24 |
my $backend = $dbfile->backend |
|
25 |
or die "File with ID '$file_id' has no backend specified."; |
|
26 |
|
|
27 |
my $doc_path; |
|
28 |
if ($backend eq 'Webdav') { |
|
29 |
$doc_path = SL::System::Process::exe_dir() . '/webdav'; |
|
30 |
} elsif ($backend eq 'Filesystem') { |
|
31 |
$doc_path = $::lx_office_conf{paths}->{document_path}; |
|
32 |
} else { |
|
33 |
die "Unknown backend '$backend' for file with ID '$file_id'."; |
|
34 |
} |
|
35 |
|
|
36 |
my @versions = SL::File->get_all_versions(dbfile => $dbfile); |
|
37 |
foreach my $version (@versions) { |
|
38 |
my $tofile = $version->get_file(); |
|
39 |
my $rel_file = $tofile; |
|
40 |
$rel_file =~ s/$doc_path//; |
|
41 |
|
|
42 |
my $fv = SL::DB::FileVersion->new( |
|
43 |
file_id => $dbfile->id, |
|
44 |
version => $version->version, |
|
45 |
file_location => $rel_file, |
|
46 |
doc_path => $doc_path, |
|
47 |
backend => $dbfile->backend, |
|
48 |
guid => create_uuid_as_string(UUID_V4), |
|
49 |
)->save; |
|
50 |
} |
|
38 | 51 |
} |
39 |
} |
|
52 |
1; |
|
53 |
}) or do { die SL::DB->client->error }; |
|
40 | 54 |
|
41 | 55 |
return 1; |
42 | 56 |
} |
Auch abrufbar als: Unified diff
FileVersion: Migration für Backend Webdav angepasst