[rt-devel] Using RT with HTML::Mason::ApacheHandler( args_method => 'mod_perl' )

Alexei Barantsev barancev at kazbek.ispras.ru
Wed Feb 20 04:19:48 EST 2002


Hello,

Use of RT with (args_method => 'CGI') and (args_method => 'mod_perl') differ
in attachments uploading. The matter is that you cannot call $m->cgi_object
if you use (args_method => 'mod_perl'). You should use Apache::Request to
upload attachments instead of CGI object.

Here is a patch that manages RT to work with both CGI and mod_perl methods.

<LYRICAL_DIGRESSION>
Why do I need (args_method => 'mod_perl'), why don't use suggested by
default (args_method => 'CGI')? I'm not a performance crazy. The reason is
that I have installed RT on the site where Mason works already for a long
time with (args_method => 'mod_perl'). You know that this is an option of
module import. So if the module has already loaded from main server
configuration with (args_method => 'mod_perl') I can't change this setting.
May be it is possible to change this on per-VirtualHost or per-request
basis? Any suggestions would be greatly appeciated.
</LYRICAL_DIGRESSION>

bash$ diff -u ~/original/rt-2-0-12-pre4/lib/RT/Interface/Web.pm
/usr/local/rt2/lib/RT/Interface/Web.pm
--- /home/barancev/original/rt-2-0-12-pre4/lib/RT/Interface/Web.pm      Tue
Feb 19 02:00:19 2002
+++ /usr/local/rt2/lib/RT/Interface/Web.pm      Wed Feb 20 11:14:57 2002
@@ -317,11 +317,14 @@
         Data    => [ $args{'Body'} ]
     );

-    my $cgi_object = CGIObject();
-    if ( $cgi_object->param( $args{'AttachmentFieldName'} ) ) {
-
-        my $cgi_filehandle =
-          $cgi_object->upload( $args{'AttachmentFieldName'} );
+    my ($cgi_object, $ar);
+    if ($HTML::Mason::ApacheHandler::ARGS_METHOD eq '_cgi_args') {
+        $cgi_object = CGIObject();
+    } else {
+        use Apache::Request;
+        $ar = new Apache::Request($r);
+    }
+    if ( ($cgi_object || $ar)->param( $args{'AttachmentFieldName'} ) ) {

         use File::Temp qw(tempfile tempdir);

@@ -333,22 +336,33 @@

         # We're having trouble with tempfiles not getting created. Let's
try it with
         # a scalar instead
+
+        my ($filehandle, $filename, $content_type);
+        if ($cgi_object) {
+            $filehandle = $cgi_object->upload(
$args{'AttachmentFieldName'} );
+            $filename = "$filehandle";
+            my $uploadinfo = $cgi_object->uploadInfo($filehandle);
+            $content_type = $upload->info('Content-Type');
+        } else {
+            my $upload = $ar->upload($args{'AttachmentFieldName'});
+            $filehandle = $upload->fh;
+            $filename = $upload->filename;
+            $content_type = $upload->info('Content-Type');
+        }

         my ($buffer, at file);

-        while ( my $bytesread = read( $cgi_filehandle, $buffer, 4096 ) ) {
+        while ( my $bytesread = read( $filehandle, $buffer, 4096 ) ) {
             push(@file, $buffer);
         }

         $RT::Logger->debug($file);
-        my $filename = "$cgi_filehandle";
         $filename =~ s#^(.*)/##;
-        my $uploadinfo = $cgi_object->uploadInfo($cgi_filehandle);
         $Message->attach(
             Data    => \@file,
             #Path     => $temp_file,
             Filename => $filename,
-            Type     => $uploadinfo->{'Content-Type'}
+            Type     => $content_type
         );
         #close($fh);
         #unlink($temp_file);



Best regards,
Alexei

--
Alexei Barantsev, ISP RAS
E-mail: barancev at kazbek.ispras.ru
ICQ   : 3959207





More information about the Rt-devel mailing list