diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 1c1383c34..bee6a966e 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -3,6 +3,7 @@ - fixed #12229: Indexed thingy data has gateway url prepended to it - fixed #12195: Visitor group by scratch membership shared among all Visitors (Dale Trexel) - fixed #12227: Corrected AssetReport such that OrderBy works correctly. + - fixed #12238: Old template attachement in search template slows down sites 7.10.22 - rfe #12223: Add date type to content profiling (metadata) diff --git a/docs/gotcha.txt b/docs/gotcha.txt index ec51f5d9e..1e34dceb3 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -7,6 +7,12 @@ upgrading from one version to the next, or even between multiple versions. Be sure to heed the warnings contained herein as they will save you many hours of grief. +7.10.23 +-------------------------------------------------------------------- + * The default_search2 template had a bad template attachment pointing to + an old WebGUI CSS Snippet called /webgui.css. Any attachment with that + URL will be removed from ALL templates in the Search namespace. + 7.10.21 -------------------------------------------------------------------- * WebGUI now depends on Kwargs. diff --git a/docs/upgrades/upgrade_7.10.22-7.10.23.pl b/docs/upgrades/upgrade_7.10.22-7.10.23.pl index c9bd039d2..feea6eb2c 100644 --- a/docs/upgrades/upgrade_7.10.22-7.10.23.pl +++ b/docs/upgrades/upgrade_7.10.22-7.10.23.pl @@ -31,6 +31,7 @@ my $quiet; # this line required my $session = start(); # this line required # upgrade functions go here +fixBadTemplateAttachments($session); finish($session); # this line required @@ -44,6 +45,23 @@ finish($session); # this line required # print "DONE!\n" unless $quiet; #} +#---------------------------------------------------------------------------- +sub fixBadTemplateAttachments { + my $session = shift; + print "\tRemove template attachements in search templates that refer to an old, deleted CSS snippet... " unless $quiet; + # and here's our code + use WebGUI::Asset::Template; + my $get_template = WebGUI::Asset::Template->getIsa($session); + TEMPLATE: while (1) { + my $template = eval {$get_template->()}; + next TEMPLATE if Exception::Class->caught; + last TEMPLATE unless $template; + next TEMPLATE unless $template->get('namespace') eq 'Search'; + $template->removeAttachments(['^/(webgui.css);']); + } + print "DONE!\n" unless $quiet; +} + # -------------- DO NOT EDIT BELOW THIS LINE -------------------------------- diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index eb6658018..c2b4b5587 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -646,15 +646,15 @@ sub prepare { $style->setRawHeadTags($headBlock); + my %props = ( type => 'text/css', rel => 'stylesheet' ); foreach my $sheet ( @{ $self->getAttachments('stylesheet') } ) { - my %props = ( type => 'text/css', rel => 'stylesheet' ); $style->setLink($sheet->{url}, \%props); } my $doScripts = sub { my ($type, $body) = @_; + my %props = ( type => 'text/javascript' ); foreach my $script ( @{ $self->getAttachments($type) } ) { - my %props = ( type => 'text/javascript' ); $style->setScript($script->{url}, \%props, $body); } }; diff --git a/t/templateAttachments.t b/t/templateAttachments.t new file mode 100644 index 000000000..e0961a2a8 --- /dev/null +++ b/t/templateAttachments.t @@ -0,0 +1,58 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use FindBin; +use strict; +use warnings; +use lib "$FindBin::Bin/lib"; ##t/lib + +use WebGUI::Test; +use WebGUI::Session; +use Data::Dumper; +use WebGUI::Asset; +use WebGUI::Asset::Template; +use WebGUI::Macro; + +#The goal of this test is to find template attachments that do not resolve. + +use Test::More; # increment this value for each test you create +my $numTests = 0; + +my $session = WebGUI::Test->session; + +# put your tests here + +$numTests = $session->db->quickScalar('select count(distinct(assetId)) from template'); + +my $getATemplate = WebGUI::Asset::Template->getIsa($session); + +WebGUI::Test->originalConfig('extrasURL'); +$session->config->set('extrasURL', ''); + +TEMPLATE: while (my $templateAsset = $getATemplate->()) { + my $bad_attachments = 0; + foreach my $attachment (@{ $templateAsset->getAttachments }) { + my $url = $attachment->{url}; + WebGUI::Macro::process($session, \$url); + my $url_exists = 0; + if ($attachment->{url} =~ /\^Extras/) { + ##File system path for /extras, adjust the URL for that. + $url = $session->config->get('extrasPath') . $url; + $url_exists = -e $url; + } + else { + my $asset = eval { WebGUI::Asset->newByUrl($session, $url) }; + $url_exists = defined $asset; + } + ok $url_exists, sprintf "%s: %s (%s) has a bad attachment url: %s", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl, $attachment->{url}; + } +} + +done_testing;