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

@ -3,6 +3,7 @@
- fixed #11152: Image edits do not autocommit version tags
- fixed template attachments are not cleaned up during purge
- fixed #11150: matrix - search boxes all ticked
- fixed #11063: template_attachments
7.8.2
- Added scheduled vendor payout workflow activity. (Special thanks to Martin @ Oqapi)

View file

@ -31,12 +31,30 @@ my $quiet; # this line required
my $session = start(); # this line required
# upgrade functions go here
reKeyTemplateAttachments($session);
finish($session); # this line required
#----------------------------------------------------------------------------
# Describe what our function does
sub reKeyTemplateAttachments {
my $session = shift;
print "\tChanging the key structure for the template attachments table... " unless $quiet;
# and here's our code
$session->db->write('ALTER TABLE template_attachments ADD COLUMN attachId CHAR(22) BINARY NOT NULL');
my $rh = $session->db->read('select url, templateId, revisionDate from template_attachments');
my $wh = $session->db->prepare('update template_attachments set attachId=? where url=? and templateId=? and revisionDate=?');
while (my @key = $rh->array) {
$wh->execute([$session->id->generate, @key ]);
}
$rh->finish;
$wh->finish;
$session->db->write('ALTER TABLE template_attachments DROP PRIMARY KEY');
$session->db->write('ALTER TABLE template_attachments ADD PRIMARY KEY (attachId)');
print "DONE!\n" unless $quiet;
}
#sub exampleFunction {
# my $session = shift;
# print "\tWe're doing some stuff here that you should know about... " unless $quiet;

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(@_);
}

View file

@ -121,6 +121,10 @@ is($att4->[1]->{url}, 'bar', 'rev still has bar');
is($att4->[2]->{url}, 'baz', 'rev does have new thing');
is(@$att4, 3, 'rev is proper size');
##This is a non-test. Duplicate URLs will not cause the test to blow-up with
##an untrappable error.
$template3rev->addAttachments([{ type => 'headScript', sequence => 3, url => 'baz'}]);
$template3rev->purgeRevision();
## Check how templates in the trash and clipboard are handled.
@ -168,6 +172,7 @@ like($brokenOutput, qr/$brokenUrl/, '... and the template url');
like($brokenOutput, qr/$brokenId/, '... and the template id');
like($logError, qr/$brokenUrl/, 'process: logged error has the url');
like($logError, qr/$brokenId/, '... and the template id');
WebGUI::Test->restoreLogging;
WebGUI::Test->tagsToRollback(WebGUI::VersionTag->getWorking($session));