Tags:
create new tag
, view all tags

Feature Proposal: Add Meta Data to beforeAttachmentSaveHandler and afterAttachmentSaveHandler

Motivation

Plugins might want to update meta data based on attachments, such as a form field that should contain the filename of the most recently uploaded attachment.

Description and Documentation

Add $meta as new parameter to beforeAttachmentSaveHandler() and afterAttachmentSaveHandler().

Updated lib/TWiki/Plugins/EmptyPlugin.pm:

=pod

---++ beforeAttachmentSaveHandler(\%attrHash, $topic, $web, $meta )
   * =\%attrHash= - reference to hash of attachment attribute values
   * =$topic= - the name of the topic in the current CGI query
   * =$web= - the name of the web in the current CGI query
   * =$meta= - meta-data object for the topic
This handler is called once when an attachment is uploaded. When this
handler is called, the attachment has *not* been recorded in the database.

The attributes hash will include at least the following attributes:
   * =attachment= => the attachment name
   * =comment= - the comment
   * =user= - the user id
   * =tmpFilename= - name of a temporary file containing the attachment data

*Since:* TWiki::Plugins::VERSION = 1.025

=cut

sub DISABLE_beforeAttachmentSaveHandler {
    # do not uncomment, use $_[0], $_[1]... instead
    ###   my( $attrHashRef, $topic, $web ) = @_;
    TWiki::Func::writeDebug( "- ${pluginName}::beforeAttachmentSaveHandler( $_[2].$_[1] )" ) if $debug;
}

=pod

---++ afterAttachmentSaveHandler(\%attrHash, $topic, $web, $error, $meta )
   * =\%attrHash= - reference to hash of attachment attribute values
   * =$topic= - the name of the topic in the current CGI query
   * =$web= - the name of the web in the current CGI query
   * =$error= - any error string generated during the save process
   * =$meta= - meta-data object for the topic
This handler is called just after the save action. The attributes hash
will include at least the following attributes:
   * =attachment= => the attachment name
   * =comment= - the comment
   * =user= - the user id

*Since:* TWiki::Plugins::VERSION = 1.025

=cut

sub DISABLE_afterAttachmentSaveHandler {
    # do not uncomment, use $_[0], $_[1]... instead
    ###   my( $attrHashRef, $topic, $web ) = @_;
    TWiki::Func::writeDebug( "- ${pluginName}::afterAttachmentSaveHandler( $_[2].$_[1] )" ) if $debug;
}

Impact

Implementation

in twiki/lib/TWiki/Store.pm add $meta:

               select((select( $fh ), $| = 1)[0]);
               seek( $fh, 0, 0 ) or die "can't seek temp: $! \n";
               $opts->{stream} = $fh;
               $attrs->{tmpFilename} = $tmpFile;
               $plugins->dispatch('beforeAttachmentSaveHandler', $attrs, $topic, $web, $meta );
            }

....

            if( $plugins->haveHandlerFor( 'afterAttachmentSaveHandler' )) {
                $plugins->dispatch('afterAttachmentSaveHandler',
                                   $attrs, $topic, $web,
                                   $error ? $error->{-text} : '',
                                   $meta );
            }

-- Contributors: PeterThoeny - 2011-02-19

Discussion

This is now accepted by 7-day rule, implemented in trunk, and EmptyPlugin is updated as well.

-- PeterThoeny - 2011-03-07

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2011-03-07 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.