Bugzilla – Attachment 47092 Details for
Bug 15632
Move the messages related code to Koha::Patron::Messages
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15632: Koha::Patron::Messages - Be sure add and delete will log
Bug-15632-KohaPatronMessages---Be-sure-add-and-del.patch (text/plain), 4.76 KB, created by
Jonathan Druart
on 2016-01-21 09:35:16 UTC
(
hide
)
Description:
Bug 15632: Koha::Patron::Messages - Be sure add and delete will log
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-01-21 09:35:16 UTC
Size:
4.76 KB
patch
obsolete
>From 83ee665c6a5d8a5ce8501d658dd0b9106ff3968a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 20 Jan 2016 17:56:07 +0000 >Subject: [PATCH] Bug 15632: Koha::Patron::Messages - Be sure add and delete > will log > >If the pref BorrowersLog is on, the store and delete method should log >into the action_logs table. >Easy to do by overloading them. >--- > Koha/Patron/Message.pm | 35 +++++++++++++++++++++++++++++++++++ > t/db_dependent/Koha/Patron/Messages.t | 24 ++++++++++++++++++++++-- > 2 files changed, 57 insertions(+), 2 deletions(-) > >diff --git a/Koha/Patron/Message.pm b/Koha/Patron/Message.pm >index dfe3d82..501e6ee 100644 >--- a/Koha/Patron/Message.pm >+++ b/Koha/Patron/Message.pm >@@ -19,6 +19,9 @@ use Modern::Perl; > > use Carp; > >+use C4::Context; >+use C4::Log qw( logaction ); >+ > use Koha::Database; > > use base qw(Koha::Object); >@@ -33,6 +36,38 @@ Koha::Patron::Message - Koha Message Object class > > =cut > >+=head3 store >+ >+=cut >+ >+sub store { >+ my ($self) = @_; >+ >+ # This should be done at the DB level >+ return unless $self->borrowernumber >+ and $self->message >+ and $self->message_type >+ and $self->branchcode; >+ >+ C4::Log::logaction( "MEMBERS", "ADDCIRCMESSAGE", $self->borrowernumber, $self->message ) >+ if C4::Context->preference("BorrowersLog"); >+ >+ return $self->SUPER::store($self); >+} >+ >+=head3 delete >+ >+=cut >+ >+sub delete { >+ my ($self) = @_; >+ >+ C4::Log::logaction("MEMBERS", "DELCIRCMESSAGE", $self->borrowernumber, $self->message) >+ if C4::Context->preference("BorrowersLog"); >+ >+ return $self->SUPER::delete($self); >+} >+ > =head3 type > > =cut >diff --git a/t/db_dependent/Koha/Patron/Messages.t b/t/db_dependent/Koha/Patron/Messages.t >index 9cab130..22bf694 100644 >--- a/t/db_dependent/Koha/Patron/Messages.t >+++ b/t/db_dependent/Koha/Patron/Messages.t >@@ -19,8 +19,10 @@ > > use Modern::Perl; > >-use Test::More tests => 4; >+use Test::More tests => 9; > >+use C4::Context; >+use C4::Log; > use Koha::Patron::Message; > use Koha::Patron::Messages; > use Koha::Database; >@@ -33,7 +35,10 @@ $schema->storage->txn_begin; > my $builder = t::lib::TestBuilder->new; > my $library = $builder->build( { source => 'Branch' } ); > my $patron = $builder->build( { source => 'Borrower', values => { branchcode => $library->{branchcode} } } ); >+my $nb_of_logaction = get_nb_of_logactions(); > my $nb_of_messages = Koha::Patron::Messages->search->count; >+ >+C4::Context->set_preference('BorrowersLog', 0); > my $new_message_1 = Koha::Patron::Message->new( > { borrowernumber => $patron->{borrowernumber}, > branchcode => $library->{branchcode}, >@@ -41,6 +46,9 @@ my $new_message_1 = Koha::Patron::Message->new( > message => 'my message 1', > } > )->store; >+is( get_nb_of_logactions(), $nb_of_logaction, 'With BorrowersLog off, no new log should have been added' ); >+ >+C4::Context->set_preference('BorrowersLog', 1); > my $new_message_2 = Koha::Patron::Message->new( > { borrowernumber => $patron->{borrowernumber}, > branchcode => $library->{branchcode}, >@@ -48,6 +56,7 @@ my $new_message_2 = Koha::Patron::Message->new( > message => 'my message 2', > } > )->store; >+is( get_nb_of_logactions(), $nb_of_logaction + 1, 'With BorrowersLog on, 1 new log should have been added when adding a new message' ); > > like( $new_message_1->message_id, qr|^\d+$|, 'Adding a new message should have set the message_id'); > is( Koha::Patron::Messages->search->count, $nb_of_messages + 2, 'The 2 messages should have been added' ); >@@ -55,9 +64,20 @@ is( Koha::Patron::Messages->search->count, $nb_of_messages + 2, 'The 2 messages > my $retrieved_message_1 = Koha::Patron::Messages->find( $new_message_1->message_id ); > is( $retrieved_message_1->message, $new_message_1->message, 'Find a message by id should return the correct message' ); > >+C4::Context->set_preference('BorrowersLog', 0); > $retrieved_message_1->delete; >-is( Koha::Patron::Messages->search->count, $nb_of_messages + 1, 'Delete should have deleted the message' ); >+is( Koha::Patron::Messages->search->count, $nb_of_messages + 1, 'Delete should have deleted the message 1' ); >+is( get_nb_of_logactions(), $nb_of_logaction + 1, 'With BorrowersLog off, no new log should have been added when deleting a new message' ); >+ >+C4::Context->set_preference('BorrowersLog', 1); >+$new_message_2->delete; >+is( Koha::Patron::Messages->search->count, $nb_of_messages, 'Delete should have deleted the message 2' ); >+is( get_nb_of_logactions(), $nb_of_logaction + 2, 'With BorrowersLog on, 1 new log should have been added when deleting a new message' ); > > $schema->storage->txn_rollback; > >+sub get_nb_of_logactions { >+ return scalar( @{ C4::Log::GetLogs( undef, undef, undef, ['MEMBERS'] ) } ); >+} >+ > 1; >-- >2.1.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15632
:
47091
|
47092
|
47093
|
47094
|
47095
|
47096
|
47097
|
47515
|
47516
|
47525
|
47571
|
47572
|
47573
|
47574
|
47575
|
47580
|
47581
|
47582
|
47583
|
47584
|
47585
|
47586
|
47587
|
48004
|
48009
|
48010
|
48011
|
48012
|
48013
|
48014
|
48015
|
48016
|
48017
|
48018
|
48020
|
48422
|
48423
|
48424
|
48425
|
48426
|
48427
|
48591
|
48592
|
48593