]> 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:04:06 +0000 (02:04 +0000)
committerlpsolit%gmail.com <>
Fri, 14 Jul 2006 02:04:06 +0000 (02:04 +0000)
importxml.pl

index 6ed2727ea47478394dd3780241c7a1d8d7de5f4e..dbcc72f1c7122c657c7709a61ca2443fe5cb9db8 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
 );
 
@@ -365,14 +367,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');
@@ -1212,6 +1224,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