Bugzilla – Attachment 63808 Details for
Bug 17499
Koha objects for messaging preferences
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17499: Simplify searching by message_name
Bug-17499-Simplify-searching-by-messagename.patch (text/plain), 5.83 KB, created by
Marc Véron
on 2017-05-29 12:34:40 UTC
(
hide
)
Description:
Bug 17499: Simplify searching by message_name
Filename:
MIME Type:
Creator:
Marc Véron
Created:
2017-05-29 12:34:40 UTC
Size:
5.83 KB
patch
obsolete
>From b3d3e61d34e4d7d59baa784c6bca9676de1621c2 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@jns.fi> >Date: Tue, 8 Nov 2016 13:29:07 +0200 >Subject: [PATCH] Bug 17499: Simplify searching by message_name >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch adds optional search & find parameter message_name for >Koha::Patron::Message::Preferences->search and ->find. This simplifies object >usage by allowing us to skip joins or finding the attribute id ourselves. > >prove -v t/db_dependent/Koha/Patron/Message/Preferences.t turns green >Signed-off-by: Marc Véron <veron@veron.ch> >--- > Koha/Patron/Message/Preference.pm | 27 +++++++++++- > Koha/Patron/Message/Preferences.pm | 55 ++++++++++++++++++++++++ > t/db_dependent/Koha/Patron/Message/Preferences.t | 23 +++++++++- > 3 files changed, 101 insertions(+), 4 deletions(-) > >diff --git a/Koha/Patron/Message/Preference.pm b/Koha/Patron/Message/Preference.pm >index c7e2b95..1df44af 100644 >--- a/Koha/Patron/Message/Preference.pm >+++ b/Koha/Patron/Message/Preference.pm >@@ -156,6 +156,28 @@ sub new_from_default { > return $self; > } > >+=head3 message_name >+ >+$preference->message_name >+ >+Gets message_name for this messaging preference. >+ >+Setter not implemented. >+ >+=cut >+ >+sub message_name { >+ my ($self) = @_; >+ >+ if ($self->{'_message_name'}) { >+ return $self->{'_message_name'}; >+ } >+ $self->{'_message_name'} = Koha::Patron::Message::Attributes->find({ >+ message_attribute_id => $self->message_attribute_id, >+ })->message_name; >+ return $self->{'_message_name'}; >+} >+ > =head3 message_transport_types > > $preference->message_transport_types >@@ -385,8 +407,9 @@ sub _validate_message_transport_types { > is_digest => $tmp->{'wants_digest'}, > })) { > Koha::Exceptions::BadParameter->throw( >- error => "Message transport option for '$type' (". >- ($tmp->{'wants_digest'} ? 'digest':'no digest').") does not exist", >+ error => "Message transport option '$type' (". >+ ($tmp->{'wants_digest'} ? 'digest':'no digest').") for ". >+ $self->message_name . 'does not exist', > parameter => 'message_transport_type', > ); > } >diff --git a/Koha/Patron/Message/Preferences.pm b/Koha/Patron/Message/Preferences.pm >index bf3d14c..34af5e0 100644 >--- a/Koha/Patron/Message/Preferences.pm >+++ b/Koha/Patron/Message/Preferences.pm >@@ -20,6 +20,7 @@ package Koha::Patron::Message::Preferences; > use Modern::Perl; > > use Koha::Database; >+use Koha::Patron::Message::Attributes; > use Koha::Patron::Message::Preference; > use Koha::Patron::Message::Transports; > >@@ -35,6 +36,32 @@ Koha::Patron::Message::Preferences - Koha Patron Message Preferences object clas > > =cut > >+=head3 find_with_message_name >+ >+Koha::Patron::Message::Preferences->find_with_message_name({ >+ borrowernumber => 123, >+ message_name => 'Hold_Filled', >+}); >+ >+Converts C<message_name> into C<message_attribute_id> and continues find. >+ >+=cut >+ >+sub find_with_message_name { >+ my ($self, $id) = @_; >+ >+ if (ref($id) eq "HASH" && $id->{'message_name'}) { >+ my $attr = Koha::Patron::Message::Attributes->find({ >+ message_name => $id->{'message_name'}, >+ }); >+ $id->{'message_attribute_id'} = ($attr) ? >+ $attr->message_attribute_id : undef; >+ delete $id->{'message_name'}; >+ } >+ >+ return $self->SUPER::find($id); >+} >+ > =head3 get_options > > my $messaging_options = Koha::Patron::Message::Preferences->get_options >@@ -69,6 +96,34 @@ sub get_options { > return \@return; > } > >+=head3 search >+ >+Koha::Patron::Message::Preferences->search_with_message_name({ >+ borrowernumber => 123, >+ message_name => 'Hold_Filled', >+}); >+ >+Converts C<message_name> into C<message_attribute_id> and continues search. Use >+Koha::Patron::Message::Preferences->search with a proper join for more complicated >+searches. >+ >+=cut >+ >+sub search_with_message_name { >+ my ($self, $params, $attributes) = @_; >+ >+ if (ref($params) eq "HASH" && $params->{'message_name'}) { >+ my $attr = Koha::Patron::Message::Attributes->find({ >+ message_name => $params->{'message_name'}, >+ }); >+ $params->{'message_attribute_id'} = ($attr) ? >+ $attr->message_attribute_id : undef; >+ delete $params->{'message_name'}; >+ } >+ >+ return $self->SUPER::search($params, $attributes); >+} >+ > =head3 type > > =cut >diff --git a/t/db_dependent/Koha/Patron/Message/Preferences.t b/t/db_dependent/Koha/Patron/Message/Preferences.t >index 0c98222..8f5626a 100644 >--- a/t/db_dependent/Koha/Patron/Message/Preferences.t >+++ b/t/db_dependent/Koha/Patron/Message/Preferences.t >@@ -19,8 +19,7 @@ > > use Modern::Perl; > >- >-use Test::More tests => 6; >+use Test::More tests => 7; > > use t::lib::Mocks; > use t::lib::TestBuilder; >@@ -320,6 +319,26 @@ subtest 'Test Koha::Patron::Message::Preference->message_transport_types' => sub > }; > }; > >+subtest 'Test Koha::Patron::Message::Preference->message_name' => sub { >+ plan tests => 1; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = build_a_test_patron(); >+ my $attribute = build_a_test_attribute(); >+ my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({ >+ patron => $patron, >+ attr => $attribute, >+ }); >+ my $message_name_pref = Koha::Patron::Message::Preferences->search_with_message_name({ >+ borrowernumber => $patron->{'borrowernumber'}, >+ message_name => $attribute->message_name, >+ })->next; >+ is($message_name_pref->message_name, $attribute->message_name, "Found preference with message_name"); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'Test adding a new preference with invalid parameters' => sub { > plan tests => 4; > >-- >2.1.4
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 17499
:
63427
|
63428
|
63429
|
63430
|
63431
|
63432
|
63433
|
63434
|
63786
|
63787
|
63788
|
63789
|
63790
|
63791
|
63792
|
63793
|
63801
|
63802
|
63803
|
63804
|
63805
|
63806
|
63807
|
63808
|
63809
|
63810
|
63811
|
63812
|
63878
|
63895
|
64035
|
64036
|
64037
|
64038
|
64039
|
64040
|
64041
|
64042
|
64043
|
64044
|
64795
|
66686
|
69434
|
69435
|
69458
|
91864
|
93863
|
93865
|
93872
|
94748
|
99479
|
99634
|
99668
|
99669
|
99670
|
103441
|
103442
|
103443
|
106653
|
106654
|
106655
|
106656
|
106657
|
107612
|
107613
|
107614
|
107615
|
107616
|
113010
|
113011
|
113127
|
113129
|
113686
|
113687
|
113765
|
113766
|
113767
|
113768
|
118452
|
118453
|
119470
|
119471
|
119472
|
119473
|
119474
|
119475
|
119476
|
119477
|
119478
|
119479
|
119480
|
119481
|
119482
|
119483
|
119484
|
119485
|
119486
|
119487
|
119488
|
119489
|
119490
|
119491
|
141408
|
141409
|
141410
|
141411
|
141412
|
141413
|
141414
|
141415
|
141416
|
141417
|
141418
|
146529
|
146530
|
146531
|
146532
|
146533
|
146534
|
146535
|
146536
|
146537
|
146538
|
146539
|
146540
|
151900
|
151901
|
151902
|
151903
|
151904
|
151905
|
151906
|
151907
|
151908
|
151909
|
151910
|
151911
|
151937
|
151938
|
151939
|
151940
|
151941
|
151942
|
151943
|
151944
|
151945
|
151946
|
151947
|
151948
|
155365
|
155366
|
155367
|
155368
|
155369
|
155370
|
155371
|
155372
|
155373
|
155374
|
155375
|
155376