Skip to content

Commit

Permalink
Item14223: preserve attachment attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Nov 22, 2016
1 parent 4d34fd0 commit 13addc0
Showing 1 changed file with 14 additions and 8 deletions.
Expand Up @@ -55,10 +55,6 @@ sub handle {
my $fileCreateLink = $params->{createlink} || '0';
$fileCreateLink = $fileCreateLink eq 'on' ? 1:0;

my $fileHide = $params->{hidefile};
$fileHide = 'off' unless defined $fileHide;
$fileHide = $fileHide eq 'on' ? 1:0;

# loop thru all uploads
my $uploads = $request->uploads();
my @result = ();
Expand Down Expand Up @@ -96,22 +92,32 @@ sub handle {
return;
}

my $prevAttachment;
my $fileComment = $params->{filecomment};
unless (defined $fileComment) {
#$this->writeDebug("filecomment not found in query ... reading from topic");
# get prev comment as we override it otherwise
my $attrs = $meta->get( 'FILEATTACHMENT', $fileName );
$fileComment = $attrs->{comment} // '';
$prevAttachment = $meta->get('FILEATTACHMENT', $fileName) || {};
$fileComment = $prevAttachment->{comment} // '';
}

my $fileHide = $params->{hidefile};
unless (defined $fileHide) {
# get prev hide attr as we override it otherwise
$prevAttachment = $meta->get('FILEATTACHMENT', $fileName) unless defined $prevAttachment;
$fileHide = ($prevAttachment->{attr} && $prevAttachment->{attr} =~ /h/)?'on':'off';
}
$fileHide = $fileHide eq 'on' ? 1:0;

$this->writeDebug("web=$web, topic=$topic, fileName=$fileName, origName=$origName, tmpFileName=$tmpFileName, fileComment=$fileComment");
$this->writeDebug("web=$web, topic=$topic, fileName=$fileName, origName=$origName, tmpFileName=$tmpFileName, fileComment=$fileComment, fileHide=$fileHide");

my $error;
try {
$error = Foswiki::Func::saveAttachment(
$web, $topic, $fileName, {
dontlog => !$Foswiki::cfg{Log}{upload},
comment => $fileComment,
hide => $fileHide,
createlink => $fileCreateLink,
stream => $stream,
filesize => $fileSize,
filedate => $fileDate,
Expand Down

0 comments on commit 13addc0

Please sign in to comment.