diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 5f4acebe7..78d86ec93 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -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) diff --git a/docs/upgrades/upgrade_7.8.2-7.8.3.pl b/docs/upgrades/upgrade_7.8.2-7.8.3.pl index e72bbce1c..166124e08 100644 --- a/docs/upgrades/upgrade_7.8.2-7.8.3.pl +++ b/docs/upgrades/upgrade_7.8.2-7.8.3.pl @@ -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; diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index 58d6e7610..dc242d5f8 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -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(@_); } diff --git a/t/Asset/Template.t b/t/Asset/Template.t index ad0f3c5bf..18657936f 100644 --- a/t/Asset/Template.t +++ b/t/Asset/Template.t @@ -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));