You are here: Foswiki>Tasks Web>Item13049 (25 Sep 2016, GeorgeClark)Edit Attach

Item13049: BatchUploadPlugin: beforeUploadHandler error if ModPerlEngineContrib enabled

pencil
Priority: Normal
Current State: Needs Developer
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: BatchUploadPlugin
Branches:
Reported By: ChristianLudwig
Waiting For:
Last Change By: GeorgeClark

Description of the problem

In the beforeUploadHandler of the BatchUploadPlugin there is hack (throwing a Simple::Error with the message "Do not save zip file!") in order
  • not to attach the zip file, i.e. stopping the attachment process (because the files inside the zip-file have already been attached) and
  • not to overwrite the meta data (with the extracted files) with the saved meta data in the caller (that is missing the extracted files)

This method of "stopping" doesn't work as expected if ModPerlEngineContrib is used. Then this error message will be propagated to the user. Without ModPerlEngineContrib I think this throw statement es never executed, because there is a redirectCgiQuery before.

Please see also Support.Question238.

Workarounds

OK. In my case I'm using a very ugly/insane workaround. Instead of the original (inside beforeUploadHandler in BatchUploadPlugin)
Foswiki::Func::redirectCgiQuery( undef, $url );

# SMELL: bit of a hack?
# user won't see this, but if left out the zip file will be attached, overwriting the unzipped files
#exit 0; this just returns a blank page to the user, not very good...
throw Error::Simple( 'Do not save zip file!' ); # this seems to work fine, the user gets returned to their viewed page and the unzipped files do not get overwritten. Presumably it is caught somewhere higher up.
I set a special "flag" in the attrHashRef
# Foswiki::Func::redirectCgiQuery( undef, $url );

# SMELL: bit of a hack?
$attrHashRef->{'attachActions'}=[] unless defined($attrHashRef->{'attachActions'});
push @{$attrHashRef->{'attachActions'}},'cancelattachment';

and inside Meta.pm inside the method attach I check the special "attachActions":
$plugins->dispatch( 'beforeUploadHandler', $attrs, $this );
$opts{stream} = $attrs->{stream};
my $actions=$attrs->{'attachActions'};
if (defined($actions) && 'ARRAY' eq ref($actions)) {
  # one of the beforeUploadHandlers wants some "special" actions
  if (grep { $_ eq 'cancelattachment' } @$actions) {
    goto cancelAttachment;
  }
}
and I added the jump "cancelAttachment" at the end of the method:
cancelAttachment:
delete $attrs->{stream};
delete $attrs->{tmpFilename};

-- ChristianLudwig - 08 Oct 2014

 
Topic revision: r2 - 25 Sep 2016, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy