From 6c9d43ef947091ae8191741f390ee7a5bed72d17 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Fri, 9 Oct 2015 17:24:31 +0200 Subject: [PATCH] =?utf8?q?2.=20=C3=9Cberarbeitung=20=20=20=20=20Pr=C3=BCfe?= =?utf8?q?n=20beim=20Speichern,=20ob=20Dokument=20ge=C3=A4ndert=20wurde.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit API-Funktion minimale Sicherheitschecks auf Parameter. Häßliche If-Abfrage mosufiziert POD ergänzt --- SL/Form.pm | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/SL/Form.pm b/SL/Form.pm index 645544eec..a0dbb91cc 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -2604,21 +2604,18 @@ sub all_vc { } sub mtime_ischanged { - my ($self, $relation, $option) = @_; + my ($self, $table, $option) = @_; - return unless $self->{id}; # maybe better croak, but i have no api doc to refer to ... + return unless $self->{id}; + croak ("wrong call, no valid table defined") unless $table =~ /(oe|ar|ap|delivery_orders|parts)/; - my $query = "SELECT mtime, itime FROM " . $relation . " WHERE id = ?"; - my $ref = selectfirst_hashref_query($self, $self->get_standard_dbh, $query, $self->{id}); - $ref->{mtime} = $ref->{itime} if !$ref->{mtime}; + my $query = "SELECT mtime, itime FROM " . $table . " WHERE id = ?"; + my $ref = selectfirst_hashref_query($self, $self->get_standard_dbh, $query, $self->{id}); + $ref->{mtime} ||= $ref->{itime}; if ($self->{lastmtime} && $self->{lastmtime} ne $ref->{mtime} ) { - 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"); - - $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") - if ($option eq 'mail'); - # ^^ I prefer: - # my $etxt = ($option eq 'mail') ? locale1 : locale2; + 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" : + "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"; $self->error($main::locale->text($etxt)); ::end_of_request(); } @@ -2792,7 +2789,7 @@ sub create_links { foreach my $key (keys %$ref) { $self->{$key} = $ref->{$key}; } - $self->{mtime} ||= $self->{itime}; + $self->{mtime} ||= $self->{itime}; $self->{lastmtime} = $self->{mtime}; my $transdate = "current_date"; if ($self->{transdate}) { @@ -3759,6 +3756,17 @@ Used to override the default favicon. A html page title will be generated from this +=item mtime_ischanged + +Tries to avoid concurrent write operations to records by checking the database mtime with a fetched one. + +Can be used / called with any table, that has itime and mtime attributes. +Valid C names are: oe, ar, ap, delivery_orders, parts. +Can be called wit C