From e53a1b961c96d3a8ae1093262b94d3a6b6d7ac88 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 6 Jun 2019 12:39:52 -0500 Subject: [PATCH] Bug 23064: Fix mod subscription with strict sql modes --- C4/Serials.pm | 68 ++++++++++++++++++++++++++++-------------------- t/db_dependent/Serials.t | 26 +++++++++--------- 2 files changed, 54 insertions(+), 40 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index e6eae860ff..477cd8010d 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1306,37 +1306,49 @@ sub ModSubscription { $itemtype, $previousitemtype, $mana_id ) = @_; - my $dbh = C4::Context->dbh; - my $query = "UPDATE subscription - SET librarian=?, branchcode=?, aqbooksellerid=?, cost=?, aqbudgetid=?, - startdate=?, periodicity=?, firstacquidate=?, irregularity=?, - numberpattern=?, locale=?, numberlength=?, weeklength=?, monthlength=?, - lastvalue1=?, innerloop1=?, lastvalue2=?, innerloop2=?, - lastvalue3=?, innerloop3=?, status=?, biblionumber=?, - callnumber=?, notes=?, letter=?, manualhistory=?, - internalnotes=?, serialsadditems=?, staffdisplaycount=?, - opacdisplaycount=?, graceperiod=?, location = ?, enddate=?, - skip_serialseq=?, itemtype=?, previousitemtype=?, mana_id=? - WHERE subscriptionid = ?"; + my $subscription = Koha::Subscriptions->find( $subscriptionid ); + return unless $subscription; - my $sth = $dbh->prepare($query); - $sth->execute( - $auser, $branchcode, $aqbooksellerid, $cost, - $aqbudgetid, $startdate, $periodicity, $firstacquidate, - $irregularity, $numberpattern, $locale, $numberlength, - $weeklength, $monthlength, $lastvalue1, $innerloop1, - $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, - $status, $biblionumber, $callnumber, $notes, - $letter, ($manualhistory ? $manualhistory : 0), - $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, - $graceperiod, $location, $enddate, $skip_serialseq, - $itemtype, $previousitemtype, $mana_id, - $subscriptionid - ); - my $rows = $sth->rows; + $subscription->librarian($auser); + $subscription->branchcode($branchcode); + $subscription->aqbooksellerid($aqbooksellerid); + $subscription->cost($cost); + $subscription->aqbudgetid($aqbudgetid); + $subscription->biblionumber($biblionumber); + $subscription->startdate($startdate); + $subscription->periodicity($periodicity); + $subscription->numberlength($numberlength); + $subscription->weeklength($weeklength); + $subscription->monthlength($monthlength); + $subscription->lastvalue1($lastvalue1); + $subscription->innerloop1($innerloop1); + $subscription->lastvalue2($lastvalue2); + $subscription->lastvalue3($lastvalue3); + $subscription->innerloop3($innerloop3); + $subscription->status($status); + $subscription->notes($notes); + $subscription->letter($letter); + $subscription->firstacquidate($firstacquidate); + $subscription->irregularity($irregularity); + $subscription->numberpattern($numberpattern); + $subscription->locale($locale); + $subscription->callnumber($callnumber); + $subscription->manualhistory($manualhistory || 0); + $subscription->internalnotes($internalnotes); + $subscription->serialsadditems($serialsadditems); + $subscription->staffdisplaycount($staffdisplaycount); + $subscription->opacdisplaycount($opacdisplaycount); + $subscription->graceperiod($graceperiod); + $subscription->location($location); + $subscription->enddate($enddate); + $subscription->skip_serialseq($skip_serialseq); + $subscription->itemtype($itemtype); + $subscription->previousitemtype($previousitemtype); + $subscription->mana_id($mana_id); + my $modified = $subscription->store; logaction( "SERIAL", "MODIFY", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog"); - return $rows; + return $modified; } =head2 NewSubscription diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index c6b8e06778..f1f44eac9a 100755 --- a/t/db_dependent/Serials.t +++ b/t/db_dependent/Serials.t @@ -355,10 +355,11 @@ subtest "NewSubscription" => sub { my $subscriptionid = NewSubscription( "", "", "", "", $budget_id, $biblionumber, '2013-01-01', $frequency_id, "", "", "", - "", "", "", "", "", "", - 1, $notes,"", '2013-01-01', "", $pattern_id, - "", "", 0, $internalnotes, 0, - "", "", 0, "", '2013-12-31', 0 + "", "", "", "", "", + "", 1, $notes,"", '2013-01-01', "", + $pattern_id, "", "", 0, $internalnotes, + 0, "", "", 0, + "", '2013-12-31', 0, ); ok($subscriptionid, "Sending empty string instead of undef to reflect use of the interface"); }; @@ -367,13 +368,14 @@ subtest "ModSuscription" => sub { plan tests => 1; my $subscription = $builder->build_object({ class => 'Koha::Subscriptions' }); my $modified = ModSubscription( - "", "", "", "", $budget_id, $biblionumber, - '2013-01-01', $frequency_id, "", "", "", - "", "", "", "", "", "", - 1, $notes,"", '2013-01-01', "", $pattern_id, - "", "", 0, $internalnotes, 0, - "", "", 0, "", '2013-12-31', $subscription->subscriptionid, - 0 + "", "", "", "", $budget_id, '2013-01-01', + $frequency_id, '2013-01-01', "", $pattern_id, "", + "", "", "", "", "", + "", "", "", "", 1, + $biblionumber, "", "", "", 0, + "", 0, "", "", + 0, "", "", $subscription->subscriptionid, 0, ); - is($modified, 1); + + isnt($modified, 0); }; -- 2.11.0