#!/usr/bin/env perl #------------------------------------------------------------------- # 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 #------------------------------------------------------------------- $|++; # disable output buffering our ($webguiRoot, $configFile, $help, $man); BEGIN { $webguiRoot = ".."; unshift (@INC, $webguiRoot."/lib"); } use strict; use Pod::Usage; use Getopt::Long; use WebGUI::Session; use HTML::TagParser; # Get parameters here, including $help GetOptions( 'configFile=s' => \$configFile, 'help' => \$help, 'man' => \$man, ); pod2usage( verbose => 1 ) if $help; pod2usage( verbose => 2 ) if $man; pod2usage( msg => "Must specify a config file!" ) unless $configFile; my $session = start( $webguiRoot, $configFile ); my $DEBUG = 0; # Get all asset descriptions my $sth = $session->db->read( "SELECT wobject.assetId, wobject.revisionDate, title, description FROM wobject JOIN assetData USING ( assetId, revisionDate )" ); while ( my ( $assetId, $revisionDate, $title, $description ) = $sth->array ) { print "Checking '$title'"; my $changed = 0; while ( $description =~ m{src="([^"]+)"}g ) { my $src = $1; next if $src =~ /^[\^]/; # Don't mess with macros if ( WebGUI::Asset->newByUrl( $session, $src ) ) { # Not doing it right $description =~ s/$src/^FileUrl($src);/g; $changed = 1; print "."; } } if ( $changed ) { print " Changing... "; if ( $DEBUG ) { print $description; } else { my $asset = WebGUI::Asset->new( $session, $assetId, undef, $revisionDate ); $asset->addRevision({ description => $description }); } } print " DONE!\n"; } print "Finished! Make sure to clear your cache.\n\n"; finish($session); #---------------------------------------------------------------------------- sub start { my $webguiRoot = shift; my $configFile = shift; my $session = WebGUI::Session->open($webguiRoot,$configFile); $session->user({userId=>3}); my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->set({name => 'Fix Image src to use FileUrl Macro'}); return $session; } #---------------------------------------------------------------------------- sub finish { my $session = shift; my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->commit; $session->var->end; $session->close; } __END__ =head1 NAME fixImageFileUrl.pl -- Fix to use FileUrl macro =head1 SYNOPSIS fixImageFileUrl.pl --configFile config.conf fixImageFileUrl.pl --help =head1 DESCRIPTION This WebGUI utility script will edit all assets to use the FileUrl macro instead of using the Image asset URL directly. This improves performance dramatically (one proxy request for each image instead of two proxy requests and one perl request). =head1 OPTIONS =over =item B<--configFile config.conf> The WebGUI config file to use. Only the file name needs to be specified, since it will be looked up inside WebGUI's configuration directory. This parameter is required. =item B<--help> Shows a short summary and usage =item B<--man> Shows this document =back =head1 AUTHOR Copyright 2001-2009 Plain Black Corporation. =cut #vim:ft=perl