rt 4.2.13 ticket#13852
[freeside.git] / rt / sbin / rt-fulltext-indexer.in
index bd55adb..ceffc97 100644 (file)
@@ -3,7 +3,7 @@
 #
 # COPYRIGHT:
 #
-# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
 #                                          <sales@bestpractical.com>
 #
 # (Except where explicitly superseded by other copyright notices)
@@ -99,6 +99,8 @@ if ( !flock main::DATA, LOCK_EX | LOCK_NB ) {
     }
 }
 
+my $max_size = RT->Config->Get('MaxFulltextAttachmentSize');
+
 my $db_type = RT->Config->Get('DatabaseType');
 my $fts_config = $ENV{RT_FTS_CONFIG} ? JSON::from_json($ENV{RT_FTS_CONFIG})
     : RT->Config->Get('FullTextSearch') || {};
@@ -201,8 +203,16 @@ sub process_bulk_insert {
         my ($attachments) = @_;
         my @insert;
         my $found = 0;
+
         while ( my $a = $attachments->Next ) {
             debug("Found attachment #". $a->id );
+            if ( $max_size and $a->ContentLength > $max_size ){
+                debug("Attachment #" . $a->id . " is " . $a->ContentLength .
+                      " bytes which is larger than configured MaxFulltextAttachmentSize " .
+                      " of " . $max_size . ", skipping");
+                next;
+            }
+
             my $text = $a->Content // "";
             HTML::Entities::decode_entities($text) if $a->ContentType eq "text/html";
             push @insert, $text, $a->id;
@@ -304,9 +314,17 @@ sub process_pg_update {
     attachment_loop( sub {
         my ($attachments) = @_;
         my @insert;
+
         while ( my $a = $attachments->Next ) {
             debug("Found attachment #". $a->id );
 
+            if ( $max_size and $a->ContentLength > $max_size ){
+                debug("Attachment #" . $a->id . " is " . $a->ContentLength .
+                      " bytes which is larger than configured MaxFulltextAttachmentSize " .
+                      " of " . $max_size . ", skipping");
+                next;
+            }
+
             my $text = $a->Content // "";
             HTML::Entities::decode_entities($text) if $a->ContentType eq "text/html";