From: Martin Helmling martin.helmling@octosoft.eu Date: Fri, 29 Sep 2017 12:50:25 +0000 (+0200) Subject: Dateimanagement: Checkbox zum Löschen/Umbenennen fehlt teilweise bei ERP-Dokumenten X-Git-Tag: release-3.5.4~712 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=48baa5ebf4441c31d45d0111a0fe8b88d10a4dcd;p=kivitendo-erp.git Dateimanagement: Checkbox zum Löschen/Umbenennen fehlt teilweise bei ERP-Dokumenten Umgebaut, damit jede einzelne Version eines Dokumentes löschbar ist fix #51 --- diff --git a/SL/Controller/File.pm b/SL/Controller/File.pm index bb976e056..2572da16b 100644 --- a/SL/Controller/File.pm +++ b/SL/Controller/File.pm @@ -350,9 +350,13 @@ sub _delete_all { foreach my $id_version (@{ $::form->{$ids} || [] }) { my ($id, $version) = split /_/, $id_version; my $dbfile = SL::File->get(id => $id); - $dbfile->version($version) if $dbfile && $version; - if ( $dbfile && $dbfile->delete ) { - $files .= ' ' . $dbfile->file_name; + if ( $dbfile ) { + if ( $version ) { + $dbfile->version($version); + $files .= ' ' . $dbfile->file_name if $dbfile->delete_version; + } else { + $files .= ' ' . $dbfile->file_name if $dbfile->delete; + } } } $self->js->flash('info', $infotext . $files) if $files; diff --git a/SL/File.pm b/SL/File.pm index 677be676b..329697474 100644 --- a/SL/File.pm +++ b/SL/File.pm @@ -72,6 +72,7 @@ sub get_all_versions { 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); push @versionobjs, $fileobj; if ($maxversion > 1) { for my $version (2..$maxversion) { @@ -162,8 +163,8 @@ sub _delete { } if ($backend->delete(%params)) { my $do_delete = 0; - if ( $params{last} || $params{all_but_notlast} ) { - if ( $backend->get_version_count > 0 ) { + if ( $params{last} || $params{version} || $params{all_but_notlast} ) { + if ( $backend->get_version_count(%params) > 0 ) { $params{dbfile}->mtime(DateTime->now_local); $params{dbfile}->save; } else { diff --git a/SL/File/Backend/Filesystem.pm b/SL/File/Backend/Filesystem.pm index 70d956e0a..922928380 100644 --- a/SL/File/Backend/Filesystem.pm +++ b/SL/File/Backend/Filesystem.pm @@ -15,16 +15,28 @@ use File::Path qw(make_path); sub delete { my ($self, %params) = @_; die "no dbfile in backend delete" unless $params{dbfile}; - my $backend_data = $params{dbfile}->backend_data; - $backend_data = 0 if $params{last}; - $backend_data = $params{dbfile}->backend_data-1 if $params{all_but_notlast}; - - if ($backend_data > 0 ) { - for my $version ( 1..$backend_data) { + 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{all_but_notlast}) { + 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; @@ -32,6 +44,8 @@ sub delete { $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); } diff --git a/SL/File/Object.pm b/SL/File/Object.pm index 88883ac0a..7ac8706fc 100644 --- a/SL/File/Object.pm +++ b/SL/File/Object.pm @@ -97,6 +97,10 @@ sub delete_last_version { SL::File->delete(dbfile => $_[0]->loaded_db_file, last => 1 ) } +sub delete_version { + SL::File->delete(dbfile => $_[0]->loaded_db_file, version => $_[0]->version ) +} + sub purge { SL::File->delete(dbfile => $_[0]->loaded_db_file, all_but_notlast => 1 ) } diff --git a/templates/webpages/file/list.html b/templates/webpages/file/list.html index 238fb12fe..271ab8147 100644 --- a/templates/webpages/file/list.html +++ b/templates/webpages/file/list.html @@ -44,14 +44,10 @@ $(function() { [%- FOREACH file = source.files %] [%- IF edit_attachments %] - [%- IF file.newest %] - [%- L.checkbox_tag(checkname _ '[]', 'value'=file.id, 'class'=checkname) %] - [%- ELSE %] - - [%- END %] + [%- L.checkbox_tag(checkname _ '[]', 'value'=file.id _ '_' _ file.version, 'class'=checkname) %] [%- END %] - [% file.mtime_as_timestamp_s %] + [% file.mtime_as_timestamp_s %][% L.hidden_tag("version[]", file.version) %] [% file.file_name %] [%- IF file_type == 'image' %]