]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 344298: importxml.pl performance problem - Patch by Vance Baarda <vrb@novell...
authorlpsolit%gmail.com <>
Fri, 14 Jul 2006 02:06:15 +0000 (02:06 +0000)
committerlpsolit%gmail.com <>
Fri, 14 Jul 2006 02:06:15 +0000 (02:06 +0000)
importxml.pl

index 2040678e4258cd92fa9dea0399a1e9760e7cbd03..82582f78d7100b8a1b5ab8f6f46708c75708cbbb 100755 (executable)
@@ -100,11 +100,13 @@ Bugzilla->batch(1);
 
 my $debug = 0;
 my $mail  = '';
+my $attach_path = '';
 my $help  = 0;
 
 my $result = GetOptions(
     "verbose|debug+" => \$debug,
     "mail|sendmail!" => \$mail,
+    "attach_path=s"  => \$attach_path,
     "help|?"         => \$help
 );
 
@@ -401,14 +403,24 @@ sub process_attachment() {
     $attachment{'isprivate'}  = $attach->{'att'}->{'isprivate'} || 0;
     $attachment{'filename'}   = $attach->field('filename') || "file";
     # Attachment data is not exported in versions 2.20 and older.
-    if (defined $attach->first_child('data')
-        && defined $attach->first_child('data')->{'att'}->{'encoding'}
-        && $attach->first_child('data')->{'att'}->{'encoding'} =~ /base64/ )
-    {
-        # decode the base64
-        my $data   = $attach->field('data');
-        my $output = decode_base64($data);
-        $attachment{'data'} = $output;
+    if (defined $attach->first_child('data') &&
+            defined $attach->first_child('data')->{'att'}->{'encoding'}) {
+        my $encoding = $attach->first_child('data')->{'att'}->{'encoding'};
+        if ($encoding =~ /base64/) {
+            # decode the base64
+            my $data   = $attach->field('data');
+            my $output = decode_base64($data);
+            $attachment{'data'} = $output;
+        }
+        elsif ($encoding =~ /filename/) {
+            # read the attachment file
+            Error("attach_path is required", undef) unless ($attach_path);
+            my $attach_filename = $attach_path . "/" . $attach->field('data');
+            open(ATTACH_FH, $attach_filename) or
+                Error("cannot open $attach_filename", undef);
+            $attachment{'data'} = do { local $/; <ATTACH_FH> };
+            close ATTACH_FH;
+        }
     }
     else {
         $attachment{'data'} = $attach->field('data');
@@ -1248,6 +1260,8 @@ importxml - Import bugzilla bug data from xml.
        -v --verbose     print error and debug information. 
                         Mulltiple -v increases verbosity
        -m --sendmail    send mail to recipients with log of bugs imported
+       --attach_path    The path to the attachment files.
+                        (Required if encoding="filename" is used for attachments.)
 
 =head1 OPTIONS