Skip to content

Commit 7a89bf1

Browse files
committedAug 29, 2011
Remove a template attachment in the Search namespace. Add tests to check all other template attachments. Fixes bug #12238.
1 parent d400484 commit 7a89bf1

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed
 

‎docs/changelog/7.x.x.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- fixed #12229: Indexed thingy data has gateway url prepended to it
44
- fixed #12195: Visitor group by scratch membership shared among all Visitors (Dale Trexel)
55
- fixed #12227: Corrected AssetReport such that OrderBy works correctly.
6+
- fixed #12238: Old template attachement in search template slows down sites
67

78
7.10.22
89
- rfe #12223: Add date type to content profiling (metadata)

‎docs/gotcha.txt

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ upgrading from one version to the next, or even between multiple
77
versions. Be sure to heed the warnings contained herein as they will
88
save you many hours of grief.
99

10+
7.10.23
11+
--------------------------------------------------------------------
12+
* The default_search2 template had a bad template attachment pointing to
13+
an old WebGUI CSS Snippet called /webgui.css. Any attachment with that
14+
URL will be removed from ALL templates in the Search namespace.
15+
1016
7.10.21
1117
--------------------------------------------------------------------
1218
* WebGUI now depends on Kwargs.

‎docs/upgrades/upgrade_7.10.22-7.10.23.pl

+18
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ BEGIN
3131
my $session = start(); # this line required
3232

3333
# upgrade functions go here
34+
fixBadTemplateAttachments($session);
3435

3536
finish($session); # this line required
3637

@@ -44,6 +45,23 @@ BEGIN
4445
# print "DONE!\n" unless $quiet;
4546
#}
4647

48+
#----------------------------------------------------------------------------
49+
sub fixBadTemplateAttachments {
50+
my $session = shift;
51+
print "\tRemove template attachements in search templates that refer to an old, deleted CSS snippet... " unless $quiet;
52+
# and here's our code
53+
use WebGUI::Asset::Template;
54+
my $get_template = WebGUI::Asset::Template->getIsa($session);
55+
TEMPLATE: while (1) {
56+
my $template = eval {$get_template->()};
57+
next TEMPLATE if Exception::Class->caught;
58+
last TEMPLATE unless $template;
59+
next TEMPLATE unless $template->get('namespace') eq 'Search';
60+
$template->removeAttachments(['^/(webgui.css);']);
61+
}
62+
print "DONE!\n" unless $quiet;
63+
}
64+
4765

4866
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------
4967

‎lib/WebGUI/Asset/Template.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -646,15 +646,15 @@ sub prepare {
646646

647647
$style->setRawHeadTags($headBlock);
648648

649+
my %props = ( type => 'text/css', rel => 'stylesheet' );
649650
foreach my $sheet ( @{ $self->getAttachments('stylesheet') } ) {
650-
my %props = ( type => 'text/css', rel => 'stylesheet' );
651651
$style->setLink($sheet->{url}, \%props);
652652
}
653653

654654
my $doScripts = sub {
655655
my ($type, $body) = @_;
656+
my %props = ( type => 'text/javascript' );
656657
foreach my $script ( @{ $self->getAttachments($type) } ) {
657-
my %props = ( type => 'text/javascript' );
658658
$style->setScript($script->{url}, \%props, $body);
659659
}
660660
};

‎t/templateAttachments.t

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#-------------------------------------------------------------------
2+
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
3+
#-------------------------------------------------------------------
4+
# Please read the legal notices (docs/legal.txt) and the license
5+
# (docs/license.txt) that came with this distribution before using
6+
# this software.
7+
#-------------------------------------------------------------------
8+
# http://www.plainblack.com info@plainblack.com
9+
#-------------------------------------------------------------------
10+
11+
use FindBin;
12+
use strict;
13+
use warnings;
14+
use lib "$FindBin::Bin/lib"; ##t/lib
15+
16+
use WebGUI::Test;
17+
use WebGUI::Session;
18+
use Data::Dumper;
19+
use WebGUI::Asset;
20+
use WebGUI::Asset::Template;
21+
use WebGUI::Macro;
22+
23+
#The goal of this test is to find template attachments that do not resolve.
24+
25+
use Test::More; # increment this value for each test you create
26+
my $numTests = 0;
27+
28+
my $session = WebGUI::Test->session;
29+
30+
# put your tests here
31+
32+
$numTests = $session->db->quickScalar('select count(distinct(assetId)) from template');
33+
34+
my $getATemplate = WebGUI::Asset::Template->getIsa($session);
35+
36+
WebGUI::Test->originalConfig('extrasURL');
37+
$session->config->set('extrasURL', '');
38+
39+
TEMPLATE: while (my $templateAsset = $getATemplate->()) {
40+
my $bad_attachments = 0;
41+
foreach my $attachment (@{ $templateAsset->getAttachments }) {
42+
my $url = $attachment->{url};
43+
WebGUI::Macro::process($session, \$url);
44+
my $url_exists = 0;
45+
if ($attachment->{url} =~ /\^Extras/) {
46+
##File system path for /extras, adjust the URL for that.
47+
$url = $session->config->get('extrasPath') . $url;
48+
$url_exists = -e $url;
49+
}
50+
else {
51+
my $asset = eval { WebGUI::Asset->newByUrl($session, $url) };
52+
$url_exists = defined $asset;
53+
}
54+
ok $url_exists, sprintf "%s: %s (%s) has a bad attachment url: %s", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl, $attachment->{url};
55+
}
56+
}
57+
58+
done_testing;

0 commit comments

Comments
 (0)