Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 26081e15

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 26081e15648fb3a36b1139984387119636e4c525
  • Vorgänger dd9a94f2
  • Nachfolger ca09815c

BJ: CheckBelowMinimumStock: Überprüfung der E-Mailadresse angepasst

Unterschiede anzeigen:

SL/BackgroundJob/CheckBelowMinimumStock.pm
5 5

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

  
8
use SL::Mailer;
8 9
use SL::DB::Part;
9 10
use SL::Presenter::Part qw(part);
10 11
use SL::Presenter::Tag qw(html_tag);
......
49 50

  
50 51
sub _email_user {
51 52
  my ($self) = @_;
52
  $self->{email_user} ||= SL::DB::Manager::AuthUser->find_by(login => $self->{config}->{send_email_to});
53
  return unless ($self->{config} && $self->{config}->{send_email_to});
54
  SL::DB::Manager::AuthUser->find_by(login => $self->{config}->{send_email_to})->get_config_value('email');
53 55
}
54 56

  
55 57

  
56 58
sub send_email {
57 59
  my ($self) = @_;
58 60

  
59
  my @ids = @{$self->{job_obj}->data_as_hash->{ids}};
60
  return unless (scalar @ids && $self->{config} && $self->{config}->{send_email_to});
61

  
62
  my $user  = $self->_email_user;
63
  my $email = $self->{job_obj}->data_as_hash->{mail_to} ? $self->{job_obj}->data_as_hash->{mail_to}
64
            : $user                                     ? $user->get_config_value('email')
65
            : undef;
61
  my $email = $self->{job_obj}->data_as_hash->{send_email_to} or $self->_email_user;
66 62
  return unless $email;
67 63

  
68 64
  # additional email
69
  $email .= $self->{job_obj}->data_as_hash->{email} if $self->{job_obj}->data_as_hash->{email} =~ m/(\S+)@(\S+)$/;
65
  $email .= " " . $self->{job_obj}->data_as_hash->{additional_email} if $self->{job_obj}->data_as_hash->{additional_email} =~ m/(\S+)@(\S+)$/;
70 66

  
71 67
  my ($output, $content_type) = $self->_prepare_report;
72 68

  
......
83 79
    my $error = $self->{job_obj}->data_as_hash->{errors} . t8('Mailer error #1', $err);
84 80
    $self->{job_obj}->set_data(errors => $error)->save;
85 81
  }
82

  
83
  return
86 84
}
87 85

  
88 86
sub _prepare_report {
......
140 138

  
141 139
  $self->check_below_minimum_stock();
142 140

  
143
  $self->send_email();
144

  
145 141
  my $data = $job_obj->data_as_hash;
146
  die $data->{errors} if $data->{errors};
142
  if ($data->{errors}) {
143
      # on error we have to inform the user
144
      $self->send_email();
145
      die $data->{errors};
146
  }
147 147

  
148 148
  $job_obj->set_data(status => DONE())->save;
149 149
  return ;

Auch abrufbar als: Unified diff