From 39be0a81ce0dc13b46d01935b57aceacb69416f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 29 Jul 2016 15:14:08 +0200 Subject: [PATCH] TODO: single-dbh --- SL/TODO.pm | 55 +++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/SL/TODO.pm b/SL/TODO.pm index de99ad1dc..c575fa847 100644 --- a/SL/TODO.pm +++ b/SL/TODO.pm @@ -3,6 +3,7 @@ package TODO; use SL::DBUtils; +use SL::DB; use strict; @@ -59,42 +60,42 @@ sub save_user_config { my $myconfig = \%main::myconfig; my $form = $main::form; - my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); - - my $query = qq|SELECT id FROM employee WHERE login = ?|; + SL::DB->client->with_transaction(sub { + my $dbh = $params{dbh} || SL::DB->client->dbh; - my ($id) = selectfirst_array_query($form, $dbh, $query, $params{login}); + my $query = qq|SELECT id FROM employee WHERE login = ?|; - if (!$id) { - $main::lxdebug->leave_sub(); - return; - } + my ($id) = selectfirst_array_query($form, $dbh, $query, $params{login}); - $query = - qq|SELECT show_after_login - FROM todo_user_config - WHERE employee_id = ?|; + if (!$id) { + $main::lxdebug->leave_sub(); + return; + } - if (! selectfirst_hashref_query($form, $dbh, $query, $id)) { - do_query($form, $dbh, qq|INSERT INTO todo_user_config (employee_id) VALUES (?)|, $id); - } + $query = + qq|SELECT show_after_login + FROM todo_user_config + WHERE employee_id = ?|; - $query = - qq|UPDATE todo_user_config SET - show_after_login = ?, - show_follow_ups = ?, - show_follow_ups_login = ?, - show_overdue_sales_quotations = ?, - show_overdue_sales_quotations_login = ? + if (! selectfirst_hashref_query($form, $dbh, $query, $id)) { + do_query($form, $dbh, qq|INSERT INTO todo_user_config (employee_id) VALUES (?)|, $id); + } - WHERE employee_id = ?|; + $query = + qq|UPDATE todo_user_config SET + show_after_login = ?, + show_follow_ups = ?, + show_follow_ups_login = ?, + show_overdue_sales_quotations = ?, + show_overdue_sales_quotations_login = ? - my @values = map { $params{$_} ? 't' : 'f' } qw(show_after_login show_follow_ups show_follow_ups_login show_overdue_sales_quotations show_overdue_sales_quotations_login); - push @values, $id; + WHERE employee_id = ?|; - do_query($form, $dbh, $query, @values); + my @values = map { $params{$_} ? 't' : 'f' } qw(show_after_login show_follow_ups show_follow_ups_login show_overdue_sales_quotations show_overdue_sales_quotations_login); + push @values, $id; - $dbh->commit(); + do_query($form, $dbh, $query, @values); + }); $main::lxdebug->leave_sub(); } -- 2.20.1