Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 378828e9

Von Tamino Steinert vor 11 Monaten hinzugefügt

  • ID 378828e90f2679049e0bc762a1b672878e856ec4
  • Vorgänger ee82caf3
  • Nachfolger ca10be4b

SL::File: Versionsnummber über file_version bestimmen

Unterschiede anzeigen:

SL/File.pm
@fileobjs = $self->get_all(%params);
}
foreach my $fileobj (@fileobjs) {
$main::lxdebug->message(LXDebug->DEBUG2(), "obj=" . $fileobj . " id=" . $fileobj->id." versions=".$fileobj->version_count);
my $maxversion = $fileobj->version_count;
$fileobj->version($maxversion);
my @file_versions = reverse @{$fileobj->loaded_db_file->file_versions_sorted};
my $latest_file_version = shift @file_versions;
$fileobj->version($latest_file_version->version);
push @versionobjs, $fileobj;
if ($maxversion > 1) {
for my $version (2..$maxversion) {
$main::lxdebug->message(LXDebug->DEBUG2(), "clone for version=".($maxversion-$version+1));
eval {
my $clone = $fileobj->clone;
$clone->version($maxversion-$version+1);
$clone->newest(0);
$main::lxdebug->message(LXDebug->DEBUG2(), "clone version=".$clone->version." mtime=". $clone->mtime);
push @versionobjs, $clone;
1;
} or do {$::lxdebug->message(LXDebug::WARN(), "clone for version=".($maxversion-$version+1) . "failed: " . $@)};
}
foreach my $file_version (@file_versions) {
my $clone = $fileobj->clone;
$clone->version($file_version->version);
$clone->newest(0);
push @versionobjs, $clone;
}
}
return @versionobjs;
SL/File/Backend/Filesystem.pm
use SL::DB::File;
use SL::DB::FileVersion;
use Carp;
use List::Util qw(first);
use File::Copy;
use File::Slurp;
use File::stat;
......
sub delete {
my ($self, %params) = @_;
die "no dbfile in backend delete" unless $params{dbfile};
my $last_version = $params{dbfile}->backend_data;
my $first_version = 1;
$last_version = 0 if $params{last};
$last_version = $params{dbfile}->backend_data-1 if $params{all_but_notlast};
$last_version = $params{version} if $params{version};
$first_version = $params{version} if $params{version};
if ($last_version > 0 ) {
for my $version ( $first_version..$last_version) {
my $file_path = $self->_filesystem_path($params{dbfile},$version);
unlink($file_path);
}
if ($params{version}) {
for my $version ( $last_version+1 .. $params{dbfile}->backend_data) {
my $from = $self->_filesystem_path($params{dbfile},$version);
my $to = $self->_filesystem_path($params{dbfile},$version - 1);
die "file not exists in backend delete" unless -f $from;
rename($from,$to);
}
$params{dbfile}->backend_data($params{dbfile}->backend_data-1);
}
elsif ($params{all_but_notlast}) {
my $from = $self->_filesystem_path($params{dbfile},$params{dbfile}->backend_data);
my $to = $self->_filesystem_path($params{dbfile},1);
die "file not exists in backend delete" unless -f $from;
rename($from,$to);
$params{dbfile}->backend_data(1);
} else {
$params{dbfile}->backend_data(0);
}
unless ($params{dbfile}->backend_data) {
my $dir_path = $self->_filesystem_path($params{dbfile});
rmdir($dir_path);
}
my @versions = @{$params{dbfile}->file_versions_sorted};
my @versions_to_delete;
if ($params{last}) {
my $last = pop @versions;
@versions_to_delete = ($last);
} elsif ($params{all_but_notlast}) {
pop @versions; # remove last
@versions_to_delete = @versions;
} elsif ($params{version}) {
my $version = first {$_->version == $params{version}} @versions
or confess "Version not found.";
@versions_to_delete = ($version);
} else {
my $file_path = $self->_filesystem_path($params{dbfile},$params{dbfile}->backend_data);
die "file not exists in backend delete" unless -f $file_path;
unlink($file_path);
$params{dbfile}->backend_data($params{dbfile}->backend_data-1);
@versions_to_delete = @versions;
}
return 1;
}
sub rename {
foreach my $version (@versions_to_delete) {
unlink($version->get_system_location());
$version->delete;
}
return 1;
}
sub save {
......
return 1 if $last_file_size == $new_file_size;
}
$dbfile->backend_data(0) unless $dbfile->backend_data;
$dbfile->backend_data($dbfile->backend_data*1+1);
$dbfile->save->load;
my @versions = @{$dbfile->file_versions_sorted};
my $new_version_number = scalar @versions ? $versions[-1]->version + 1 : 1;
my $tofile = $self->_filesystem_path($dbfile);
my $tofile = $self->_filesystem_path($dbfile, $new_version_number);
if ($params{file_path} && -f $params{file_path}) {
File::Copy::copy($params{file_path}, $tofile);
} elsif ($params{file_contents}) {
......
$rel_file =~ s/$doc_path//;
my $fv = SL::DB::FileVersion->new(
file_id => $dbfile->id,
version => $dbfile->backend_data,
version => $new_version_number,
file_location => $rel_file,
doc_path => $doc_path,
backend => 'Filesystem',
......
sub get_version_count {
my ($self, %params) = @_;
die "no dbfile" unless $params{dbfile};
return $params{dbfile}->backend_data//0 * 1;
my $file_id = $params{dbfile}->id;
return 0 unless defined $file_id;
return SL::DB::Manager::FileVersion->get_all_count(where => [file_id => $file_id]);
}
sub get_mtime {
my ($self, %params) = @_;
die "no dbfile" unless $params{dbfile};
die "unknown version" if $params{version} &&
($params{version} < 0 || $params{version} > $params{dbfile}->backend_data);
my $path = $self->_filesystem_path($params{dbfile}, $params{version});
die "No file found at $path. Expected: $params{dbfile}{file_name}, file.id: $params{dbfile}{id}" if !-f $path;
my $path = $self->get_filepath(%params);
my $dt = DateTime->from_epoch(epoch => stat($path)->mtime, time_zone => $::locale->get_local_time_zone()->name, locale => $::lx_office_conf{system}->{language})->clone();
return $dt;
......
}
sub sync_from_backend {
my ($self, %params) = @_;
my @query = (file_type => $params{file_type});
push @query, (file_name => $params{file_name}) if $params{file_name};
push @query, (mime_type => $params{mime_type}) if $params{mime_type};
push @query, (source => $params{source}) if $params{source};
my $sortby = $params{sort_by} || 'itime DESC,file_name ASC';
my @files = @{ SL::DB::Manager::File->get_all(query => [@query], sort_by => $sortby) };
for (@files) {
$main::lxdebug->message(LXDebug->DEBUG2(), "file id=" . $_->id." version=".$_->backend_data);
my $newversion = $_->backend_data;
for my $version ( reverse 1 .. $_->backend_data ) {
my $path = $self->_filesystem_path($_, $version);
$main::lxdebug->message(LXDebug->DEBUG2(), "path=".$path." exists=".( -f $path?1:0));
last if -f $path;
$newversion = $version - 1;
}
$main::lxdebug->message(LXDebug->DEBUG2(), "newversion=".$newversion." version=".$_->backend_data);
if ( $newversion < $_->backend_data ) {
$_->backend_data($newversion);
$_->save if $newversion > 0;
$_->delete if $newversion <= 0;
}
}
die "Not implemented";
}
#
......
die "No files backend enabled" unless $::instance_conf->get_doc_files || $::lx_office_conf{paths}->{document_path};
# use filesystem with depth 3
$version = $dbfile->backend_data if !$version || $version < 1 || $version > $dbfile->backend_data;
$version ||= $dbfile->file_versions_sorted->[-1]->version;
confess "Version is required." unless $version;
my $iddir = sprintf("%04d", $dbfile->id % 1000);
my $path = File::Spec->catdir($::lx_office_conf{paths}->{document_path}, $::auth->client->{id}, $iddir, $dbfile->id);
if (!-d $path) {
File::Path::make_path($path, { chmod => 0770 });
}
return $path if !$version;
return File::Spec->catdir($path, $dbfile->id . '_' . $version);
}
locale/de/all
'Could not spawn ghostscript.' => 'Die Anwendung "ghostscript" konnte nicht gestartet werden.',
'Could not spawn the printer command.' => 'Die Druckanwendung konnte nicht gestartet werden.',
'Could not update prices!' => 'Preise konnten nicht aktualisiert werden!',
'Count' => 'Anzahl',
'Country' => 'Land',
'Country (Shipping)' => 'Land (Lieferung)',
'Create' => 'Anlegen',
locale/en/all
'Could not spawn ghostscript.' => '',
'Could not spawn the printer command.' => '',
'Could not update prices!' => '',
'Count' => '',
'Country' => '',
'Country (Shipping)' => '',
'Create' => '',
sql/Pg-upgrade2/add_file_version.pl
use parent qw(SL::DBUpgrade2::Base);
sub get_all_versions {
my ($fileobj) = @_;
my @versionobjs;
my $maxversion = $fileobj->version_count;
$fileobj->version($maxversion);
push @versionobjs, $fileobj;
if ($maxversion > 1) {
for my $version (2..$maxversion) {
my $clone = $fileobj->clone;
$clone->version($maxversion-$version+1);
$clone->newest(0);
push @versionobjs, $clone;
}
}
}
sub run {
my ($self) = @_;
......
die "Unknown backend '$backend' for file with ID '$file_id'.";
}
my @versions = SL::File->get_all_versions(dbfile => $dbfile);
my @versions = get_all_versions($dbfile);
foreach my $version (@versions) {
my $tofile;
eval {
......
my $fv = SL::DB::FileVersion->new(
file_id => $dbfile->id,
version => $version->version,
version => $version->version || 1,
file_location => $rel_file,
doc_path => $doc_path,
backend => $dbfile->backend,
templates/design40_webpages/file/list.html
</th>
<th>[% source.chkall_title %]</th>
[% END %]
<th>[% LxERP.t8('Version') %]</th>
<th>[% LxERP.t8('Version') _ ' (' _ LxERP.t8('Count') _ ')' %]</th>
<th>[% LxERP.t8('Date') %]</th>
<th>[% source.file_title %]</th>
[% IF file_type == 'image' %]
......
[% END %]
<td class="right[%- IF file.version_count > 1 && !is_other_version %] cursor-pointer" onclick="kivi.File.toggle_versions('[% file.id %]')"[%- ELSE -%]"[%- END %]>[%#"%]
[%- IF file.version_count > 1 && !is_other_version %]<span id="[% 'version_toggle_' _ file.id %]">⏷ </span>[% END %]
[% file.version _ '/' _ file.version_count %]
[% file.version _ ' (' _ file.version_count _ ')' %]
[% L.hidden_tag("version[]", file.version) %]
</td>
<td>[% file.mtime_as_timestamp_s %]</td>
templates/webpages/file/list.html
<th class="listheading" width="3%">[% L.checkbox_tag(checkname _ '_checkall') %]</th>
<th class="listheading" width="7%">[% source.chkall_title %]</th>
[%- END %]
<th class="listheading" width="2%"><b>[% LxERP.t8('Version') %]</b></th>
<th class="listheading" width="2%"><b>[% LxERP.t8('Version') _ ' (' _ LxERP.t8('Count') _ ')' %]</b></th>
<th class="listheading" width="15%"><b>[% LxERP.t8('Date') %]</b></th>
<th class="listheading" width="20%"><b>[% source.file_title %]</b></th>
[%- IF file_type == 'image' %]
......
[%- END %]
<td align="right" [%- IF file.version_count > 1 && !is_other_version %] class="cursor-pointer" onclick="kivi.File.toggle_versions('[% file.id %]')"[%- END %]>
[%- IF file.version_count > 1 && !is_other_version %]<span id="[% 'version_toggle_' _ file.id %]">⏷ </span>[% END %]
[% file.version _ '/' _ file.version_count %]
[% file.version _ ' (' _ file.version_count _ ')' %]
[% L.hidden_tag("version[]", file.version) %]
</td>
<td>[% file.mtime_as_timestamp_s %]</td>

Auch abrufbar als: Unified diff