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;
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) {
}
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 {
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;
$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);
}
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 )
}
[%- FOREACH file = source.files %]
<tr class="listrow[% loop.count % 2 %]">
[%- IF edit_attachments %]
- [%- IF file.newest %]
- <td>[%- L.checkbox_tag(checkname _ '[]', 'value'=file.id, 'class'=checkname) %]</td>
- [%- ELSE %]
- <td></td>
- [%- END %]
+ <td>[%- L.checkbox_tag(checkname _ '[]', 'value'=file.id _ '_' _ file.version, 'class'=checkname) %]</td>
<td></td>
[%- END %]
- <td>[% file.mtime_as_timestamp_s %]</td>
+ <td>[% file.mtime_as_timestamp_s %][% L.hidden_tag("version[]", file.version) %]</td>
<td><a href="controller.pl?action=File/download&id=[% file.id %][%- IF file.version %]&version=[%- file.version %][%- END %]">
<span id="[% "filename_" _ file.id %][%- IF file.version %]_[% file.version %][%- END %]">[% file.file_name %]</span></a></td>
[%- IF file_type == 'image' %]