Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 6c9d43ef

Von Jan Büren vor mehr als 9 Jahren hinzugefügt

  • ID 6c9d43ef947091ae8191741f390ee7a5bed72d17
  • Vorgänger d2af074a
  • Nachfolger 5ecd9ac7

2. Überarbeitung Prüfen beim Speichern, ob Dokument geändert wurde.

API-Funktion minimale Sicherheitschecks auf Parameter.
Häßliche If-Abfrage mosufiziert
POD ergänzt

Unterschiede anzeigen:

SL/Form.pm
2604 2604
}
2605 2605

  
2606 2606
sub mtime_ischanged {
2607
  my ($self, $relation, $option) = @_;
2607
  my ($self, $table, $option) = @_;
2608 2608

  
2609
  return unless $self->{id};  # maybe better croak, but i have no api doc to refer to ...
2609
  return                                       unless $self->{id};
2610
  croak ("wrong call, no valid table defined") unless $table =~ /(oe|ar|ap|delivery_orders|parts)/;
2610 2611

  
2611
  my $query = "SELECT mtime, itime FROM " . $relation . " WHERE id = ?";
2612
  my $ref = selectfirst_hashref_query($self, $self->get_standard_dbh, $query, $self->{id});
2613
  $ref->{mtime} = $ref->{itime} if !$ref->{mtime};
2612
  my $query       = "SELECT mtime, itime FROM " . $table . " WHERE id = ?";
2613
  my $ref         = selectfirst_hashref_query($self, $self->get_standard_dbh, $query, $self->{id});
2614
  $ref->{mtime} ||= $ref->{itime};
2614 2615

  
2615 2616
  if ($self->{lastmtime} && $self->{lastmtime} ne $ref->{mtime} ) {
2616
      my $etxt = $main::locale->text("The document has been changed from other user. Please reopen it in another window and copy the changes to the new window");
2617

  
2618
      $etxt = $main::locale->text("The document has been changed from other user. No mail was sent. Please reopen it in another window and copy the changes to the new window")
2619
        if ($option eq 'mail');
2620
      # ^^ I prefer:
2621
      # my $etxt = ($option eq 'mail') ? locale1 : locale2;
2617
      my $etxt = ($option eq 'mail') ? "The document has been changed from other user. Please reopen it in another window and copy the changes to the new window" :
2618
                                       "The document has been changed from other user. No mail was sent. Please reopen it in another window and copy the changes to the new window";
2622 2619
      $self->error($main::locale->text($etxt));
2623 2620
    ::end_of_request();
2624 2621
  }
......
2792 2789
    foreach my $key (keys %$ref) {
2793 2790
      $self->{$key} = $ref->{$key};
2794 2791
    }
2795
    $self->{mtime} ||= $self->{itime};
2792
    $self->{mtime}   ||= $self->{itime};
2796 2793
    $self->{lastmtime} = $self->{mtime};
2797 2794
    my $transdate = "current_date";
2798 2795
    if ($self->{transdate}) {
......
3759 3756

  
3760 3757
A html page title will be generated from this
3761 3758

  
3759
=item mtime_ischanged
3760

  
3761
Tries to avoid concurrent write operations to records by checking the database mtime with a fetched one.
3762

  
3763
Can be used / called with any table, that has itime and mtime attributes.
3764
Valid C<table> names are: oe, ar, ap, delivery_orders, parts.
3765
Can be called wit C<option> mail to generate a different error message.
3766

  
3767
Returns undef if no save operation has been done yet ($self->{id} not present).
3768
Returns undef if no concurrent write process is detected otherwise a error message.
3769

  
3762 3770
=back
3763 3771

  
3764 3772
=cut

Auch abrufbar als: Unified diff