Rekey the template_attachments table. Fixes bug #11063.

Also, prevent template attachments from throwing an error on duplicate
URLs, and fix the purge method added earlier.
This commit is contained in:
Colin Kuskie 2009-10-21 16:11:22 -07:00
parent 13f833c27b
commit ece9d56a9e
4 changed files with 33 additions and 14 deletions

View file

@ -128,20 +128,16 @@ sub addAttachments {
my $db = $self->session->db;
my $sql = q{
INSERT INTO template_attachments
(templateId, revisionDate, url, type, sequence)
VALUES
(?, ?, ?, ?, ?)
};
foreach my $a (@$attachments) {
my @params = (
$self->getId,
$self->get('revisionDate'),
@{$a}{qw(url type sequence)}
my %params = (
templateId => $self->getId,
revisionDate => $self->get('revisionDate'),
url => $a->{url},
type => $a->{type},
sequence => $a->{sequence},
attachId => 'new',
);
$db->write($sql, \@params);
$db->setRow('template_attachments', 'attachId', \%params);
}
}
@ -725,9 +721,8 @@ Extend the master to purge attachments in all revisions.
=cut
sub purgeRevision {
sub purge {
my $self = shift;
$self->removeAttachments;
$self->session->db->write('delete from template_attachments where templateId=?', [$self->getId]);
return $self->SUPER::purge(@_);
}