Restore addAttachments and restoreAttachments to the 7.x series. In 8.x, the object property will act like an arrayref, so they won't be necessary. Fixes bug #11861.
This commit is contained in:
parent
1131a5b4bc
commit
2eed74891a
3 changed files with 84 additions and 1 deletions
|
|
@ -48,6 +48,34 @@ These methods are available from this class:
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 addAttachments ( new_attachments )
|
||||
|
||||
Adds attachments to this template. New attachments are added to the end of the current set of
|
||||
attachments.
|
||||
|
||||
=head3 new_attachments
|
||||
|
||||
An arrayref of hashrefs, where each hashref should have at least url and type. All
|
||||
other keys will be ignored.
|
||||
|
||||
=cut
|
||||
|
||||
sub addAttachments {
|
||||
my ($self, $new_attachments) = @_;
|
||||
my $attachments = $self->getAttachments();
|
||||
|
||||
foreach my $a (@{ $new_attachments }) {
|
||||
push @{ $attachments }, {
|
||||
url => $a->{url},
|
||||
type => $a->{type},
|
||||
};
|
||||
}
|
||||
my $json = JSON->new->encode( $attachments );
|
||||
$self->update({ attachmentsJson => $json, });
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 cut ( )
|
||||
|
||||
Extend the base method to handle cutting the User Function Style template and destroying your site.
|
||||
|
|
@ -704,6 +732,32 @@ sub purge {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 removeAttachments ( urls )
|
||||
|
||||
Removes attachments.
|
||||
|
||||
=head3 urls
|
||||
|
||||
C<urls> is an arrayref of URLs to remove. If C<urls>
|
||||
is not defined, will remove all attachments for this revision.
|
||||
|
||||
=cut
|
||||
|
||||
sub removeAttachments {
|
||||
my ($self, $urls) = @_;
|
||||
|
||||
my @attachments = ();
|
||||
|
||||
if ($urls) {
|
||||
@attachments = grep { !isIn($_->{url}, @{ $urls }) } @{ $self->getAttachments() };
|
||||
}
|
||||
|
||||
my $json = JSON->new->encode( \@attachments );
|
||||
$self->update({ attachmentsJson => $json, });
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 update
|
||||
|
||||
Override update from Asset.pm to handle backwards compatibility with the old
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue