Bug 22778: Suggestions with no "suggester" can cause errors
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 25 Apr 2019 19:50:35 +0000 (15:50 -0400)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 14 Apr 2020 07:19:21 +0000 (08:19 +0100)
If one tries to modify a suggestion that has no suggester you will get the following error:

Can't call method "lang" on an undefined value at /usr/share/koha/lib/C4/Suggestions.pm line 506

Koha assumes that every suggestion has a borrowernumber in suggestedby

Test Plan:
1) Create a suggestion with an unpopulated suggestedby
2) Attempt to modify that suggestion
3) Note the error
4) Apply this patch
5) Restart all teh things
6) Attempt to modify that suggestion
7) No error!

Signed-off-by: David Roberts <david@koha-ptfs.co.uk>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/Suggestions.pm

index 8d53360..5102421 100644 (file)
@@ -527,10 +527,11 @@ sub ModSuggestion {
     };
     return 0 if $@;
 
-    if ( $suggestion->{STATUS} ) {
+    if ( $suggestion->{STATUS} && $suggestion_object->suggestedby ) {
 
         # fetch the entire updated suggestion so that we can populate the letter
         my $full_suggestion = GetSuggestion( $suggestion->{suggestionid} );
+
         my $patron = Koha::Patrons->find( $full_suggestion->{suggestedby} );
 
         my $transport = (C4::Context->preference("FallbackToSMSIfNoEmail")) && ($patron->smsalertnumber) && (!$patron->email) ? 'sms' : 'email';