Bug 10845: Multi transport types for holds
authorJonathan Druart <jonathan.druart@biblibre.com>
Mon, 9 Sep 2013 14:58:22 +0000 (16:58 +0200)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 2 May 2014 20:29:19 +0000 (20:29 +0000)
The HOLD_PRINT and HOLD_PHONE notices become useless.
This patch modifies existing notices in order to group them into the
main notice type 'HOLD', with any pre-existing print and phone
templates in the appropriate places.

Test plan:
- Apply the patch and execute the update database entry.
- Verify that your previous HOLD_PHONE and HOLD_PRINT are displayed
  when editing the HOLD notice (under phone and print).
- Choose a patron and check SMS, email, phone for "Hold filled"
  (on the patron messaging preferences).
- Place a hold.
- Check the item in and confirm the hold.
- If the patron has an email *and* a SMS number, 2 new messages are put
  into the  message_queue table: 1 sms and 1 email.
  If the patron does not have 1 of them, there are 2 new messages: 1
  sms/email and 1 print.
  If the user has neither of them, there is 1 new message: 1 print.
- The generated messages should correspond with the notices defined,
  depending the message transport type.

Signed-off-by: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Just noting that if email and SMS are disabled in the msg prefs, the user
will not have a print message.
And if the SMS driver fails, the record status in message_queue is 'failed',
but staff may not be aware of that.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
C4/Reserves.pm
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/help/tools/letter.tt
misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl

index 49f8c11..6c06e2c 100644 (file)
@@ -1890,15 +1890,11 @@ sub _koha_notify_reserve {
     
     # Try to get the borrower's email address
     my $to_address = C4::Members::GetNoticeEmailAddress($borrowernumber);
-    
-    my $letter_code;
-    my $print_mode = 0;
-    my $messagingprefs;
-    if ( $to_address || $borrower->{'smsalertnumber'} ) {
-        $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber, message_name => 'Hold_Filled' } );
-    } else {
-        $print_mode = 1;
-    }
+
+    my $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( {
+            borrowernumber => $borrowernumber,
+            message_name => 'Hold_Filled'
+    } );
 
     my $sth = $dbh->prepare("
         SELECT *
@@ -1925,43 +1921,23 @@ sub _koha_notify_reserve {
         substitute => { today => C4::Dates->new()->output() },
     );
 
-
-    if ( $print_mode ) {
-        $letter_params{ 'letter_code' } = 'HOLD_PRINT';
-        my $letter =  C4::Letters::GetPreparedLetter ( %letter_params ) or die "Could not find a letter called '$letter_params{'letter_code'}' in the 'reserves' module";
+    my $print_sent = 0;
+    while ( my ( $mtt, $letter_code ) = each %{ $messagingprefs->{transports} } ) {
+        if ( ($mtt eq 'email' and not $to_address) or ($mtt eq 'sms' and not $borrower->{smsalertnumber}) ) {
+            # email or sms is requested but not exist, do a print.
+            $mtt = 'print';
+        }
+        $letter_params{letter_code} = $letter_code;
+        $letter_params{message_transport_type} = $mtt;
+        my $letter =  C4::Letters::GetPreparedLetter ( %letter_params )
+            or die "Could not find a letter called '$letter_params{'letter_code'}' in the 'reserves' module";
 
         C4::Letters::EnqueueLetter( {
             letter => $letter,
             borrowernumber => $borrowernumber,
-            message_transport_type => 'print',
+            from_address => $admin_email_address,
+            message_transport_type => $mtt,
         } );
-        
-        return;
-    }
-
-    if ( $to_address && defined $messagingprefs->{transports}->{'email'} ) {
-        $letter_params{ 'letter_code' } = $messagingprefs->{transports}->{'email'};
-        my $letter =  C4::Letters::GetPreparedLetter ( %letter_params ) or die "Could not find a letter called '$letter_params{'letter_code'}' in the 'reserves' module";
-
-        C4::Letters::EnqueueLetter(
-            {   letter                 => $letter,
-                borrowernumber         => $borrowernumber,
-                message_transport_type => 'email',
-                from_address           => $admin_email_address,
-            }
-        );
-    }
-
-    if ( $borrower->{'smsalertnumber'} && defined $messagingprefs->{transports}->{'sms'} ) {
-        $letter_params{ 'letter_code' } = $messagingprefs->{transports}->{'sms'};
-        my $letter =  C4::Letters::GetPreparedLetter ( %letter_params ) or die "Could not find a letter called '$letter_params{'letter_code'}' in the 'reserves' module";
-
-        C4::Letters::EnqueueLetter(
-            {   letter                 => $letter,
-                borrowernumber         => $borrowernumber,
-                message_transport_type => 'sms',
-            }
-        );
     }
 }
 
index 433e70f..af7cbc6 100755 (executable)
@@ -8295,6 +8295,26 @@ if ( CheckVersion($DBversion) ) {
 }
 
 
+
+
+
+
+$DBversion = "3.15.00.XXX";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q|
+        UPDATE message_transports SET letter_code='HOLD' WHERE letter_code='HOLD_PHONE' OR letter_code='HOLD_PRINT'
+    |);
+    $dbh->do(q|
+        UPDATE letter SET code='HOLD', message_transport_type='print' WHERE code='HOLD_PRINT'
+    |);
+    $dbh->do(q|
+        UPDATE letter SET code='HOLD', message_transport_type='phone' WHERE code='HOLD_PHONE'
+    |);
+    print "Upgrade to $DBversion done (Bug 10845: Multi transport types for holds)\n";
+    SetVersion($DBversion);
+}
+
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
index 2f1f9d3..18d90a1 100644 (file)
     <li>When this notice references the branches table it is referring to the pickup library information.</li>
 </ul>
 </li>
-       <li>HOLD_PRINT (Printed notice when hold available for pickup)
-<ul>
-       <li>This notice is used for hold confirmation notices that are sent out in print format. This will not effect what the email notice looks like.</li>
-    <li>When this notice references the branches table it is referring to the pickup library information.</li>
-</ul>
-</li>
        <li>ODUE (Overdue Notice)
 <ul>
        <li>This notice is used to send Overdue Notices to Patrons</li>
 
 <p><strong>See the full documentation for Notices in the <a href="http://manual.koha-community.org/[% helpVersion %]/en/notices.html">manual</a> (online).</strong></p>
 
-[% INCLUDE 'help-bottom.inc' %]
\ No newline at end of file
+[% INCLUDE 'help-bottom.inc' %]
index b4d4e9c..42728d6 100755 (executable)
@@ -70,7 +70,7 @@ my $type_module_map = {
 my $type_notice_map = {
     'PREOVERDUE' => 'PREDUE_PHONE',
     'OVERDUE'    => 'OVERDUE_PHONE',
-    'RESERVE'    => 'HOLD_PHONE',
+    'RESERVE'    => 'HOLD',
 };
 
 GetOptions(
@@ -133,7 +133,8 @@ foreach my $type (@types) {
             tables      => {
                 borrowers   => $issues->{'borrowernumber'},
                 biblio      => $issues->{'biblionumber'},
-                biblioitems => $issues->{'biblionumber'}
+                biblioitems => $issues->{'biblionumber'},
+                message_transport_type => 'phone',
             },
         );