Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ca10be4b

Von Tamino Steinert vor 7 Monaten hinzugefügt

  • ID ca10be4bb31730f94daee8224833ed02b65944c4
  • Vorgänger 378828e9
  • Nachfolger 0534f27e

File: Löschen über die guid der Version

Unterschiede anzeigen:

SL/Controller/File.pm
393 393
  my ($self, $do_unimport, $infotext) = @_;
394 394
  my $files = '';
395 395
  my $ids = $::form->{ids};
396
  foreach my $id_version (@{ $::form->{$ids} || [] }) {
397
    my ($id, $version) = split /_/, $id_version;
398
    my $dbfile = SL::File->get(id => $id);
399
    if ( $dbfile ) {
400
      if ( $version ) {
401
        $dbfile->version($version);
402
        $files .= ' ' . $dbfile->file_name if $dbfile->delete_version;
403
      } else {
404
        $files .= ' ' . $dbfile->file_name if $dbfile->delete;
405
      }
396
  foreach my $version_guid (@{ $::form->{$ids} || [] }) {
397
    my $dbfile = SL::File->get(guid => $version_guid);
398
    if ($dbfile) {
399
      $files .= ' ' . $dbfile->file_name if $dbfile->delete_file_version;
406 400
    }
407 401
  }
408 402
  $self->js->flash('info', $infotext . $files) if $files;
SL/File.pm
4 4

  
5 5
use parent qw(Rose::Object);
6 6

  
7
use Carp;
7 8
use SL::File::Backend;
8 9
use SL::File::Object;
9 10
use SL::DB;
10 11
use SL::DB::History;
11 12
use SL::DB::ShopImage;
12 13
use SL::DB::File;
14
use SL::DB::FileVersion;
13 15
use SL::Helper::UserPreferences;
14 16
use SL::Controller::Helper::ThumbnailCreator qw(file_probe_type);
15 17
use SL::JSON;
......
22 24

  
23 25
sub get {
24 26
  my ($self, %params) = @_;
25
  die "no id or dbfile" unless $params{id} || $params{dbfile};
26
  $params{dbfile} = SL::DB::Manager::File->get_first(query => [id => $params{id}]) if !$params{dbfile};
27
  die 'not found' unless $params{dbfile};
28
  $main::lxdebug->message(LXDebug->DEBUG2(), "object_id=".$params{dbfile}->object_id." object_type=".$params{dbfile}->object_type." dbfile=".$params{dbfile});
29
  SL::File::Object->new(db_file => $params{dbfile}, id => $params{dbfile}->id, loaded => 1);
27
  croak "no id or dbfile or guid" unless $params{id} || $params{dbfile} || $params{guid};
28
  croak "dbfile has to be of type SL::DB::File"
29
    if defined $params{dbfile} && ref $params{dbfile} ne 'SL::DB::File';
30

  
31
  my $dbfile;
32
  my $file_version;
33
  if (defined $params{guid}) {
34
    $file_version = SL::DB::Manager::FileVersion->get_first(where => [guid => $params{guid}]);
35
    die 'file version with guid not found: ' . $params{guid} unless $file_version;
36
    $dbfile = $file_version->file;
37
    if (defined $params{dbfile}) {
38
      croak "dbfile doesn't match guid" if $dbfile->id != $params{dbfile}->id;
39
    }
40
    if (defined $params{id}) {
41
      croak "id doesn't match guid" if $dbfile->id != $params{id};
42
    }
43
  } elsif (defined $params{dbfile}) {
44
    $dbfile = $params{dbfile};
45
    if (defined $params{id}) {
46
      croak "id doesn't match dbfile id" if $dbfile->_id != $params{id};
47
    }
48
  } elsif (defined $params{id}) {
49
    $dbfile = SL::DB::Manager::File->get_first(query => [id => $params{id}]);
50
    die 'file with id not found: ' . $params{id} unless $dbfile;
51
  }
52

  
53
  my %object_params = (
54
    db_file => $dbfile,
55
    id => $dbfile->id,
56
    loaded => 1,
57
  );
58
  $object_params{file_version} = $file_version if $file_version;
59
  SL::File::Object->new(%object_params);
30 60
}
31 61

  
32 62
sub get_version_count {
......
75 105
    my @file_versions = reverse @{$fileobj->loaded_db_file->file_versions_sorted};
76 106
    my $latest_file_version = shift @file_versions;
77 107
    $fileobj->version($latest_file_version->version);
108
    $fileobj->file_version($latest_file_version);
78 109
    push @versionobjs, $fileobj;
79 110
    foreach my $file_version (@file_versions) {
80 111
      my $clone = $fileobj->clone;
81 112
      $clone->version($file_version->version);
113
      $clone->file_version($file_version);
82 114
      $clone->newest(0);
83 115
      push @versionobjs, $clone;
84 116
    }
......
160 192
  }
161 193
  if ($backend->delete(%params)) {
162 194
    my $do_delete = 0;
163
    if ( $params{last} || $params{version} || $params{all_but_notlast} ) {
195
    if ( $params{last} || $params{file_version} || $params{all_but_notlast} ) {
164 196
      if ( $backend->get_version_count(%params) > 0 ) {
165 197
        $params{dbfile}->mtime(DateTime->now_local);
166 198
        $params{dbfile}->save;
SL/File/Backend.pm
100 100
If none of the two parameters C<all_versions> or C<all__but_notlast> is set
101 101
all version of the file are deleted.
102 102

  
103
=item C<file_version>
104

  
105
If this parameter is set only this file version will be deleted. The object has
106
to be of type C<SL::DB::FileVersion>.
107

  
103 108
=back
104 109

  
105 110
=item C<rename PARAMS>
SL/File/Backend/Filesystem.pm
22 22
sub delete {
23 23
  my ($self, %params) = @_;
24 24
  die "no dbfile in backend delete" unless $params{dbfile};
25
  my @versions = @{$params{dbfile}->file_versions_sorted};
26 25

  
27 26
  my @versions_to_delete;
28
  if ($params{last}) {
29
    my $last = pop @versions;
30
    @versions_to_delete = ($last);
31
  } elsif ($params{all_but_notlast}) {
32
    pop @versions; # remove last
33
    @versions_to_delete = @versions;
34
  } elsif ($params{version}) {
35
    my $version = first {$_->version == $params{version}} @versions
36
      or confess "Version not found.";
37
    @versions_to_delete = ($version);
27
  if ($params{file_version}) {
28
    croak "file_version has to be of type SL::DB::FileVersion"
29
      unless ref $params{file_version} eq 'SL::DB::FileVersion';
30
    @versions_to_delete = ($params{file_version});
38 31
  } else {
39
    @versions_to_delete = @versions;
32
    my @versions = @{$params{dbfile}->file_versions_sorted};
33
    if ($params{last}) {
34
      my $last = pop @versions;
35
      @versions_to_delete = ($last);
36
    } elsif ($params{all_but_notlast}) {
37
      pop @versions; # remove last
38
      @versions_to_delete = @versions;
39
    } else {
40
      @versions_to_delete = @versions;
41
    }
40 42
  }
41 43

  
42 44
  foreach my $version (@versions_to_delete) {
SL/File/Object.pm
6 6

  
7 7
use Rose::Object::MakeMethods::Generic (
8 8
  scalar => [ qw() ],
9
  'scalar --get_set_init' => [ qw(db_file loaded id version newest) ],
9
  'scalar --get_set_init' => [ qw(db_file loaded id file_version version newest) ],
10 10
);
11 11

  
12 12
#use SL::DB::Helper::Attr;
......
97 97
  SL::File->delete(dbfile => $_[0]->loaded_db_file, last => 1 )
98 98
}
99 99

  
100
sub delete_version {
101
  SL::File->delete(dbfile => $_[0]->loaded_db_file, version => $_[0]->version )
100
sub delete_file_version {
101
  SL::File->delete(dbfile => $_[0]->loaded_db_file, file_version => $_[0]->file_version )
102 102
}
103 103

  
104 104
sub purge {
......
129 129
}
130 130

  
131 131

  
132
sub init_db_file { die 'must always have a db file'; }
133
sub init_loaded  { 0 }
134
sub init_id      { 0 }
135
sub init_version { 0 }
136
sub init_newest  { 1 }
132
sub init_db_file      { die 'must always have a db file'; }
133
sub init_loaded       { 0 }
134
sub init_id           { 0 }
135
sub init_version      { 0 }
136
sub init_file_version { undef }
137
sub init_newest       { 1 }
137 138

  
138 139
1;
139 140

  
......
218 219

  
219 220
=back
220 221

  
221
Additional are there special methods. If the Object is created by SL::File::get_all_versions()
222
or by "$object->versions"
223
it has a version number. So the different mtime, filepath or content can be retrieved:
222
Additional are there special methods. If the Object is created by
223
C<SL::File::get_all_versions()> or by C<$object->versions>. It has a version
224
number in C<version> and a version object in C<file_version> of type
225
C<SL::DB::FileVersion>. So the different mtime, filepath or content can be
226
retrieved:
224 227

  
225 228
=over 4
226 229

  
templates/design40_webpages/file/list.html
54 54
        <tr class="[% 'version_row_' _ file.id %] hidden">
55 55
      [%- END %]
56 56
        [% IF edit_attachments %]
57
          <td>[% L.checkbox_tag(checkname _ '[]', 'value'=file.id _ '_' _ file.version, 'class'=checkname) %]</td>
57
          <td>[% L.checkbox_tag(checkname _ '[]', 'value'=file.file_version.guid, 'class'=checkname) %]</td>
58 58
          <td></td>
59 59
        [% END %]
60 60
          <td class="right[%- IF file.version_count > 1 && !is_other_version %] cursor-pointer" onclick="kivi.File.toggle_versions('[% file.id %]')"[%- ELSE -%]"[%- END %]>[%#"%]
templates/mobile_webpages/file/list.html
30 30
  [%- FOREACH file = source.files %]
31 31
   <tr>
32 32
    [%- IF edit_attachments %]
33
    <td>[%- P.M.checkbox_tag(checkname _ '[]', value=file.id _ '_' _ file.version, class=checkname, label=' ') %]</td>
33
    <td>[%- P.M.checkbox_tag(checkname _ '[]', value=file.file_version.guid, class=checkname, label=' ') %]</td>
34 34
    [%- END %]
35 35
    <td>[% file.mtime_as_timestamp_s %][% L.hidden_tag("version[]", file.version) %]</td>
36 36
    <td><a href="controller.pl?action=File/download&id=[% file.id %][%- IF file.version %]&version=[%- file.version %][%- END %]">
templates/webpages/file/list.html
55 55
      <tr class="[% 'version_row_' _ file.id %] listrow[% row_cnt % 2 %] hidden">
56 56
     [%- END %]
57 57
      [%- IF edit_attachments %]
58
       <td>[%- L.checkbox_tag(checkname _ '[]', 'value'=file.id _ '_' _ file.version, 'class'=checkname) %]</td>
58
       <td>[%- L.checkbox_tag(checkname _ '[]', 'value'=file.file_version.guid, 'class'=checkname) %]</td>
59 59
       <td></td>
60 60
      [%- END %]
61 61
      <td align="right" [%- IF file.version_count > 1 && !is_other_version %] class="cursor-pointer" onclick="kivi.File.toggle_versions('[% file.id %]')"[%- END %]>

Auch abrufbar als: Unified diff