From d9c983c5680a877fad0dcef383c9af2b565862e4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 20 Jan 2016 17:56:58 +0000 Subject: [PATCH] Bug 15632: Koha::Patron::Messages - Remove AddMessage MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The AddMessage subroutine just 1. checked if all the parameters were passed 2. inserted the message in the DB 3. logged the action if needed These 3 jobs are now done by the overloaded store method of Koha::Patron::Message. Test plan: 1/ Go on the "check out" page of a patron 2/ Add different new messages Signed-off-by: Marc Véron Signed-off-by: Brendan A Gallagher --- C4/Members.pm | 29 ----------------------------- circ/add_message.pl | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 98e9fc50c4..6d23a4c643 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -96,7 +96,6 @@ BEGIN { &GetExpiryDate &GetUpcomingMembershipExpires - &AddMessage &DeleteMessage &GetMessages &GetMessagesCount @@ -2134,34 +2133,6 @@ sub ModPrivacy { privacy => $privacy ); } -=head2 AddMessage - - AddMessage( $borrowernumber, $message_type, $message, $branchcode ); - -Adds a message to the messages table for the given borrower. - -Returns: - True on success - False on failure - -=cut - -sub AddMessage { - my ( $borrowernumber, $message_type, $message, $branchcode ) = @_; - - my $dbh = C4::Context->dbh; - - if ( ! ( $borrowernumber && $message_type && $message && $branchcode ) ) { - return; - } - - my $query = "INSERT INTO messages ( borrowernumber, branchcode, message_type, message ) VALUES ( ?, ?, ?, ? )"; - my $sth = $dbh->prepare($query); - $sth->execute( $borrowernumber, $branchcode, $message_type, $message ); - logaction("MEMBERS", "ADDCIRCMESSAGE", $borrowernumber, $message) if C4::Context->preference("BorrowersLog"); - return 1; -} - =head2 GetMessages GetMessages( $borrowernumber, $type ); diff --git a/circ/add_message.pl b/circ/add_message.pl index 912314a88c..e0ffc409f2 100755 --- a/circ/add_message.pl +++ b/circ/add_message.pl @@ -17,20 +17,13 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use strict; -use warnings; +use Modern::Perl; use CGI qw ( -utf8 ); -use C4::Context; use C4::Auth; use C4::Output; -use C4::Members; -use C4::Accounts; -use C4::Stats; -use C4::Koha; -use C4::Overdues; -use C4::Branch; # GetBranches +use Koha::Patron::Message; my $input = new CGI; @@ -49,7 +42,14 @@ my $branchcode = $input->param('branchcode'); my $message_type = $input->param('message_type'); my $borrower_message = $input->param('borrower_message'); -AddMessage( $borrowernumber, $message_type, $borrower_message, $branchcode ); +Koha::Patron::Message->new( + { + borrowernumber => $borrowernumber, + branchcode => $branchcode, + message_type => $message_type, + message => $borrower_message, + } +); print $input->redirect( "/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber"); -- 2.39.5