Bug 30813: Adjust TransformMarcToKoha to take kohafields parameter
[koha-ffzg.git] / C4 / Letters.pm
index 58e6293..8ab0bb7 100644 (file)
@@ -40,6 +40,8 @@ use Koha::Patrons;
 use Koha::SMTP::Servers;
 use Koha::Subscriptions;
 
+use constant SERIALIZED_EMAIL_CONTENT_TYPE => 'message/rfc822';
+
 our (@ISA, @EXPORT_OK);
 BEGIN {
     require Exporter;
@@ -527,56 +529,6 @@ sub SendAlerts {
                 . $letter->{content}
         ) if C4::Context->preference("ClaimsLog");
     }
-   # send an "account details" notice to a newly created user
-    elsif ( $type eq 'members' ) {
-        my $library = Koha::Libraries->find( $externalid->{branchcode} );
-        my $letter = GetPreparedLetter (
-            module => 'members',
-            letter_code => $letter_code,
-            branchcode => $externalid->{'branchcode'},
-            lang       => $externalid->{lang} || 'default',
-            tables => {
-                'branches'    => $library->unblessed,
-                'borrowers' => $externalid->{'borrowernumber'},
-            },
-            substitute => { 'borrowers.password' => $externalid->{'password'} },
-            want_librarian => 1,
-        ) or return;
-        return { error => "no_email" } unless $externalid->{'emailaddr'};
-
-        my $success = try {
-
-            # FIXME: This 'default' behaviour should be moved to Koha::Email
-            my $mail = Koha::Email->create(
-                {
-                    to       => $externalid->{'emailaddr'},
-                    from     => $library->branchemail,
-                    reply_to => $library->branchreplyto,
-                    sender   => $library->branchreturnpath,
-                    subject  => "" . $letter->{'title'},
-                }
-            );
-
-            if ( $letter->{is_html} ) {
-                $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) );
-            }
-            else {
-                $mail->text_body( $letter->{content} );
-            }
-
-            $mail->send_or_die({ transport => $library->smtp_server->transport });
-        }
-        catch {
-            # We expect ref($_) eq 'Email::Sender::Failure'
-            $error = $_->message;
-
-            carp "$_";
-            return;
-        };
-
-        return { error => $error }
-            unless $success;
-    }
 
     # If we come here, return an OK status
     return 1;
@@ -647,6 +599,7 @@ sub GetPreparedLetter {
 
     if (%$substitute) {
         while ( my ($token, $val) = each %$substitute ) {
+            $val //= q{};
             if ( $token eq 'items.content' ) {
                 $val =~ s|\n|<br/>|g if $letter->{is_html};
             }
@@ -799,6 +752,7 @@ sub _parseletter_sth {
     ($table eq 'serial') ? "SELECT * FROM $table WHERE serialid = ?" :
     ($table eq 'problem_reports') ? "SELECT * FROM $table WHERE reportid = ?" :
     ($table eq 'additional_contents' || $table eq 'opac_news') ? "SELECT * FROM additional_contents WHERE idnew = ?" :
+    ($table eq 'recalls') ? "SELECT * FROM $table WHERE recall_id = ?" :
     undef ;
     unless ($query) {
         warn "ERROR: No _parseletter_sth query for table '$table'";
@@ -871,8 +825,9 @@ sub _parseletter {
                     $dateonly = $1 unless $dateonly;
                 }
                 my $replacedby_date = eval {
-                    output_pref({ dt => dt_from_string( $replacedby ), dateonly => $dateonly });
+                    output_pref({ dt => scalar dt_from_string( $replacedby ), dateonly => $dateonly });
                 };
+                $replacedby_date //= q{};
 
                 if ( $letter->{ $letter_field } ) {
                     $letter->{ $letter_field } =~ s/\Q<<$table.$field$filter_string_used>>\E/$replacedby_date/g;
@@ -1230,7 +1185,7 @@ sub ResendMessage {
   This routine picks the I<content> of I<letter> and generates a MIME
   email, attaching the passed I<attachments> using Koha::Email. The
   content is replaced by the string representation of the MIME object,
-  and the content-type is updated to B<MIME> for later handling.
+  and the content-type is updated for later handling.
 
 =cut
 
@@ -1259,7 +1214,7 @@ sub _add_attachments {
         );
     }
 
-    $letter->{'content-type'} = 'MIME';
+    $letter->{'content-type'} = SERIALIZED_EMAIL_CONTENT_TYPE;
     $letter->{content} = $message->as_string;
 
     return $letter;
@@ -1409,7 +1364,7 @@ sub _send_message_by_email {
             subject  => "" . $message->{subject}
         };
 
-        if ( $message->{'content_type'} && $message->{'content_type'} eq 'MIME' ) {
+        if ( $message->{'content_type'} && $message->{'content_type'} eq SERIALIZED_EMAIL_CONTENT_TYPE ) {
 
             # The message has been previously composed as a valid MIME object
             # and serialized as a string on the DB