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