Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e768f277

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID e768f277bc8e9e36e8dce1c8ead6a6fd645b3405
  • Vorgänger 0ceb92a3
  • Nachfolger 944509db

File: Script fürs Löschen von ungültigen Einträgen in DB::File

Unterschiede anzeigen:

SL/BackgroundJob/RemoveInvalidFileEntries.pm
1
package SL::BackgroundJob::RemoveInvalidFileEntries;
2

  
3
use strict;
4
use warnings;
5

  
6
use parent qw(SL::BackgroundJob::Base);
7

  
8
use SL::File;
9

  
10
use constant WAITING_FOR_EXECUTION => 0;
11
use constant SCAN_START            => 1;
12
use constant DONE                  => 2;
13

  
14
# Data format:
15
# my $data = {
16
#   file_errors = [
17
#     "Ich bin ein Fehler",
18
#   ],
19
# }
20

  
21
sub scan_file_entry {
22
  my ($self)  = @_;
23
  my $job_obj = $self->{job_obj};
24
  $job_obj->set_data(status => SCAN_START())->save;
25

  
26
  my @file_entries = @{ SL::DB::Manager::File->get_all() };
27

  
28
  my @files = map { SL::File::Object->new(db_file => $_, id => $_->id, loaded => 1) } @file_entries;
29

  
30
  my $data  = $job_obj->data_as_hash;
31
  foreach my $file (@files) {
32
    unless (eval {$file->get_file()}) {
33
      #warn $@;
34
      push(@{$data->{file_errors}}, $@);
35
      $job_obj->update_attributes(data_as_hash => $data);
36
      $file->loaded_db_file->delete();
37
    }
38
  }
39
}
40

  
41
sub run {
42
  my ($self, $job_obj) = @_;
43
  $self->{job_obj} = $job_obj;
44

  
45
  $self->scan_file_entry();
46

  
47
  $job_obj->set_data(status => DONE())->save;
48
  return 1;
49
}
50

  
51
1;

Auch abrufbar als: Unified diff