From 033b4d7c0bb028c990dc4c34f81c916ff44439bc Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Mon, 19 Apr 2010 10:58:14 -0500 Subject: [PATCH 01/36] fix WebGUI::Paths recursion --- lib/WebGUI/Paths.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WebGUI/Paths.pm b/lib/WebGUI/Paths.pm index eeac57101..69e03cf49 100644 --- a/lib/WebGUI/Paths.pm +++ b/lib/WebGUI/Paths.pm @@ -201,7 +201,7 @@ Returns the list of modules to exclude from preloading as an array. sub preloadExclude { my $class = shift; - my @excludes = _readTextLines($class->preloadExclude); + my @excludes = _readTextLines($class->preloadExclusions); return @excludes; } From 9c613ab6380d40a786c929d56e3b2a30dc933c3e Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Mon, 19 Apr 2010 11:01:39 -0500 Subject: [PATCH 02/36] more WebGUI::Paths fixes --- lib/WebGUI/Paths.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/WebGUI/Paths.pm b/lib/WebGUI/Paths.pm index 69e03cf49..ef2dfc446 100644 --- a/lib/WebGUI/Paths.pm +++ b/lib/WebGUI/Paths.pm @@ -217,8 +217,9 @@ sub preloadAll { require WebGUI::Pluggable; + my @exclusions = $class->preloadExclude; WebGUI::Pluggable::findAndLoad( 'WebGUI', { - exclude => \( $class->preloadExclude ), + exclude => \@exclusions, onLoadFail => sub { warn sprintf "Error loading %s: %s\n", @_ }, }); } @@ -226,7 +227,7 @@ sub preloadAll { sub _readTextLines { my $file = shift; my @lines; - open my $fh, '<', $file or croak "Cannot open $file: $!"; + open my $fh, '<', $file or return; while (my $line = <$fh>) { $line =~ s/#.*//; $line =~ s/^\s+//; From d46f77bf2eaae9fb04a6bbe68f864f11ce4bb7ed Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 19 Apr 2010 09:46:24 -0500 Subject: [PATCH 03/36] more work on admin console --- lib/WebGUI/Admin.pm | 2 ++ www/extras/admin/admin.css | 8 +++--- www/extras/admin/admin.js | 52 ++++++++++++++++++++++++++++++++------ 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/lib/WebGUI/Admin.pm b/lib/WebGUI/Admin.pm index 8aa439e5e..a100ecc40 100644 --- a/lib/WebGUI/Admin.pm +++ b/lib/WebGUI/Admin.pm @@ -177,6 +177,7 @@ sub www_view { } $var->{viewUrl} = $url->page; + $var->{homeUrl} = WebGUI::Asset->getDefault( $session )->getUrl; # All this needs to be template attachments $style->setLink( $url->extras('yui/build/button/assets/skins/sam/button.css'), {type=>"text/css",rel=>"stylesheet"}); @@ -265,6 +266,7 @@ __DATA__ diff --git a/www/extras/admin/admin.css b/www/extras/admin/admin.css index 029c1219d..c7f96b8b8 100644 --- a/www/extras/admin/admin.css +++ b/www/extras/admin/admin.css @@ -39,22 +39,22 @@ #locationBar #left { position: absolute; - width: 16%; + width: 12%; top: 5px; left: 0; } #locationBar #right { position: absolute; - width: 8%; + width: 10%; top: 5px; right: 0; } #locationBar #location { position: relative; - margin: auto 7% auto 16%; - width: 75%; + margin: auto 10% auto 12%; + width: 77%; height: 80%; border: 1px solid #333; border-radius: 3px; diff --git a/www/extras/admin/admin.js b/www/extras/admin/admin.js index 71cf9d95c..696db56dd 100644 --- a/www/extras/admin/admin.js +++ b/www/extras/admin/admin.js @@ -99,9 +99,10 @@ WebGUI.Admin.prototype.navigate * WebGUI.Admin.LocationBar */ WebGUI.Admin.LocationBar -= function (id) { += function (id, cfg) { // Public properties this.id = id; // ID of the element containing the location bar + this.cfg = cfg; // Configuration this.currentAssetDef = null; // Object containing assetId, title, url, icon this.backAssetDefs = [ ]; // Asset defs to go back to this.forwardAssetDefs = [ ]; // Asset defs to go forward to @@ -129,12 +130,20 @@ WebGUI.Admin.LocationBar menu : [] } ); self.btnSearch = new YAHOO.widget.Button( "searchButton", { - label : '' + label : '', + onclick : { fn: self.clickSearchButton, scope: self } } ); self.btnHome = new YAHOO.widget.Button( "homeButton", { - label : '' + type : "button", + label : '', + onclick : { fn: self.goHome, scope: self } } ); // Take control of the location input + self.klInput = new YAHOO.util.KeyListener( "locationUrl", { keys: 13 }, { + fn: self.doInputSearch, + scope: self, + correctScope: true + } ); YAHOO.util.Event.addListener( "locationUrl", "focus", self.inputFocus, self, true ); YAHOO.util.Event.addListener( "locationUrl", "blur", self.inputBlur, self, true ); } @@ -186,6 +195,29 @@ WebGUI.Admin.LocationBar.prototype.clickForwardMenuItem this.swapForwardToBack( assetDef ); }; +/** + * doInputSearch() + * Perform the search as described in the location bar + */ +WebGUI.Admin.LocationBar.prototype.doInputSearch += function ( ) { + var input = document.getElementById("locationUrl").value; + // If input starts with a / and doesn't contain a ? go to the asset + if ( input.match(/^\//) ) { + if ( !input.match(/\?/) ) { + window.admin.gotoAsset( input ); + } + // If does contain a ?, go to url + else { + window.admin.go( input ); + } + } + // Otherwise ask WebGUI what do + else { + alert("TODO"); + } +}; + /** * getMenuItemLabel( assetDef ) * Build a menu item label for the given assetDef @@ -234,6 +266,7 @@ WebGUI.Admin.LocationBar.prototype.inputBlur if ( e.target.value.match(/^\s*$/) ) { e.target.value = this.currentAssetDef.url; } + this.klInput.disable(); }; /** @@ -245,6 +278,7 @@ WebGUI.Admin.LocationBar.prototype.inputFocus if ( e.target.value == this.currentAssetDef.url ) { e.target.value = ""; } + this.klInput.enable(); }; /** @@ -257,12 +291,14 @@ WebGUI.Admin.LocationBar.prototype.navigate this.setTitle( assetDef.title ); this.setUrl( assetDef.url ); - if ( this.currentAssetDef ) { - if ( this.currentAssetDef.assetId == assetDef.assetId ) { - // Don't do the same asset twice - return; - } + // Don't do the same asset twice + if ( this.currentAssetDef && this.currentAssetDef.assetId != assetDef.assetId ) { this.addBackAsset( this.currentAssetDef ); + // We navigated, so destroy the forward queue + //this.forwardAssetDefs = []; + //this.btnForward.getMenu().clearItems(); + //this.btnForward.getMenu().render(); + //this.btnForward.set( "disabled", true ); } // Current asset is now... From 5cdde20633229b2d01028e1d3c2b105d9a051434 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 19 Apr 2010 10:58:52 -0500 Subject: [PATCH 04/36] initial CHI implementation --- lib/WebGUI/Session.pm | 49 ++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index 6e5396c40..657f46f50 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -15,7 +15,10 @@ package WebGUI::Session; =cut use strict; -use WebGUI::Cache; +use 5.010; + +use CHI; +use File::Temp; use WebGUI::Config; use WebGUI::SQL; use WebGUI::User; @@ -117,17 +120,39 @@ Returns a WebGUI::Cache object, which is connected to the WebGUI memcached serve =cut sub cache { - my $self = shift; - unless (exists $self->{_cache}) { - my $cache = WebGUI::Cache->new($self); - if (defined $cache) { - $self->{_cache} = $cache; - } - else { - $self->log->fatal("Couldn't connect to WebGUI memcached server, and can't continue without it."); - } - } - return $self->{_cache}; + my $self = shift; + unless (exists $self->{_cache}) { + my $cacheConf = $self->config->get('cache'); + + # Default values + my $resolveConf = sub { + my ($config) = @_; + given ( $config->{driver} ) { + when ( /DBI/ ) { + $config->{ dbh } = $self->db->dbh; + continue; + } + when ( /File|FastMmap|BerkeleyDB/ ) { + $config->{ root_dir } ||= tempdir(); + continue; + } + when ( /FastMmap/ ) { + #$config->{ cache_size } = '64m'; + continue; + } + } + $config->{namespace} ||= $self->config->get('sitename')->[0]; + }; + + $resolveConf->( $cacheConf ); + if ( $cacheConf->{l1_cache} ) { + $resolveConf->( $cacheConf->{l1_cache} ); + } + + my $cache = CHI->new( %{$cacheConf} ); + $self->{_cache} = $cache; + } + return $self->{_cache}; } #------------------------------------------------------------------- From 30e2a857d8b821f4609fff4ace42f2cfb8029937 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 19 Apr 2010 11:36:25 -0500 Subject: [PATCH 05/36] finished adding CHI --- lib/WebGUI/Session.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index 657f46f50..29052fab8 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -18,7 +18,7 @@ use strict; use 5.010; use CHI; -use File::Temp; +use File::Temp qw( tempdir ); use WebGUI::Config; use WebGUI::SQL; use WebGUI::User; From 9015df5f98a550278f4b2fc95f38dec01165ae52 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 19 Apr 2010 11:58:07 -0500 Subject: [PATCH 06/36] added new cache to original conf --- etc/WebGUI.conf.original | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index cce3490fe..6ecbcd40b 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -88,17 +88,30 @@ #"webServerPort" : 80, -# The cacheServers directive tells WebGUI how to connect to -# memcached. If a "socket" is specified it will be used instead -# of the host and port info, and this should be the -# path to the unix socket that you started memcached with. "host" -# and "port" are used to tell WebGUI how to connect to -# memcached over TCP. And since this is an array you can specify -# as many server connections as you have memcached servers - -"cacheServers" : [ - { "socket" : "/tmp/memcached.sock", "host" : "127.0.0.1", "port" : "11211" } -], +# The cache key defines the configuration of the caching mechanism. +# Required keys: +# driver -> one of "Memory", "DBI", "FastMmap", "Memcached" +# FastMmap is recommended for single-server sites +# Memcached is recommended for multi-server sites +# +# Optional keys: +# expires_variance -> Define a percentage of variance in a cache item's +# expiration. This prevents "cache miss stampedes" where +# many things will attempt to refresh the cache at once. +# Set as a decimal percentage: "0.10" = 10% variance +# l1_cache -> Define a Level 1 cache, a faster cache to use for commonly- +# accessed stuff. Uses the same format and keys as the top level. +# ex: +# "l1_cache" : { +# "driver" : "Memory" +# }, +# mirror_cache -> Define a write-only mirror. Used to warm up a new cache +# before switching over to it. Defined exactly like an l1_cache +# +"cache" : { + "driver" : "FastMmap", + "expires_variance" : "0.10" +}, # Sessions that are "hot", those that are not only not expired, # but that are currently active on the site are kept in memory From ef89051084196dd01931f36950094efccdafdd24 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 19 Apr 2010 12:00:36 -0500 Subject: [PATCH 07/36] added new cache to upgrade --- var/upgrades/upgrade_7.9.3-8.0.0.pl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/var/upgrades/upgrade_7.9.3-8.0.0.pl b/var/upgrades/upgrade_7.9.3-8.0.0.pl index b21d870b2..ce8f29cbe 100644 --- a/var/upgrades/upgrade_7.9.3-8.0.0.pl +++ b/var/upgrades/upgrade_7.9.3-8.0.0.pl @@ -40,7 +40,10 @@ sub migrateToNewCache { unlink "../../lib/WebGUI/Workflow/Activity/CleanDatabaseCache.pm"; unlink "../../lib/WebGUI/Workflow/Activity/CleanFileCache.pm"; my $config = $session->config; - $config->set("cacheServers", [ { "socket" => "/data/wre/var/memcached.sock", "host" => "127.0.0.1", "port" => "11211" } ]); + $config->set("cache", { + "driver" => "FastMmap", + "expires_variance" => "0.10", + }); $config->set("hotSessionFlushToDb", 600); $config->delete("disableCache"); $config->delete("cacheType"); From cd0fbf8ecb0ce81ef459ce3a6ed193dd1b1ffca3 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 19 Apr 2010 10:21:57 -0700 Subject: [PATCH 08/36] Remove subclassed methods validParent and addChild from GalleryFile and Gallery. --- lib/WebGUI/Asset/File/GalleryFile.pm | 13 ------------- lib/WebGUI/Asset/Wobject/Gallery.pm | 28 ---------------------------- 2 files changed, 41 deletions(-) diff --git a/lib/WebGUI/Asset/File/GalleryFile.pm b/lib/WebGUI/Asset/File/GalleryFile.pm index f812a69ba..3325cdb6a 100644 --- a/lib/WebGUI/Asset/File/GalleryFile.pm +++ b/lib/WebGUI/Asset/File/GalleryFile.pm @@ -827,19 +827,6 @@ sub valid_parent_classes { #---------------------------------------------------------------------------- -=head2 validParent ( ) - -Override validParent to only allow GalleryAlbums to hold GalleryFiles. - -=cut - -sub validParent { - my ($class, $session) = @_; - return $session->asset->isa('WebGUI::Asset::Wobject::GalleryAlbum'); -} - -#---------------------------------------------------------------------------- - =head2 view ( ) method called by the container www_view method. diff --git a/lib/WebGUI/Asset/Wobject/Gallery.pm b/lib/WebGUI/Asset/Wobject/Gallery.pm index b19322bfa..385d8d61f 100644 --- a/lib/WebGUI/Asset/Wobject/Gallery.pm +++ b/lib/WebGUI/Asset/Wobject/Gallery.pm @@ -342,34 +342,6 @@ use WebGUI::HTML; #---------------------------------------------------------------------------- -=head2 addChild ( properties, [...] ) - -Add a child to this asset. See C for more info. - -Overridden to ensure that only GalleryAlbums are added to Galleries. - -=cut - -sub addChild { - my $self = shift; - my $properties = shift; - my $albumClass = "WebGUI::Asset::Wobject::GalleryAlbum"; - - # Load the class - WebGUI::Pluggable::load( $properties->{className} ); - - if ( !$properties->{className}->isa( $albumClass ) ) { - $self->session->errorHandler->security( - "add a ".$properties->{className}." to a ".$self->className - ); - return undef; - } - - return $self->next::method( $properties, @_ ); -} - -#---------------------------------------------------------------------------- - =head2 appendTemplateVarsSearchForm ( var ) Appends the template vars for the search form to the hash reference C. From ff1cd9fad82e6751d890456568dd72a271b59baf Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 19 Apr 2010 10:32:22 -0700 Subject: [PATCH 09/36] Update Session POD for CHI. --- lib/WebGUI/Session.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index 29052fab8..c98983d60 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -115,7 +115,7 @@ sub asset { =head2 cache ( ) -Returns a WebGUI::Cache object, which is connected to the WebGUI memcached server. +Returns a CHI object, configured according to the settings in the config file. =cut From 43413fe75ce3c493d147f8451583e9c75c641cb8 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 19 Apr 2010 11:00:45 -0700 Subject: [PATCH 10/36] Put back the skipNotification property into Asset. --- lib/WebGUI/Asset.pm | 6 ++++++ lib/WebGUI/AssetVersioning.pm | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 37b9d60c1..5fde8666a 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -261,6 +261,12 @@ property tagId => ( fieldType => 'guid', default => 0, ); +property skipNotification => ( + autoGenerate => 0, + noFormPost => 1, + fieldType => 'yesNo', + ); + has session => ( is => 'ro', required => 1, diff --git a/lib/WebGUI/AssetVersioning.pm b/lib/WebGUI/AssetVersioning.pm index b9ebe8d5e..9674e1e5e 100644 --- a/lib/WebGUI/AssetVersioning.pm +++ b/lib/WebGUI/AssetVersioning.pm @@ -456,7 +456,7 @@ Sets a flag so that developers know whether to send notifications out on certain sub setSkipNotification { my $self = shift; $self->session->db->write("update assetData set skipNotification=1 where assetId=? and revisionDate=?", [$self->getId, $self->get("revisionDate")]); - $self->{_properties}->{skipNotification} = 1; + $self->skipNotification(1); } #------------------------------------------------------------------- From 92cd204b31fff4da90d4f864e6c72aa9406e38bf Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 19 Apr 2010 14:58:35 -0500 Subject: [PATCH 11/36] fix composite cache keys and remove setByHttp --- lib/WebGUI/Asset.pm | 6 ++-- lib/WebGUI/Asset/Snippet.pm | 24 -------------- lib/WebGUI/Asset/Wobject/HttpProxy.pm | 12 +++---- lib/WebGUI/Asset/Wobject/SyndicatedContent.pm | 31 +++++++++++++------ lib/WebGUI/Cache.pm | 23 ++++++++------ lib/WebGUI/Operation/Statistics.pm | 25 +++++++++++---- lib/WebGUI/Session/Scratch.pm | 8 ++--- lib/WebGUI/Session/Var.pm | 12 +++---- lib/WebGUI/User.pm | 6 ++-- sbin/testEnvironment.pl | 2 ++ 10 files changed, 78 insertions(+), 71 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 5fde8666a..0f11632c7 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -350,7 +350,7 @@ around BUILDARGS => sub { } } - my $properties = eval{$session->cache->get(["asset",$assetId,$revisionDate])}; + my $properties = eval{$session->cache->get("asset".$assetId.$revisionDate)}; unless (exists $properties->{assetId}) { # can we get it from cache? my $sql = "select * from asset"; my $where = " where asset.assetId=?"; @@ -368,7 +368,7 @@ around BUILDARGS => sub { $session->errorHandler->error("Asset $assetId $className $revisionDate is missing properties. Consult your database tables for corruption. "); return undef; } - eval{ $session->cache->set(["asset",$assetId,$revisionDate], $properties, 60*60*24) }; + eval{ $session->cache->set("asset".$assetId.$revisionDate, $properties, 60*60*24) }; } if (defined $properties) { @@ -2369,7 +2369,7 @@ sub purgeCache { $stow->delete('assetLineage'); $stow->delete('assetClass'); $stow->delete('assetRevision'); - eval{$self->session->cache->delete(["asset",$self->getId,$self->get("revisionDate")])}; + eval{$self->session->cache->delete("asset".$self->getId.$self->get("revisionDate"))}; } diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm index 78e998c42..3da563f43 100644 --- a/lib/WebGUI/Asset/Snippet.pm +++ b/lib/WebGUI/Asset/Snippet.pm @@ -165,30 +165,6 @@ sub exportGetUrlAsPath { #------------------------------------------------------------------- -=head2 getCache ( $calledAsWebMethod ) - -Overrides the base method to handle Snippet specific caching. - -=head3 $calledAsWebMethod - -If this is true, then change the cache key. - -=cut - -sub getCache { - my $self = shift; - my $calledAsWebMethod = shift; - my $session = $self->session; - my $cacheKey = "view_".$calledAsWebMethod.'_'.$self->getId; - if ($session->env->sslRequest) { - $cacheKey .= '_ssl'; - } - my $cache = WebGUI::Cache->new($session, $cacheKey); - return $cache; -} - -#------------------------------------------------------------------- - =head2 getToolbar ( ) Returns a toolbar with a set of icons that hyperlink to functions that delete, edit, promote, demote, cut, and copy. diff --git a/lib/WebGUI/Asset/Wobject/HttpProxy.pm b/lib/WebGUI/Asset/Wobject/HttpProxy.pm index bc4db5bf2..7affd50e9 100644 --- a/lib/WebGUI/Asset/Wobject/HttpProxy.pm +++ b/lib/WebGUI/Asset/Wobject/HttpProxy.pm @@ -270,8 +270,8 @@ override purgeCache => sub { my $self = shift; my $cache = $self->session->cache; eval { - $cache->delete([$self->proxiedUrl,"URL"]); - $cache->delete([$self->proxiedUrl,"HEADER"]); + $cache->delete($self->proxiedUrl."_URL"); + $cache->delete($self->proxiedUrl."_HEADER"); }; super(); }; @@ -317,8 +317,8 @@ sub view { my $cache = $self->session->cache; if ($requestMethod =~ /^GET$/i) { eval { - $var{header} = $cache->get([$proxiedUrl,'HEADER']); - $var{content} = $cache->get([$proxiedUrl,"URL"]); + $var{header} = $cache->get($proxiedUrl.'_HEADER'); + $var{content} = $cache->get($proxiedUrl."_URL"); }; } @@ -460,8 +460,8 @@ sub view { } unless ($self->cacheTimeout <= 10) { eval{ - $cache->set([$proxiedUrl,'URL'], $var{content}, $self->cacheTimeout); - $cache->set([$proxiedUrl,'HEADER'], $var{header}, $self->cacheTimeout); + $cache->set($proxiedUrl.'URL', $var{content}, $self->cacheTimeout); + $cache->set($proxiedUrl.'HEADER', $var{header}, $self->cacheTimeout); }; } } diff --git a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm index c8efaeb82..b7a2ba715 100644 --- a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm +++ b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm @@ -115,23 +115,36 @@ Combines all feeds into a single XML::FeedPP object. sub generateFeed { my $self = shift; my $limit = shift || $self->maxHeadlines; + my $session = $self->session; + my ( $log, $cache ) = $session->quick(qw( log cache )); my $feed = XML::FeedPP::Atom->new(); - my $log = $self->session->log; # build one feed out of many my $newlyCached = 0; - my $cache = $self->session->cache; foreach my $url (split(/\s+/, $self->rssUrl)) { $log->info("Processing FEED: ".$url); $url =~ s/^feed:/http:/; if ($self->processMacroInRssUrl) { WebGUI::Macro::process($self->session, \$url); } - my $value = eval{$cache->get($url)}; - unless ($value) { - $value = eval{$cache->setByHttp($url, $self->cacheTimeout)}; - $newlyCached = 1; - } + + my $value = $cache->compute( $url, sub { + my $ua = LWP::UserAgent->new( + env_proxy => 1, + agent => "WebGUI/" . $WebGUI::VERSION, + timeout => 30, + ); + + my $r = $ua->get( $url ); + if ( $r->is_error ) { + $session->log->warn( "Could not get syndicated content from '$url': " . $r->status_line ); + } + else { + $newlyCached = 1; + return $r->decoded_content; + } + }, $self->cacheTimeout ); + # if the content can be downgraded, it is either valid latin1 or didn't have # an HTTP Content-Encoding header. In the second case, XML::FeedPP will take # care of any encoding specified in the XML prolog @@ -142,7 +155,7 @@ sub generateFeed { $feed->merge_item($singleFeed); }; if ($@) { - $log->error("Syndicated Content asset (".$self->getId.") has a bad feed URL (".$url."). Failed with ".$@); + $log->warn("Syndicated Content asset (".$self->getId.") has a bad feed URL (".$url."). Failed with ".$@); } } @@ -159,7 +172,7 @@ sub generateFeed { } } - my %seen = {}; + my %seen = (); my @items = $feed->get_item; $feed->clear_item; ITEM: foreach my $item (@items) { diff --git a/lib/WebGUI/Cache.pm b/lib/WebGUI/Cache.pm index 723460abb..c4d05149c 100644 --- a/lib/WebGUI/Cache.pm +++ b/lib/WebGUI/Cache.pm @@ -457,16 +457,19 @@ sub setByHttp { if ($debug) { $self->session->log->debug("Called setByHttp() with URL $url."); } - my $userAgent = new LWP::UserAgent; - $userAgent->env_proxy; - $userAgent->agent("WebGUI/".$WebGUI::VERSION); - $userAgent->timeout(30); - my $header = new HTTP::Headers; - my $referer = "http://webgui.http.request/".$self->session->env->get("SERVER_NAME").$self->session->env->get("REQUEST_URI"); - chomp $referer; - $header->referer($referer); - my $request = HTTP::Request->new(GET => $url, $header); - my $response = $userAgent->request($request); + + # Why is this being done? + my $referer = "http://webgui.http.request/".$self->session->env->get("SERVER_NAME").$self->session->env->get("REQUEST_URI"); + chomp $referer; + + my $ua = LWP::UserAgent->new( + env_proxy => 1, + agent => "WebGUI/" . $WebGUI::VERSION, + timeout => 30, + default_headers => HTTP::Headers->new( referer => $referer ), + ); + + my $response = $ua->get( $url ); if ($response->is_error) { $self->session->log->error("$url could not be retrieved."); if ($debug) { diff --git a/lib/WebGUI/Operation/Statistics.pm b/lib/WebGUI/Operation/Statistics.pm index 8e9265837..659ecb458 100644 --- a/lib/WebGUI/Operation/Statistics.pm +++ b/lib/WebGUI/Operation/Statistics.pm @@ -182,13 +182,26 @@ sub www_viewStatistics { return $session->privilege->adminOnly() unless canView($session); my ($output, $data); my $i18n = WebGUI::International->new($session); - my $url = "http://update.webgui.org/latest-version.txt"; + + # Get the latest WebGUI version + my $url = "http://update.webgui.org/latest-version.txt"; my $cache = $session->cache; - my $version = eval{$cache->get($url)}; - if (not defined $version) { - $version = eval{$cache->setByHttp($url, 43200)}; - } - chomp $version; + my $value = $cache->compute( $url, sub { + my $ua = LWP::UserAgent->new( + env_proxy => 1, + agent => "WebGUI/" . $WebGUI::VERSION, + timeout => 30, + ); + + my $r = $ua->get( $url ); + if ( $r->is_error ) { + $session->log->warn( "Could not get latest WebGUI version from '$url': " . $r->status_line ); + } + else { + return $r->decoded_content; + } + } ); + $output .= ''; $output .= ''; if ($version ne $WebGUI::VERSION) { diff --git a/lib/WebGUI/Session/Scratch.pm b/lib/WebGUI/Session/Scratch.pm index d6195b7ef..b592b3eb7 100644 --- a/lib/WebGUI/Session/Scratch.pm +++ b/lib/WebGUI/Session/Scratch.pm @@ -65,7 +65,7 @@ sub delete { my $value = delete $self->{_data}{$name}; my $session = $self->session; my $id = $session->getId; - eval{$session->cache->set(["sessionscratch",$id], $self->{_data}, $session->setting->get('sessionTimeout'))}; + eval{$session->cache->set("sessionscratch_".$id, $self->{_data}, $session->setting->get('sessionTimeout'))}; $session->db->write("delete from userSessionScratch where name=? and sessionId=?", [$name, $id]); return $value; } @@ -84,7 +84,7 @@ sub deleteAll { delete $self->{_data}; my $session = $self->session; my $id = $session->getId; - eval{$session->cache->delete(["sessionscratch",$id])}; + eval{$session->cache->delete("sessionscratch_".$id)}; $session->db->write("delete from userSessionScratch where sessionId=?", [$id]); } @@ -198,7 +198,7 @@ The current session. sub new { my ($class, $session) = @_; - my $scratch = eval{$session->cache->get(["sessionscratch",$session->getId])}; + my $scratch = eval{$session->cache->get("sessionscratch_".$session->getId)}; unless (ref $scratch eq "HASH") { $scratch = $session->db->buildHashRef("select name,value from userSessionScratch where sessionId=?",[$session->getId], {noOrder => 1}); } @@ -253,7 +253,7 @@ sub set { $self->{_data}{$name} = $value; my $session = $self->session; my $id = $session->getId; - eval{$session->cache->set(["sessionscratch",$id], $self->{_data}, $session->setting->get('sessionTimeout'))}; + eval{$session->cache->set("sessionscratch_".$id, $self->{_data}, $session->setting->get('sessionTimeout'))}; $session->db->write("replace into userSessionScratch (sessionId, name, value) values (?,?,?)", [$id, $name, $value]); } diff --git a/lib/WebGUI/Session/Var.pm b/lib/WebGUI/Session/Var.pm index 3641ae66f..af98a61c0 100644 --- a/lib/WebGUI/Session/Var.pm +++ b/lib/WebGUI/Session/Var.pm @@ -71,7 +71,7 @@ sub end { my $self = shift; my $session = $self->session; my $id = $self->getId; - eval{$session->cache->delete(['session',$id])}; + eval{$session->cache->delete($id)}; $session->scratch->deleteAll; $session->db->write("delete from userSession where sessionId=?",[$id]); delete $session->{_user}; @@ -176,7 +176,7 @@ sub new { $self->start(1); } else { ##existing session requested - $self->{_var} = eval{$session->cache->get(['session',$sessionId])}; + $self->{_var} = eval{$session->cache->get($sessionId)}; unless ($self->{_var}{sessionId} eq $sessionId) { $self->{_var} = $session->db->quickHashRef("select * from userSession where sessionId=?",[$sessionId]); } @@ -202,7 +202,7 @@ sub new { } else { $self->{_var}{nextCacheFlush} = $time + $session->config->get("hotSessionFlushToDb"); - eval{$session->cache->set(['session',$sessionId], $self->{_var}, $timeout)}; + eval{$session->cache->set($sessionId, $self->{_var}, $timeout)}; } $self->session->{_sessionId} = $self->{_var}{sessionId}; return $self; @@ -264,7 +264,7 @@ sub start { userId => $userId }; $self->session->{_sessionId} = $sessionId; - eval{$session->cache->set(['session',$sessionId], $self->{_var}, $timeout)}; + eval{$session->cache->set($sessionId, $self->{_var}, $timeout)}; delete $self->{_var}{nextCacheFlush}; $session->db->setRow("userSession","sessionId",$self->{_var},$sessionId); $self->{_sessionId} = $sessionId; @@ -283,7 +283,7 @@ sub switchAdminOff { my $self = shift; $self->{_var}{adminOn} = 0; my $session = $self->session; - eval{$session->cache->set(['session',$self->getId], $self->{_var}, $session->setting->get('sessionTimeout'))}; + eval{$session->cache->set($self->getId, $self->{_var}, $session->setting->get('sessionTimeout'))}; delete $self->{_var}{nextCacheFlush}; $session->db->setRow("userSession","sessionId", $self->{_var}); } @@ -300,7 +300,7 @@ sub switchAdminOn { my $self = shift; $self->{_var}{adminOn} = 1; my $session = $self->session; - eval{$session->cache->set(['session',$self->getId], $self->{_var}, $session->setting->get('sessionTimeout'))}; + eval{$session->cache->set($self->getId, $self->{_var}, $session->setting->get('sessionTimeout'))}; delete $self->{_var}{nextCacheFlush}; $self->session->db->setRow("userSession","sessionId", $self->{_var}); } diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index f7cba2579..237e5188b 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -282,7 +282,7 @@ sub cache { for my $k (qw(_userId _user _profile)) { $userData{$k} = $self->{$k}; } - eval{$self->session->cache->set(["user",$self->userId], \%userData, 60*60*24)}; + eval{$self->session->cache->set($self->userId, \%userData, 60*60*24)}; } #------------------------------------------------------------------- @@ -1058,7 +1058,7 @@ sub new { my $userId = shift || 1; my $overrideId = shift; $userId = _create($session, $overrideId) if ($userId eq "new"); - my $self = eval{$session->cache->get(["user",$userId])} || {}; + my $self = eval{$session->cache->get($userId)} || {}; bless $self, $class; $self->{_session} = $session; unless ($self->{_userId} && $self->{_user}{username}) { @@ -1332,7 +1332,7 @@ Deletes this user object out of the cache. sub uncache { my $self = shift; - eval{$self->session->cache->delete(["user",$self->userId])}; + eval{$self->session->cache->delete($self->userId)}; } #---------------------------------------------------------------------------- diff --git a/sbin/testEnvironment.pl b/sbin/testEnvironment.pl index 7a4dc6868..332d458e9 100755 --- a/sbin/testEnvironment.pl +++ b/sbin/testEnvironment.pl @@ -145,6 +145,8 @@ checkModule("Business::PayPal::API", "0.62" ); checkModule("Locales", "0.10" ); checkModule("Test::Harness", "3.17" ); checkModule("DateTime::Event::ICal", "0.10" ); +checkModule( "CHI", ); +checkModule( "Cache::FastMmap", ); failAndExit("Required modules are missing, running no more checks.") if $missingModule; From 970ac6121d1fb92435fc3fce1ed8258f8e363d56 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 19 Apr 2010 14:59:42 -0500 Subject: [PATCH 12/36] remove old and busted for new hotness --- lib/WebGUI/Cache.pm | 541 -------------------------------------------- 1 file changed, 541 deletions(-) delete mode 100644 lib/WebGUI/Cache.pm diff --git a/lib/WebGUI/Cache.pm b/lib/WebGUI/Cache.pm deleted file mode 100644 index c4d05149c..000000000 --- a/lib/WebGUI/Cache.pm +++ /dev/null @@ -1,541 +0,0 @@ -package WebGUI::Cache; - -=head1 LEGAL - - ------------------------------------------------------------------- - 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 - ------------------------------------------------------------------- - -=cut - -use strict; -use File::Path (); -use HTTP::Headers; -use HTTP::Request; -use LWP::UserAgent; -use Memcached::libmemcached; -use Storable (); -use WebGUI::Exception; -use Params::Validate qw(:all); -Params::Validate::validation_options( on_fail => sub { - my $error = shift; - warn "Error in Cache params: ".$error; - WebGUI::Error::InvalidParam->throw( error => $error ); - } ); - - - -=head1 NAME - -Package WebGUI::Cache - -=head1 DESCRIPTION - -A base class for all Cache modules to extend. - -=head1 SYNOPSIS - - use WebGUI::Cache; - - my $cache = WebGUI::Cache->new($session, "my app cache"); - my $cache = WebGUI::Cache->new($session, [ "my app", $assetId, $version ]); - - $cache->set($value); - $cache->setByHTTP("http://www.google.com/"); - - my $value = $cache->get($name); - my ($val1, $val2) = @{$cache->mget([$name1, $name2])}; - - $cache->delete($name); - - $cache->flush; - -=head1 METHODS - -These methods are available from this class: - -=cut - - -#------------------------------------------------------------------- - -=head2 delete ( name ) - -Delete a key from the cache. - -Throws WebGUI::Error::InvalidParam, WebGUI::Error::Connection and WebGUI::Error. - -=head3 name - -Delete a key from the cache. Must be overridden. - -=cut - -sub delete { - my $self = shift; - my $debug = $self->withDebug; - my ($name) = ($debug) ? validate_pos(@_, { type => SCALAR | ARRAYREF }) : @_; - my $key = $self->parseKey($name); - if ($debug) { - $self->session->log->debug("Called delete() on cache key $key."); - } - my $memcached = $self->getMemcached; - Memcached::libmemcached::memcached_delete($memcached, $key); - if ($debug) { - my $log = $self->session->log; - if ($memcached->errstr eq 'SYSTEM ERROR Unknown error: 0') { - $log->debug("Cannot connect to memcached server."); - WebGUI::Error::Connection->throw( - error => "Cannot connect to memcached server." - ); - } - elsif ($memcached->errstr eq 'NOT FOUND' ) { - $log->debug("The cache key $key has no value."); - WebGUI::Error::ObjectNotFound->throw( - error => "The cache key $key has no value.", - id => $key, - ); - } - elsif ($memcached->errstr eq 'NO SERVERS DEFINED') { - $log->warn("No memcached servers specified in config file."); - WebGUI::Error->throw( - error => "No memcached servers specified in config file." - ); - } - elsif ($memcached->errstr ne 'SUCCESS' # deleted - && $memcached->errstr ne 'PROTOCOL ERROR' # doesn't exist to delete - ) { - $log->debug("Couldn't delete $key from cache because ".$memcached->errstr); - WebGUI::Error->throw( - error => "Couldn't delete $key from cache because ".$memcached->errstr - ); - } - } -} - -#------------------------------------------------------------------- - -=head2 flush ( ) - -Empties the caching system. - -Throws WebGUI::Error::Connection and WebGUI::Error. - -=cut - -sub flush { - my ($self) = @_; - my $debug = $self->withDebug; - if ($debug) { - $self->session->log->debug("Called flush() on cache."); - } - my $memcached = $self->getMemcached; - Memcached::libmemcached::memcached_flush($memcached); - if ($debug) { - my $log = $self->session->log; - if ($memcached->errstr eq 'SYSTEM ERROR Unknown error: 0') { - $log->debug("Cannot connect to memcached server."); - WebGUI::Error::Connection->throw( - error => "Cannot connect to memcached server." - ); - } - elsif ($memcached->errstr eq 'NO SERVERS DEFINED') { - $log->warn("No memcached servers specified in config file."); - WebGUI::Error->throw( - error => "No memcached servers specified in config file." - ); - } - elsif ($memcached->errstr ne 'SUCCESS') { - $log->debug("Couldn't flush cache because ".$memcached->errstr); - WebGUI::Error->throw( - error => "Couldn't flush cache because ".$memcached->errstr - ); - } - } -} - -#------------------------------------------------------------------- - -=head2 deleteChunk ( key ) - -Deletes a bunch of keys from the cache based upon a partial composite key. Unless overridden by the cache subclass this will just flush the whole cache. - -Throws WebGUI::Error::InvalidObject, WebGUI::Error::InvalidParam, WebGUI::Error::ObjectNotFound, WebGUI::Error::Connection and WebGUI::Error. - -=head3 name - -An array reference representing the portion of the key to delete. So if you have a key like ["asset","abc","def"] and you want to delete all items that match abc, you'd specify ["asset","abc"]. - -=cut - -sub get { - my $self = shift; - my $debug = $self->withDebug; - my ($name) = ($debug) ? validate_pos(@_, { type => SCALAR | ARRAYREF }) : @_; - my $key = $self->parseKey($name); - if ($debug) { - $self->session->log->debug("Called get() on cache key $key."); - } - my $memcached = $self->getMemcached; - my $content = Memcached::libmemcached::memcached_get($memcached, $key); - $content = Storable::thaw($content); - if ($debug) { - my $log = $self->session->log; - if ($memcached->errstr eq 'SUCCESS') { - unless (ref $content) { - $log->debug("Couldn't thaw value for $key."); - WebGUI::Error::InvalidObject->throw( - error => "Couldn't thaw value for $key." - ); - } - return ${$content}; - } - elsif ($memcached->errstr eq 'NOT FOUND' ) { - $log->debug("The cache key $key has no value."); - WebGUI::Error::ObjectNotFound->throw( - error => "The cache key $key has no value.", - id => $key, - ); - } - elsif ($memcached->errstr eq 'NO SERVERS DEFINED') { - $log->warn("No memcached servers specified in config file."); - WebGUI::Error->throw( - error => "No memcached servers specified in config file." - ); - } - elsif ($memcached->errstr eq 'SYSTEM ERROR Unknown error: 0') { - $log->debug("Cannot connect to memcached server."); - WebGUI::Error::Connection->throw( - error => "Cannot connect to memcached server." - ); - } - $log->debug("Couldn't get $key from cache because ".$memcached->errstr); - WebGUI::Error->throw( - error => "Couldn't get $key from cache because ".$memcached->errstr - ); - return undef; - } - return (ref $content) ? ${$content} : undef; -} - -sub getMemcached { - return shift->{_memcached}; -} - -#------------------------------------------------------------------- - -=head2 mget ( names ) - -Retrieves multiple values from cache at once, which is much faster than retrieving one at a time. Returns an array reference containing the values in the order they were requested. - -Throws WebGUI::Error::InvalidParam, WebGUI::Error::Connection and WebGUI::Error. - -=head3 names - -Retrieves a key value from the cache. Must be overridden. - -=cut - -sub mget { - my $self = shift; - my $debug = $self->withDebug; - my ($names) = ($debug) ? validate_pos(@_, { type => ARRAYREF }) : @_; - my @keys = map { $self->parseKey($_) } @{ $names }; - my $log = $self->session->log; - if ($debug) { - $log->debug("Called mget() for keys (".join(", ",@keys).") on cache."); - } - my %result; - my $memcached = $self->getMemcached; - $memcached->mget_into_hashref(\@keys, \%result); - if ($debug) { - if ($memcached->errstr eq 'SYSTEM ERROR Unknown error: 0') { - $log->debug("Cannot connect to memcached server."); - WebGUI::Error::Connection->throw( - error => "Cannot connect to memcached server." - ); - } - elsif ($memcached->errstr eq 'NO SERVERS DEFINED') { - $log->warn("No memcached servers specified in config file."); - WebGUI::Error->throw( - error => "No memcached servers specified in config file." - ); - } - } - # no other useful status messages are returned - my @values; - foreach my $key (@keys) { - my $content = Storable::thaw($result{$key}); - unless (ref $content) { - $log->debug("Cannot thaw key $key.") if ($debug); - next; - } - push @values, ${$content}; - } - return \@values; -} - - -#------------------------------------------------------------------- - -=head2 new ( session, withDebug ) - -Constructor. Will return a handler for the configured caching mechanism. Defaults to WebGUI::Cache::FileCache. You must override this method when building your own cache plug-in. - -Throws WebGUI::Error::InvalidParam. - -=head3 session - -A reference to the current session. - -=head3 withDebug - -A boolean indicating you want to enable parameter validation, exception handling, and debug logging. Note that this will make the cahe system up to 3 times slower. It will still be very fast, but not production fast. - -=cut - -sub new { - my ($class, $session, $withDebug) = validate_pos(@_, - 1, - { isa => 'WebGUI::Session' }, - { type => SCALAR | UNDEF, optional=>1, default=>0 }, - ); - if ($withDebug) { - my $log = $session->log; - $log->debug("Instanciated cache object."); - $log->debug("Cache debugging ".($withDebug ? "enabled" : "disabled")."."); - } - my $config = $session->config; - my $namespace = $config->getFilename; - my $memcached = Memcached::libmemcached::memcached_create(); # no exception because always returns success - foreach my $server (@{$config->get('cacheServers')}) { - if (exists $server->{socket}) { - Memcached::libmemcached::memcached_server_add_unix_socket($memcached, $server->{socket}); # no exception because always returns success - } - else { - Memcached::libmemcached::memcached_server_add($memcached, $server->{host}, $server->{port}); # no exception because always returns success - } - } - bless {_memcached => $memcached, _namespace => $namespace, _session => $session, _withDebug=>$withDebug}, $class; -} - -#------------------------------------------------------------------- - -=head2 parseKey ( key ) - -Returns a formatted string version of the key. A class method. - -Throws WebGUI::Error::InvalidParam. - -=head3 name - -Can either be a text key, or a composite key. If it's a composite key, it will be an array reference of strings that can be joined together to create a key. You might want to use a composite key in order to be able to delete large portions of cache all at once. For instance, if you have a key of ["asset","abc","def"] you can delete all cache matching ["asset","abc"]. - -=cut - -sub parseKey { - my $self = shift; - my ($name) = ($self->withDebug) ? validate_pos(@_, { type => SCALAR | ARRAYREF }) : @_; - - # prepend namespace to the key - my @key = ($self->{_namespace}); - - # check for composite or simple key, make array from either - if (ref $name eq 'ARRAY') { - push @key, @{ $name }; - } - else { - push @key, $name; - } - foreach my $part (@key) { - # convert to octets, then md5 them - utf8::encode($part); - $part = Digest::MD5::md5_base64($part); - $part =~ tr{/}{-}; - } - return join('/', @key); -} - -#------------------------------------------------------------------- - -=head2 session ( ) - -Returns a reference to the current session. - -=cut - -sub session { - $_[0]->{_session}; -} - -#------------------------------------------------------------------- - -=head2 set ( value [, ttl] ) - -Throws WebGUI::Error::InvalidParam, WebGUI::Error::Connection, and WebGUI::Error. - -=head3 name - -The name of the key to set. - -=head3 value - -A scalar value to store. - -=head3 ttl - -A time in seconds for the cache to exist. When you override default it to 60 seconds. - -=cut - -sub set { - my $self = shift; - my $debug = $self->withDebug; - my ($name, $value, $ttl) = ($debug) ? validate_pos(@_, { type => SCALAR | ARRAYREF }, { type => SCALAR | ARRAYREF | HASHREF }, { type => SCALAR | UNDEF, optional => 1 }) : @_; - $ttl ||= 60; - my $key = $self->parseKey($name); - if ($debug) { - $self->session->log->debug("Called set() on cache key $key with $value as the value."); - } - my $frozenValue = Storable::nfreeze(\(scalar $value)); # Storable doesn't like non-reference arguments, so we wrap it in a scalar ref. - my $memcached = $self->getMemcached; - Memcached::libmemcached::memcached_set($memcached, $key, $frozenValue, $ttl); - if ($debug) { - my $log = $self->session->log; - if ($memcached->errstr eq 'SUCCESS') { - return $value; - } - elsif ($memcached->errstr eq 'SYSTEM ERROR Unknown error: 0') { - $log->debug("Cannot connect to memcached server."); - WebGUI::Error::Connection->throw( - error => "Cannot connect to memcached server." - ); - } - elsif ($memcached->errstr eq 'NO SERVERS DEFINED') { - $log->warn("No memcached servers specified in config file."); - WebGUI::Error->throw( - error => "No memcached servers specified in config file." - ); - } - $log->debug("Couldn't set $key to cache because ".$memcached->errstr); - WebGUI::Error->throw( - error => "Couldn't set $key to cache because ".$memcached->errstr - ); - } - return $value; -} - - -#------------------------------------------------------------------- - -=head2 setByHttp ( url [, ttl ] ) - -Retrieves a document via HTTP and stores it in the cache and returns the content as a string. No need to override. - -Throws WebGUI::Error::InvalidParam, WebGUI::Error::Connection, and WebGUI::Error. - -=head3 url - -The URL of the document to retrieve. It must begin with the standard "http://". This will be used as the key for this cache entry. - -=head3 ttl - -The time to live for this content. This is the amount of time (in seconds) that the content will remain in the cache. Defaults to "60". - -=cut - -sub setByHttp { - my $self = shift; - my $debug = $self->withDebug; - my ($url, $ttl) = ($debug) ? validate_pos(@_, { type => SCALAR }, { type => SCALAR, optional => 1 }) : @_; - if ($debug) { - $self->session->log->debug("Called setByHttp() with URL $url."); - } - - # Why is this being done? - my $referer = "http://webgui.http.request/".$self->session->env->get("SERVER_NAME").$self->session->env->get("REQUEST_URI"); - chomp $referer; - - my $ua = LWP::UserAgent->new( - env_proxy => 1, - agent => "WebGUI/" . $WebGUI::VERSION, - timeout => 30, - default_headers => HTTP::Headers->new( referer => $referer ), - ); - - my $response = $ua->get( $url ); - if ($response->is_error) { - $self->session->log->error("$url could not be retrieved."); - if ($debug) { - WebGUI::Error::Connection->throw( - error => "Couldn't fetch $url because ".$response->message, - resource => $url, - ); - } - } - return $self->set($url, $response->decoded_content, $ttl); -} - - -#------------------------------------------------------------------- - -=head2 withDebug () - -Returns a boolean indicating whether the cache system should log debug, validate parameters, and throw exceptions. - -=cut - -sub withDebug { - my $self = shift; - return $self->{_withDebug}; -} - - - -=head1 EXCEPTIONS - -This class throws a lot of inconvenient exceptions. However, because cache should be treated as optional, none of them matter except for testing, debugging, or in very specific use cases. Therefore the best practice is to simply call each method with an eval wrapper, and then not even bother testing for specific exceptions like this: - - my $value = eval { $session->cache->get($key) }; - unless (defined $value) { - $value = $db->fetchValueFromTheDatabase; - } - -If you want to see what exceptions are being thrown, or anything else about the internal operations of the cache system, simply turn on DEBUG mode in your log. Everything you want will be there. - -NOTE: In order for exceptions to be thrown and logged with debug must be passed into the constructor. - -The exceptions that can be thrown are: - -=head2 WebGUI::Error - -When an uknown exception happens, or there are no configured memcahed servers in the cacheServers directive in your config file. - -=head2 WebGUI::Error::Connection - -When it can't connect to the memcached servers that are configured, or to the http server in the case of the setByHttp method. - -=head2 WebGUI::Error::InvalidParam - -When you pass in the wrong arguments. - -=head2 WebGUI::Error::ObjectNotFound - -When you request a cache key that doesn't exist on any configured memcached server. - -=head2 WebGUI::Error::InvalidObject - -When an object can't be thawed from cache due to corruption of some sort. - -=cut - - -1; - - From 9a9b33b4b3752c9019a78b679e9fb9f3b5d54da7 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 19 Apr 2010 14:12:22 -0700 Subject: [PATCH 13/36] Double my creates old version tag that is not found outside the scope. --- lib/WebGUI/AssetVersioning.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WebGUI/AssetVersioning.pm b/lib/WebGUI/AssetVersioning.pm index 9674e1e5e..eeefe9f3b 100644 --- a/lib/WebGUI/AssetVersioning.pm +++ b/lib/WebGUI/AssetVersioning.pm @@ -110,7 +110,7 @@ sub addRevision { $workingTag = WebGUI::VersionTag->getWorking( $session ); } else { - my $oldWorking = WebGUI::VersionTag->getWorking($session, 'noCreate'); + $oldWorking = WebGUI::VersionTag->getWorking($session, 'noCreate'); $workingTag = WebGUI::VersionTag->new( $session, $parentAsset->tagId ); $workingTag->setWorking(); } From 963690641ea033e394e28328f031ef2213dd5e87 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 19 Apr 2010 16:16:49 -0700 Subject: [PATCH 14/36] Remove tests that only test Asset.pm, and not all Asset sub-classes. --- t/tests/Test/WebGUI/Asset.pm | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/t/tests/Test/WebGUI/Asset.pm b/t/tests/Test/WebGUI/Asset.pm index ed6b3619e..67b840186 100644 --- a/t/tests/Test/WebGUI/Asset.pm +++ b/t/tests/Test/WebGUI/Asset.pm @@ -255,40 +255,6 @@ sub getParent : Test(2) { $session->db->write("delete from assetData where assetId like 'wg8TestAsset00000%'"); } -sub addRevision : Test(6) { - my $test = shift; - my $session = $test->session; - note "addRevision"; - my $testId1 = 'wg8TestAsset0000000001'; - my $testId2 = 'wg8TestAsset0000000002'; - my $now = time(); - my $revisionDate = $now - 50; - my $baseLineage = $session->db->quickScalar('select lineage from asset where assetId=?',['PBasset000000000000002']); - my $testLineage = $baseLineage. '909090'; - $session->db->write("insert into asset (assetId, className, lineage) VALUES (?,?,?)", [$testId1, 'WebGUI::Asset', $testLineage]); - $session->db->write("insert into assetData (assetId, revisionDate, status) VALUES (?,?,?)", [$testId1, $revisionDate, 'approved']); - my $testLineage2 = $testLineage . '000001'; - $session->db->write("insert into asset (assetId, className, parentId, lineage) VALUES (?,?,?,?)", [$testId2, 'WebGUI::Asset', $testId1, $testLineage2]); - $session->db->write("insert into assetData (assetId, revisionDate) VALUES (?,?)", [$testId2, $revisionDate]); - - my $testAsset = WebGUI::Asset->new($session, $testId2, $revisionDate); - $testAsset->title('test title 43'); - $testAsset->write(); - my $tag = WebGUI::VersionTag->getWorking($session); - my $revAsset = $testAsset->addRevision({}, $now); - isa_ok $revAsset, 'WebGUI::Asset'; - is $revAsset->revisionDate, $now, 'revisionDate set correctly on new revision'; - is $revAsset->title, 'test title 43', 'data fetch from database correct'; - is $revAsset->revisedBy, $session->user->userId, 'revisedBy is current session user'; - is $revAsset->tagId, $tag->getId, 'tagId is current working tagId'; - my $count = $session->db->quickScalar('SELECT COUNT(*) from assetData where assetId=?',[$testId2]); - is $count, 2, 'two records in the database'; - WebGUI::Test->addToCleanup($tag); - - $session->db->write("delete from asset where assetId like 'wg8TestAsset00000%'"); - $session->db->write("delete from assetData where assetId like 'wg8TestAsset00000%'"); -} - sub newByPropertyHashRef : Test(2) { my $test = shift; my $session = $test->session; From 841e9d57849b70223d1f4e443311cf191b783fb8 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 19 Apr 2010 16:36:22 -0700 Subject: [PATCH 15/36] fix purgeCache in Asset.pm. Add a test for it to Asset.t --- lib/WebGUI/Asset.pm | 2 +- t/Asset.t | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 0f11632c7..262e93a9f 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -2369,7 +2369,7 @@ sub purgeCache { $stow->delete('assetLineage'); $stow->delete('assetClass'); $stow->delete('assetRevision'); - eval{$self->session->cache->delete("asset".$self->getId.$self->get("revisionDate"))}; + $self->session->cache->remove("asset".$self->getId.$self->get("revisionDate")); } diff --git a/t/Asset.t b/t/Asset.t index 6d4b5d004..2193794f7 100644 --- a/t/Asset.t +++ b/t/Asset.t @@ -21,7 +21,7 @@ use Test::Deep; use Test::Exception; use WebGUI::Exception; -plan tests => 62; +plan tests => 65; my $session = WebGUI::Test->session; @@ -159,6 +159,29 @@ my $session = WebGUI::Test->session; is $asset->title, 'Root', 'got the right asset'; } +{ + note "new (caching), purgeCache"; + my $testId = 'wg8TestAsset0000000001'; + my $revisionDate = time(); + $session->db->write("insert into asset (assetId) VALUES (?)", [$testId]); + $session->db->write("insert into assetData (assetId, revisionDate) VALUES (?,?)", [$testId, $revisionDate]); + + my $datum; + $datum = $session->cache->get("asset".$testId.$revisionDate); + is $datum, undef, 'no cache exists for the test assetId, yet'; + + my $testAsset = WebGUI::Asset->new($session, $testId, $revisionDate); + $datum = $session->cache->get("asset".$testId.$revisionDate); + isnt $datum, undef, 'cache was created on new (from db)'; + + $testAsset->purgeCache(); + $datum = $session->cache->get("asset".$testId.$revisionDate); + is $datum, undef, 'purgeCache removes the cache entry'; + + $session->db->write("delete from asset where assetId=?", [$testId]); + $session->db->write("delete from assetData where assetId=?", [$testId]); +} + { note "write, update"; From 165be5b38956ebf15f15f4ebef8025f1192f0a7e Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 19 Apr 2010 18:39:49 -0500 Subject: [PATCH 16/36] remove eval{} from caching code --- lib/WebGUI/Asset.pm | 4 ++-- lib/WebGUI/Asset/File.pm | 6 +++--- lib/WebGUI/Asset/File/Image.pm | 4 ++-- lib/WebGUI/Asset/File/ZipArchive.pm | 4 ++-- lib/WebGUI/Asset/Post.pm | 2 +- lib/WebGUI/Asset/Shortcut.pm | 6 +++--- lib/WebGUI/Asset/Snippet.pm | 4 ++-- lib/WebGUI/Asset/Wobject/Article.pm | 6 +++--- lib/WebGUI/Asset/Wobject/Collaboration.pm | 4 ++-- lib/WebGUI/Asset/Wobject/Folder.pm | 6 +++--- lib/WebGUI/Asset/Wobject/Layout.pm | 4 ++-- lib/WebGUI/Asset/Wobject/Matrix.pm | 8 ++++---- lib/WebGUI/Asset/Wobject/MessageBoard.pm | 6 +++--- lib/WebGUI/Asset/Wobject/SyndicatedContent.pm | 6 +++--- lib/WebGUI/Asset/Wobject/Thingy.pm | 4 ++-- lib/WebGUI/AssetLineage.pm | 2 +- lib/WebGUI/Group.pm | 8 ++++---- lib/WebGUI/Operation/Cache.pm | 2 +- lib/WebGUI/Operation/Settings.pm | 2 +- lib/WebGUI/Session/Scratch.pm | 12 ++++++------ lib/WebGUI/Session/Var.pm | 12 ++++++------ lib/WebGUI/User.pm | 6 +++--- 22 files changed, 59 insertions(+), 59 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 262e93a9f..937150049 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -350,7 +350,7 @@ around BUILDARGS => sub { } } - my $properties = eval{$session->cache->get("asset".$assetId.$revisionDate)}; + my $properties = $session->cache->get("asset".$assetId.$revisionDate); unless (exists $properties->{assetId}) { # can we get it from cache? my $sql = "select * from asset"; my $where = " where asset.assetId=?"; @@ -368,7 +368,7 @@ around BUILDARGS => sub { $session->errorHandler->error("Asset $assetId $className $revisionDate is missing properties. Consult your database tables for corruption. "); return undef; } - eval{ $session->cache->set("asset".$assetId.$revisionDate, $properties, 60*60*24) }; + $session->cache->set("asset".$assetId.$revisionDate, $properties, 60*60*24); } if (defined $properties) { diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index 85088f2b0..c4374b2bc 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -449,7 +449,7 @@ Extends the master method to clear the view cache. override purgeCache => sub { my $self = shift; - eval{$self->session->cache->delete("view_".$self->getId)}; + $self->session->cache->delete("view_".$self->getId); super(); }; @@ -584,7 +584,7 @@ Generate the view method for the Asset, and handle caching. sub view { my $self = shift; if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) { - my $out = eval{$self->session->cache->get($self->getViewCacheKey)}; + my $out = $self->session->cache->get($self->getViewCacheKey); return $out if $out; } my %var = %{$self->get}; @@ -594,7 +594,7 @@ sub view { $var{fileSize} = formatBytes($self->get("assetSize")); my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate}); if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) { - eval{$self->session->cache->set($self->getViewCacheKey, $out, $self->get("cacheTimeout"))}; + $self->session->cache->set($self->getViewCacheKey, $out, $self->get("cacheTimeout")); } return $out; } diff --git a/lib/WebGUI/Asset/File/Image.pm b/lib/WebGUI/Asset/File/Image.pm index 3e31ddef3..05900df9a 100644 --- a/lib/WebGUI/Asset/File/Image.pm +++ b/lib/WebGUI/Asset/File/Image.pm @@ -224,7 +224,7 @@ sub view { my $cache = $session->cache; my $cacheKey = $self->getWwwCacheKey('view'); if (!$session->var->isAdminOn && $self->cacheTimeout > 10) { - my $out = eval { $cache->get( $cacheKey ) }; + my $out = $cache->get( $cacheKey ); return $out if $out; } my %var = %{$self->get}; @@ -247,7 +247,7 @@ sub view { $var{parameters} .= sprintf("id=%s", $self->getId); my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate}); if (!$session->var->isAdminOn && $self->cacheTimeout > 10) { - eval{ $cache->set( $cacheKey, $out, $self->get("cacheTimeout") ) }; + $cache->set( $cacheKey, $out, $self->get("cacheTimeout") ); } return $out; } diff --git a/lib/WebGUI/Asset/File/ZipArchive.pm b/lib/WebGUI/Asset/File/ZipArchive.pm index c5b892836..431cf1080 100644 --- a/lib/WebGUI/Asset/File/ZipArchive.pm +++ b/lib/WebGUI/Asset/File/ZipArchive.pm @@ -186,7 +186,7 @@ sub view { my $cache = $self->session->cache; my $cacheKey = $self->getWwwCacheKey('view'); if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10) { - my $out = eval { $cache->get( $cacheKey ) }; + my $out = $cache->get( $cacheKey ); return $out if $out; } my %var = %{$self->get}; @@ -209,7 +209,7 @@ sub view { $var{noFileSpecified} = $i18n->get('noFileSpecified'); my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate}); if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10) { - eval{ $cache->set( $cacheKey, $out, $self->cacheTimeout) }; + $cache->set( $cacheKey, $out, $self->cacheTimeout); } return $out; } diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index 21afb2463..9cb885c08 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -1175,7 +1175,7 @@ Extend the base class to handle caching. override purgeCache => sub { my $self = shift; - eval{$self->session->cache->delete("view_".$self->getThread->getId)} if ($self->getThread); + $self->session->cache->delete("view_".$self->getThread->getId) if ($self->getThread); super(); }; diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index e793f8938..812f6d370 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -484,7 +484,7 @@ sub getOverrides { my $cache = $session->cache; my $u = WebGUI::User->new($self->session, $self->discernUserId); - my $overridesRef = eval{$cache->get($self->_overridesCacheTag)}; + my $overridesRef = $cache->get($self->_overridesCacheTag); ##If admin mode is not on, and the cache is valid, and not expired, and the user object was not updated, ##return the cached value. if ( ! $session->var->isAdminOn @@ -532,7 +532,7 @@ sub getOverrides { } } $overrides{userLastUpdated} = $session->user->get('lastUpdated'); - eval{$cache->set($self->_overridesCacheTag, \%overrides, 60*60)}; + $cache->set($self->_overridesCacheTag, \%overrides, 60*60); $overridesRef = \%overrides; return %{ $overridesRef }; } @@ -879,7 +879,7 @@ Delete any cached overrides. sub uncacheOverrides { my $self = shift; - eval{$self->session->cache->delete($self->_overridesCacheTag)}; + $self->session->cache->delete($self->_overridesCacheTag); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm index 3da563f43..8d4ca57b6 100644 --- a/lib/WebGUI/Asset/Snippet.pm +++ b/lib/WebGUI/Asset/Snippet.pm @@ -249,7 +249,7 @@ sub view { || ($versionTag && $versionTag->getId eq $self->tagId); my $cacheKey = $self->getWwwCacheKey('view', $calledAsWebMethod); unless ($noCache) { - my $out = eval { $session->cache->get( $cacheKey )}; + my $out = $session->cache->get( $cacheKey ); return $out if $out; } my $output = $self->usePacked @@ -262,7 +262,7 @@ sub view { } WebGUI::Macro::process($session,\$output); unless ($noCache) { - eval { $session->cache->set( $cacheKey, $output, $self->cacheTimeout) }; + $session->cache->set( $cacheKey, $output, $self->cacheTimeout); } return $output; } diff --git a/lib/WebGUI/Asset/Wobject/Article.pm b/lib/WebGUI/Asset/Wobject/Article.pm index c75bca557..355dfe652 100644 --- a/lib/WebGUI/Asset/Wobject/Article.pm +++ b/lib/WebGUI/Asset/Wobject/Article.pm @@ -290,7 +290,7 @@ See WebGUI::Asset::purgeCache() for details. override purgeCache => sub { my $self = shift; - eval{$self->session->cache->delete("view_".$self->getId)}; + $self->session->cache->delete("view_".$self->getId); super(); }; @@ -322,7 +322,7 @@ sub view { my $cache = $self->session->cache; if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10 && !$self->session->form->process("overrideTemplateId") && !$self->session->form->process($self->paginateVar) && !$self->session->form->process("makePrintable")) { - my $out = eval{$cache->get($self->getViewCacheKey)}; + my $out = $cache->get($self->getViewCacheKey); return $out if $out; } my %var; @@ -386,7 +386,7 @@ sub view { my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate}); if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10 && !$self->session->form->process("overrideTemplateId") && !$self->session->form->process($self->paginateVar) && !$self->session->form->process("makePrintable")) { - eval{$cache->set($self->getViewCacheKey, $out, $self->cacheTimeout)}; + $cache->set($self->getViewCacheKey, $out, $self->cacheTimeout); } return $out; } diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index b53992401..f6d48e4e5 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -1584,7 +1584,7 @@ sub view { my $self = shift; my $cache = $self->session->cache; if ($self->_visitorCacheOk) { - my $out = eval{$cache->get($self->_visitorCacheKey)}; + my $out = $cache->get($self->_visitorCacheKey); $self->session->errorHandler->debug("HIT") if $out; return $out if $out; } @@ -1595,7 +1595,7 @@ sub view { $self->prepareView unless ($self->{_viewTemplate}); my $out = $self->processTemplate($self->getViewTemplateVars,undef,$self->{_viewTemplate}); if ($self->_visitorCacheOk) { - eval{$cache->set($self->_visitorCacheKey, $out, $self->visitorCacheTimeout)}; + $cache->set($self->_visitorCacheKey, $out, $self->visitorCacheTimeout); } return $out; } diff --git a/lib/WebGUI/Asset/Wobject/Folder.pm b/lib/WebGUI/Asset/Wobject/Folder.pm index 575b1eefd..e176e9732 100644 --- a/lib/WebGUI/Asset/Wobject/Folder.pm +++ b/lib/WebGUI/Asset/Wobject/Folder.pm @@ -190,7 +190,7 @@ See WebGUI::Asset::purgeCache() for details. override purgeCache => sub { my $self = shift; - eval{$self->session->cache->delete("view_".$self->getId)}; + $self->session->cache->delete("view_".$self->getId); super(); }; @@ -209,7 +209,7 @@ sub view { # Use cached version for visitors my $cache = $self->session->cache; if ($self->session->user->isVisitor) { - my $out = eval{$cache->get("view_".$self->getId)}; + my $out = $cache->get("view_".$self->getId); return $out if $out; } @@ -274,7 +274,7 @@ sub view { # Update the cache if ($self->session->user->isVisitor) { - eval{$cache->set("view_".$self->getId, $out, $self->visitorCacheTimeout)}; + $cache->set("view_".$self->getId, $out, $self->visitorCacheTimeout); } return $out; diff --git a/lib/WebGUI/Asset/Wobject/Layout.pm b/lib/WebGUI/Asset/Wobject/Layout.pm index 2e26e8710..87cf0ec5e 100644 --- a/lib/WebGUI/Asset/Wobject/Layout.pm +++ b/lib/WebGUI/Asset/Wobject/Layout.pm @@ -419,12 +419,12 @@ override www_view => sub { return $check if (defined $check); my $cacheKey = $self->getWwwCacheKey('view'); my $cache = $session->cache; - my $out = eval{ $cache->get($cacheKey) }; + my $out = $cache->get($cacheKey); unless ($out) { $self->prepareView; $session->stow->set("cacheFixOverride", 1); $out = $self->processStyle($self->view, { noHeadTags => 1 }); - eval{ $cache->set($cacheKey, $out, 60) }; + $cache->set($cacheKey, $out, 60); $session->stow->delete("cacheFixOverride"); } # keep those ads rotating even though the output is cached diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index eaeacae0c..8907288c3 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -486,7 +486,7 @@ sub getListings { || ($versionTag && $versionTag->getId eq $self->tagId); my $cache = $session->cache; unless ($noCache) { - $listingsEncoded = eval{$cache->get("matrixListings_".$self->getId)}; + $listingsEncoded = $cache->get("matrixListings_".$self->getId); } if ($listingsEncoded){ @@ -526,7 +526,7 @@ assetData.revisionDate } $listingsEncoded = JSON->new->encode($listings); - eval{$cache->set("matrixListings_".$self->getId, $listingsEncoded, $self->listingsCacheTimeout)}; + $cache->set("matrixListings_".$self->getId, $listingsEncoded, $self->listingsCacheTimeout); } return $listings; } @@ -647,7 +647,7 @@ sub view { || ($versionTag && $versionTag->getId eq $self->tagId); my $cache = $session->cache; unless ($noCache) { - $varStatisticsEncoded = eval{$cache->get("matrixStatistics_".$self->getId)}; + $varStatisticsEncoded = $cache->get("matrixStatistics_".$self->getId); } if ($varStatisticsEncoded){ @@ -797,7 +797,7 @@ sub view { [$self->getId]); $varStatisticsEncoded = JSON->new->encode($varStatistics); - eval{$cache->set("matrixStatistics_".$self->getId, $varStatisticsEncoded, $self->statisticsCacheTimeout)}; + $cache->set("matrixStatistics_".$self->getId, $varStatisticsEncoded, $self->statisticsCacheTimeout); } foreach my $statistic (keys %{$varStatistics}) { diff --git a/lib/WebGUI/Asset/Wobject/MessageBoard.pm b/lib/WebGUI/Asset/Wobject/MessageBoard.pm index b2db08a68..a7f188da8 100644 --- a/lib/WebGUI/Asset/Wobject/MessageBoard.pm +++ b/lib/WebGUI/Asset/Wobject/MessageBoard.pm @@ -72,7 +72,7 @@ See WebGUI::Asset::purgeCache() for details. override purgeCache => sub { my $self = shift; - eval{$self->session->cache->delete("view_".$self->getId)}; + $self->session->cache->delete("view_".$self->getId); super(); }; @@ -88,7 +88,7 @@ sub view { my $self = shift; my $cache = $self->session->cache; if ($self->session->user->isVisitor) { - my $out = eval{$cache->get("view_".$self->getId)}; + my $out = $cache->get("view_".$self->getId); return $out if $out; } my %var; @@ -153,7 +153,7 @@ sub view { my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate}); if ($self->session->user->isVisitor) { - eval{$cache->set("view_".$self->getId, $out, $self->visitorCacheTimeout)}; + $cache->set("view_".$self->getId, $out, $self->visitorCacheTimeout); } return $out; } diff --git a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm index b7a2ba715..f552dceb4 100644 --- a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm +++ b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm @@ -319,7 +319,7 @@ See WebGUI::Asset::purgeCache() for details. override purgeCache => sub { my $self = shift; - eval{$self->session->cache->delete("view_".$self->getId)}; + $self->session->cache->delete("view_".$self->getId); super(); }; @@ -337,7 +337,7 @@ sub view { # try the cached version my $cache = $session->cache; - my $out = eval{$cache->get("view_".$self->getId)}; + my $out = $cache->get("view_".$self->getId); return $out if ($out ne "" && !$session->var->isAdminOn); #return $out if $out; @@ -345,7 +345,7 @@ sub view { my $feed = $self->generateFeed; $out = $self->processTemplate($self->getTemplateVariables($feed),undef,$self->{_viewTemplate}); if (!$session->var->isAdminOn && $self->cacheTimeout > 10) { - eval{$cache->set("view_".$self->getId, $out, $self->cacheTimeout)}; + $cache->set("view_".$self->getId, $out, $self->cacheTimeout); } return $out; } diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index 2ee798035..d6e09c4b2 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -2656,7 +2656,7 @@ sub www_export { push(@fieldLabels,@metaDataFields) } - $query = eval{$session->cache->get("query_".$thingId)}; + $query = $session->cache->get("query_".$thingId); $sth = $session->db->read($query); ### Loop through the returned structure and put it through Text::CSV @@ -3301,7 +3301,7 @@ sequenceNumber'); } # store query in cache for thirty minutes - eval{$self->session->cache->set("query_".$thingId, $query, 30*60)}; + $self->session->cache->set("query_".$thingId, $query, 30*60); $paginatePage = $self->session->form->param('pn') || 1; $currentUrl = $self->session->url->append($currentUrl, "orderBy=".$orderBy) if $orderBy; diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index 0507afddf..3ba41e5dc 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -152,7 +152,7 @@ sub cascadeLineage { [$newLineage, length($oldLineage) + 1, $oldLineage . '%'] ); if ($records > 20) { - eval{$self->session->cache->flush}; + $self->session->cache->flush; } else { my $descendants = $self->session->db->read("SELECT assetId FROM asset WHERE lineage LIKE ?", [$newLineage . '%']); diff --git a/lib/WebGUI/Group.pm b/lib/WebGUI/Group.pm index 97ceb3c7f..d387d3673 100644 --- a/lib/WebGUI/Group.pm +++ b/lib/WebGUI/Group.pm @@ -126,7 +126,7 @@ not be added to any group. Groups may not be added to themselves. sub addGroups { my $self = shift; my $groups = shift; - eval{$self->session->cache->delete($self->getId)}; + $self->session->cache->delete($self->getId); GROUP: foreach my $gid (@{$groups}) { next if ($gid eq '1'); next if ($gid eq $self->getId); @@ -233,7 +233,7 @@ sub clearCaches { my $groups = $self->getAllGroupsFor(); my $cache = $self->session->cache; foreach my $group ( $self->getId, @{ $groups } ) { - eval{$cache->delete($group)}; + $cache->delete($group); } my $stow = $self->session->stow; $stow->delete("groupObj"); @@ -562,7 +562,7 @@ sub getAllUsers { my $loopCount = shift; my $expireTime = 0; my $cache = $self->session->cache; - my $value = eval{$cache->get($self->getId)}; + my $value = $cache->get($self->getId); return $value if defined $value; my @users = (); push @users, @@ -587,7 +587,7 @@ sub getAllUsers { } my %users = map { $_ => 1 } @users; @users = keys %users; - eval{$cache->set($self->getId, \@users, $self->groupCacheTimeout)}; + $cache->set($self->getId, \@users, $self->groupCacheTimeout); return \@users; } diff --git a/lib/WebGUI/Operation/Cache.pm b/lib/WebGUI/Operation/Cache.pm index 6715b894c..1f231d1e1 100644 --- a/lib/WebGUI/Operation/Cache.pm +++ b/lib/WebGUI/Operation/Cache.pm @@ -92,7 +92,7 @@ sub www_flushCache { return $session->privilege->adminOnly unless canView($session); # Flush the cache - eval{$session->cache->flush}; + $session->cache->flush; return www_manageCache($session); } diff --git a/lib/WebGUI/Operation/Settings.pm b/lib/WebGUI/Operation/Settings.pm index e98b4712d..3961ff061 100644 --- a/lib/WebGUI/Operation/Settings.pm +++ b/lib/WebGUI/Operation/Settings.pm @@ -736,7 +736,7 @@ sub www_saveSettings { $session->db->write( "UPDATE userProfileData SET showMessageOnLoginSeen=0" ); - eval{$session->cache->flush}; + $session->cache->flush; } return www_editSettings($session, { errors => \@errors, message => $i18n->get("editSettings done") }); diff --git a/lib/WebGUI/Session/Scratch.pm b/lib/WebGUI/Session/Scratch.pm index b592b3eb7..6b9405394 100644 --- a/lib/WebGUI/Session/Scratch.pm +++ b/lib/WebGUI/Session/Scratch.pm @@ -65,7 +65,7 @@ sub delete { my $value = delete $self->{_data}{$name}; my $session = $self->session; my $id = $session->getId; - eval{$session->cache->set("sessionscratch_".$id, $self->{_data}, $session->setting->get('sessionTimeout'))}; + $session->cache->set("sessionscratch_".$id, $self->{_data}, $session->setting->get('sessionTimeout')); $session->db->write("delete from userSessionScratch where name=? and sessionId=?", [$name, $id]); return $value; } @@ -84,7 +84,7 @@ sub deleteAll { delete $self->{_data}; my $session = $self->session; my $id = $session->getId; - eval{$session->cache->delete("sessionscratch_".$id)}; + $session->cache->delete("sessionscratch_".$id); $session->db->write("delete from userSessionScratch where sessionId=?", [$id]); } @@ -107,7 +107,7 @@ sub deleteName { return undef unless ($name); delete $self->{_data}{$name}; my $session = $self->session; - eval{$session->cache->flush}; + $session->cache->flush; $session->db->write("delete from userSessionScratch where name=?", [$name]); } @@ -134,7 +134,7 @@ sub deleteNameByValue { return undef unless ($name and defined $value); delete $self->{_data}{$name} if ($self->{_data}{$name} eq $value); my $session = $self->session; - eval{$session->cache->flush}; + $session->cache->flush; $session->db->write("delete from userSessionScratch where name=? and value=?", [$name,$value]); } @@ -198,7 +198,7 @@ The current session. sub new { my ($class, $session) = @_; - my $scratch = eval{$session->cache->get("sessionscratch_".$session->getId)}; + my $scratch = $session->cache->get("sessionscratch_".$session->getId); unless (ref $scratch eq "HASH") { $scratch = $session->db->buildHashRef("select name,value from userSessionScratch where sessionId=?",[$session->getId], {noOrder => 1}); } @@ -253,7 +253,7 @@ sub set { $self->{_data}{$name} = $value; my $session = $self->session; my $id = $session->getId; - eval{$session->cache->set("sessionscratch_".$id, $self->{_data}, $session->setting->get('sessionTimeout'))}; + $session->cache->set("sessionscratch_".$id, $self->{_data}, $session->setting->get('sessionTimeout')); $session->db->write("replace into userSessionScratch (sessionId, name, value) values (?,?,?)", [$id, $name, $value]); } diff --git a/lib/WebGUI/Session/Var.pm b/lib/WebGUI/Session/Var.pm index af98a61c0..73a058172 100644 --- a/lib/WebGUI/Session/Var.pm +++ b/lib/WebGUI/Session/Var.pm @@ -71,7 +71,7 @@ sub end { my $self = shift; my $session = $self->session; my $id = $self->getId; - eval{$session->cache->delete($id)}; + $session->cache->delete($id); $session->scratch->deleteAll; $session->db->write("delete from userSession where sessionId=?",[$id]); delete $session->{_user}; @@ -176,7 +176,7 @@ sub new { $self->start(1); } else { ##existing session requested - $self->{_var} = eval{$session->cache->get($sessionId)}; + $self->{_var} = $session->cache->get($sessionId); unless ($self->{_var}{sessionId} eq $sessionId) { $self->{_var} = $session->db->quickHashRef("select * from userSession where sessionId=?",[$sessionId]); } @@ -202,7 +202,7 @@ sub new { } else { $self->{_var}{nextCacheFlush} = $time + $session->config->get("hotSessionFlushToDb"); - eval{$session->cache->set($sessionId, $self->{_var}, $timeout)}; + $session->cache->set($sessionId, $self->{_var}, $timeout); } $self->session->{_sessionId} = $self->{_var}{sessionId}; return $self; @@ -264,7 +264,7 @@ sub start { userId => $userId }; $self->session->{_sessionId} = $sessionId; - eval{$session->cache->set($sessionId, $self->{_var}, $timeout)}; + $session->cache->set($sessionId, $self->{_var}, $timeout); delete $self->{_var}{nextCacheFlush}; $session->db->setRow("userSession","sessionId",$self->{_var},$sessionId); $self->{_sessionId} = $sessionId; @@ -283,7 +283,7 @@ sub switchAdminOff { my $self = shift; $self->{_var}{adminOn} = 0; my $session = $self->session; - eval{$session->cache->set($self->getId, $self->{_var}, $session->setting->get('sessionTimeout'))}; + $session->cache->set($self->getId, $self->{_var}, $session->setting->get('sessionTimeout')); delete $self->{_var}{nextCacheFlush}; $session->db->setRow("userSession","sessionId", $self->{_var}); } @@ -300,7 +300,7 @@ sub switchAdminOn { my $self = shift; $self->{_var}{adminOn} = 1; my $session = $self->session; - eval{$session->cache->set($self->getId, $self->{_var}, $session->setting->get('sessionTimeout'))}; + $session->cache->set($self->getId, $self->{_var}, $session->setting->get('sessionTimeout')); delete $self->{_var}{nextCacheFlush}; $self->session->db->setRow("userSession","sessionId", $self->{_var}); } diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index 237e5188b..73c7b318c 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -282,7 +282,7 @@ sub cache { for my $k (qw(_userId _user _profile)) { $userData{$k} = $self->{$k}; } - eval{$self->session->cache->set($self->userId, \%userData, 60*60*24)}; + $self->session->cache->set($self->userId, \%userData, 60*60*24); } #------------------------------------------------------------------- @@ -1058,7 +1058,7 @@ sub new { my $userId = shift || 1; my $overrideId = shift; $userId = _create($session, $overrideId) if ($userId eq "new"); - my $self = eval{$session->cache->get($userId)} || {}; + my $self = $session->cache->get($userId) || {}; bless $self, $class; $self->{_session} = $session; unless ($self->{_userId} && $self->{_user}{username}) { @@ -1332,7 +1332,7 @@ Deletes this user object out of the cache. sub uncache { my $self = shift; - eval{$self->session->cache->delete($self->userId)}; + $self->session->cache->delete($self->userId); } #---------------------------------------------------------------------------- From b767824711f60ae98a24d0d3e6b919ca1a132767 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 19 Apr 2010 18:51:10 -0500 Subject: [PATCH 17/36] cache: s/delete/remove/ --- lib/WebGUI/Asset/File.pm | 2 +- lib/WebGUI/Asset/Post.pm | 2 +- lib/WebGUI/Asset/Shortcut.pm | 2 +- lib/WebGUI/Asset/Sku/Product.pm | 2 +- lib/WebGUI/Asset/Snippet.pm | 8 ++++---- lib/WebGUI/Asset/Wobject/Article.pm | 2 +- lib/WebGUI/Asset/Wobject/Collaboration.pm | 4 ++-- lib/WebGUI/Asset/Wobject/Folder.pm | 2 +- lib/WebGUI/Asset/Wobject/HttpProxy.pm | 4 ++-- lib/WebGUI/Asset/Wobject/MessageBoard.pm | 2 +- lib/WebGUI/Asset/Wobject/MultiSearch.pm | 2 +- lib/WebGUI/Asset/Wobject/SQLReport.pm | 2 +- lib/WebGUI/Asset/Wobject/SyndicatedContent.pm | 2 +- lib/WebGUI/Group.pm | 4 ++-- lib/WebGUI/Session/Scratch.pm | 2 +- lib/WebGUI/Session/Var.pm | 2 +- lib/WebGUI/User.pm | 2 +- 17 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index c4374b2bc..5c181e97e 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -449,7 +449,7 @@ Extends the master method to clear the view cache. override purgeCache => sub { my $self = shift; - $self->session->cache->delete("view_".$self->getId); + $self->session->cache->remove("view_".$self->getId); super(); }; diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index 9cb885c08..80b7e6ff2 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -1175,7 +1175,7 @@ Extend the base class to handle caching. override purgeCache => sub { my $self = shift; - $self->session->cache->delete("view_".$self->getThread->getId) if ($self->getThread); + $self->session->cache->remove("view_".$self->getThread->getId) if ($self->getThread); super(); }; diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index 812f6d370..9fc0ea56a 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -879,7 +879,7 @@ Delete any cached overrides. sub uncacheOverrides { my $self = shift; - $self->session->cache->delete($self->_overridesCacheTag); + $self->session->cache->remove($self->_overridesCacheTag); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index e5fec5b86..2e3344c1d 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -769,7 +769,7 @@ Extends the base class to handle cleaning up the cache for this asset. override purgeCache => sub { my $self = shift; - $self->session->cache->delete("view_".$self->getId); + $self->session->cache->remove("view_".$self->getId); super(); }; diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm index 8d4ca57b6..1948a6424 100644 --- a/lib/WebGUI/Asset/Snippet.pm +++ b/lib/WebGUI/Asset/Snippet.pm @@ -205,10 +205,10 @@ override purgeCache => sub { my $self = shift; my $cache = $self->session->cache; eval { - $cache->delete("view__".$self->getId); - $cache->delete("view_1_".$self->getId); - $cache->delete("view__".$self->getId . '_ssl'); - $cache->delete("view_1_".$self->getId . '_ssl'); + $cache->remove("view__".$self->getId); + $cache->remove("view_1_".$self->getId); + $cache->remove("view__".$self->getId . '_ssl'); + $cache->remove("view_1_".$self->getId . '_ssl'); }; super(); }; diff --git a/lib/WebGUI/Asset/Wobject/Article.pm b/lib/WebGUI/Asset/Wobject/Article.pm index 355dfe652..d744b7635 100644 --- a/lib/WebGUI/Asset/Wobject/Article.pm +++ b/lib/WebGUI/Asset/Wobject/Article.pm @@ -290,7 +290,7 @@ See WebGUI::Asset::purgeCache() for details. override purgeCache => sub { my $self = shift; - $self->session->cache->delete("view_".$self->getId); + $self->session->cache->remove("view_".$self->getId); super(); }; diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index f6d48e4e5..656d265b1 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -1436,8 +1436,8 @@ override purgeCache => sub { my $self = shift; my $cache = $self->session->cache; eval { - $cache->delete("view_".$self->getId); - $cache->delete($self->_visitorCacheKey); + $cache->remove("view_".$self->getId); + $cache->remove($self->_visitorCacheKey); }; super(); }; diff --git a/lib/WebGUI/Asset/Wobject/Folder.pm b/lib/WebGUI/Asset/Wobject/Folder.pm index e176e9732..baa2102e3 100644 --- a/lib/WebGUI/Asset/Wobject/Folder.pm +++ b/lib/WebGUI/Asset/Wobject/Folder.pm @@ -190,7 +190,7 @@ See WebGUI::Asset::purgeCache() for details. override purgeCache => sub { my $self = shift; - $self->session->cache->delete("view_".$self->getId); + $self->session->cache->remove("view_".$self->getId); super(); }; diff --git a/lib/WebGUI/Asset/Wobject/HttpProxy.pm b/lib/WebGUI/Asset/Wobject/HttpProxy.pm index 7affd50e9..032d84541 100644 --- a/lib/WebGUI/Asset/Wobject/HttpProxy.pm +++ b/lib/WebGUI/Asset/Wobject/HttpProxy.pm @@ -270,8 +270,8 @@ override purgeCache => sub { my $self = shift; my $cache = $self->session->cache; eval { - $cache->delete($self->proxiedUrl."_URL"); - $cache->delete($self->proxiedUrl."_HEADER"); + $cache->remove($self->proxiedUrl."_URL"); + $cache->remove($self->proxiedUrl."_HEADER"); }; super(); }; diff --git a/lib/WebGUI/Asset/Wobject/MessageBoard.pm b/lib/WebGUI/Asset/Wobject/MessageBoard.pm index a7f188da8..a241a7191 100644 --- a/lib/WebGUI/Asset/Wobject/MessageBoard.pm +++ b/lib/WebGUI/Asset/Wobject/MessageBoard.pm @@ -72,7 +72,7 @@ See WebGUI::Asset::purgeCache() for details. override purgeCache => sub { my $self = shift; - $self->session->cache->delete("view_".$self->getId); + $self->session->cache->remove("view_".$self->getId); super(); }; diff --git a/lib/WebGUI/Asset/Wobject/MultiSearch.pm b/lib/WebGUI/Asset/Wobject/MultiSearch.pm index ff88000e1..1c342d421 100644 --- a/lib/WebGUI/Asset/Wobject/MultiSearch.pm +++ b/lib/WebGUI/Asset/Wobject/MultiSearch.pm @@ -82,7 +82,7 @@ See WebGUI::Asset::purgeCache() for details. override purgeCache => sub { my $self = shift; - eval{$self->session->cache->delete("view_".$self->getId)}; + eval{$self->session->cache->remove("view_".$self->getId)}; super(); }; diff --git a/lib/WebGUI/Asset/Wobject/SQLReport.pm b/lib/WebGUI/Asset/Wobject/SQLReport.pm index 114cd3546..63d42eb5a 100644 --- a/lib/WebGUI/Asset/Wobject/SQLReport.pm +++ b/lib/WebGUI/Asset/Wobject/SQLReport.pm @@ -559,7 +559,7 @@ See WebGUI::Asset::purgeCache() for details. override purgeCache => sub { my $self = shift; - eval{$self->session->cache->delete("view_".$self->getId)}; + $self->session->cache->remove("view_".$self->getId); super(); }; diff --git a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm index f552dceb4..161de15a0 100644 --- a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm +++ b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm @@ -319,7 +319,7 @@ See WebGUI::Asset::purgeCache() for details. override purgeCache => sub { my $self = shift; - $self->session->cache->delete("view_".$self->getId); + $self->session->cache->remove("view_".$self->getId); super(); }; diff --git a/lib/WebGUI/Group.pm b/lib/WebGUI/Group.pm index d387d3673..14a7f39e3 100644 --- a/lib/WebGUI/Group.pm +++ b/lib/WebGUI/Group.pm @@ -126,7 +126,7 @@ not be added to any group. Groups may not be added to themselves. sub addGroups { my $self = shift; my $groups = shift; - $self->session->cache->delete($self->getId); + $self->session->cache->remove($self->getId); GROUP: foreach my $gid (@{$groups}) { next if ($gid eq '1'); next if ($gid eq $self->getId); @@ -233,7 +233,7 @@ sub clearCaches { my $groups = $self->getAllGroupsFor(); my $cache = $self->session->cache; foreach my $group ( $self->getId, @{ $groups } ) { - $cache->delete($group); + $cache->remove($group); } my $stow = $self->session->stow; $stow->delete("groupObj"); diff --git a/lib/WebGUI/Session/Scratch.pm b/lib/WebGUI/Session/Scratch.pm index 6b9405394..28e29555b 100644 --- a/lib/WebGUI/Session/Scratch.pm +++ b/lib/WebGUI/Session/Scratch.pm @@ -84,7 +84,7 @@ sub deleteAll { delete $self->{_data}; my $session = $self->session; my $id = $session->getId; - $session->cache->delete("sessionscratch_".$id); + $session->cache->remove("sessionscratch_".$id); $session->db->write("delete from userSessionScratch where sessionId=?", [$id]); } diff --git a/lib/WebGUI/Session/Var.pm b/lib/WebGUI/Session/Var.pm index 73a058172..ffcf60f68 100644 --- a/lib/WebGUI/Session/Var.pm +++ b/lib/WebGUI/Session/Var.pm @@ -71,7 +71,7 @@ sub end { my $self = shift; my $session = $self->session; my $id = $self->getId; - $session->cache->delete($id); + $session->cache->remove($id); $session->scratch->deleteAll; $session->db->write("delete from userSession where sessionId=?",[$id]); delete $session->{_user}; diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index 73c7b318c..ecf85a14e 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -1332,7 +1332,7 @@ Deletes this user object out of the cache. sub uncache { my $self = shift; - $self->session->cache->delete($self->userId); + $self->session->cache->remove($self->userId); } #---------------------------------------------------------------------------- From 829bb7739ee1e3d2598e8b643f2bf55ecdd9e3b0 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 19 Apr 2010 18:55:45 -0500 Subject: [PATCH 18/36] add back string literal identifier --- lib/WebGUI/Group.pm | 8 ++++---- lib/WebGUI/User.pm | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/WebGUI/Group.pm b/lib/WebGUI/Group.pm index 14a7f39e3..b1a35e7d7 100644 --- a/lib/WebGUI/Group.pm +++ b/lib/WebGUI/Group.pm @@ -126,7 +126,7 @@ not be added to any group. Groups may not be added to themselves. sub addGroups { my $self = shift; my $groups = shift; - $self->session->cache->remove($self->getId); + $self->session->cache->remove("group_" . $self->getId); GROUP: foreach my $gid (@{$groups}) { next if ($gid eq '1'); next if ($gid eq $self->getId); @@ -233,7 +233,7 @@ sub clearCaches { my $groups = $self->getAllGroupsFor(); my $cache = $self->session->cache; foreach my $group ( $self->getId, @{ $groups } ) { - $cache->remove($group); + $cache->remove("group_".$group); } my $stow = $self->session->stow; $stow->delete("groupObj"); @@ -562,7 +562,7 @@ sub getAllUsers { my $loopCount = shift; my $expireTime = 0; my $cache = $self->session->cache; - my $value = $cache->get($self->getId); + my $value = $cache->get("group_".$self->getId); return $value if defined $value; my @users = (); push @users, @@ -587,7 +587,7 @@ sub getAllUsers { } my %users = map { $_ => 1 } @users; @users = keys %users; - $cache->set($self->getId, \@users, $self->groupCacheTimeout); + $cache->set("group_".$self->getId, \@users, $self->groupCacheTimeout); return \@users; } diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index ecf85a14e..a7ece5df6 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -282,7 +282,7 @@ sub cache { for my $k (qw(_userId _user _profile)) { $userData{$k} = $self->{$k}; } - $self->session->cache->set($self->userId, \%userData, 60*60*24); + $self->session->cache->set("user_" . $self->userId, \%userData, 60*60*24); } #------------------------------------------------------------------- @@ -1058,7 +1058,7 @@ sub new { my $userId = shift || 1; my $overrideId = shift; $userId = _create($session, $overrideId) if ($userId eq "new"); - my $self = $session->cache->get($userId) || {}; + my $self = $session->cache->get("user_" . $userId) || {}; bless $self, $class; $self->{_session} = $session; unless ($self->{_userId} && $self->{_user}{username}) { @@ -1332,7 +1332,7 @@ Deletes this user object out of the cache. sub uncache { my $self = shift; - $self->session->cache->remove($self->userId); + $self->session->cache->remove("user_" . $self->userId); } #---------------------------------------------------------------------------- From c4204eff89aa417baf84d9cbc3c04c77c7f1671b Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Sun, 18 Apr 2010 18:47:16 -0500 Subject: [PATCH 19/36] clean up more uses of ->get --- lib/WebGUI/Asset.pm | 21 +++++----- lib/WebGUI/Asset/Wobject/Navigation.pm | 56 +++++++++++++------------- lib/WebGUI/AssetLineage.pm | 4 +- lib/WebGUI/Session/Url.pm | 2 +- 4 files changed, 42 insertions(+), 41 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 937150049..90888c497 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -570,10 +570,10 @@ sub canView { $user = $self->session->user; $userId = $user->userId(); } - if ($userId eq $self->get("ownerUserId")) { + if ($userId eq $self->ownerUserId) { return 1; } - elsif ($user->isInGroup($self->get("groupIdView"))) { + elsif ($user->isInGroup($self->groupIdView)) { return 1; } return $self->canEdit($userId); @@ -1187,9 +1187,9 @@ Returns the extraHeadTags stored in the asset. Called in $self->session->style- sub getExtraHeadTags { my $self = shift; - return $self->get('usePackedHeadTags') - ? $self->get('extraHeadTagsPacked') - : $self->get("extraHeadTags") + return $self->usePackedHeadTags + ? $self->extraHeadTagsPacked + : $self->extraHeadTags ; } @@ -1374,11 +1374,12 @@ Returns the menu title of this asset. If it's not specified or it's "Untitled" t =cut sub getMenuTitle { - my $self = shift; - if ($self->get("menuTitle") eq "" || lc($self->get("menuTitle")) eq "untitled") { - return $self->getName; - } - return $self->get("menuTitle"); + my $self = shift; + my $menuTitle = $self->menuTitle; + if ( $menuTitle eq '' || lc $menuTitle eq 'untitled' ) { + return $self->getName; + } + return $menuTitle; } diff --git a/lib/WebGUI/Asset/Wobject/Navigation.pm b/lib/WebGUI/Asset/Wobject/Navigation.pm index 51ad00626..67308aa29 100644 --- a/lib/WebGUI/Asset/Wobject/Navigation.pm +++ b/lib/WebGUI/Asset/Wobject/Navigation.pm @@ -304,7 +304,7 @@ override getToolbar => sub { if ($self->session->asset) { $returnUrl = ";proceed=goBackToPage;returnUrl=".$self->session->url->escape($self->session->asset->getUrl); } - $toolbar = $self->session->icon->edit('func=edit'.$returnUrl,$self->get("url")) + $toolbar = $self->session->icon->edit('func=edit'.$returnUrl,$self->url) if ($userUiLevel >= $uiLevels->{"edit"}); } $self->session->style->setLink($self->session->url->extras('assetToolbar/assetToolbar.css'), {rel=>"stylesheet",type=>"text/css"}); @@ -343,11 +343,11 @@ Extend the superclass to add metadata and to preprocess the template. sub prepareView { my $self = shift; $self->SUPER::prepareView(); - my $template = WebGUI::Asset::Template->newById($self->session, $self->get("templateId")); + my $template = WebGUI::Asset::Template->newById($self->session, $self->templateId); if (!$template) { WebGUI::Error::ObjectNotFound::Template->throw( error => qq{Template not found}, - templateId => $self->get("templateId"), + templateId => $self->templateId, assetId => $self->getId, ); } @@ -376,29 +376,29 @@ sub view { $current = WebGUI::Asset->getDefault($self->session); } - if ($self->get("startType") eq "specificUrl") { - $start = WebGUI::Asset->newByUrl($self->session,$self->get("startPoint")); - } elsif ($self->get("startType") eq "relativeToRoot") { - unless (($self->get("startPoint")+1) >= $current->getLineageLength) { - $start = WebGUI::Asset->newByLineage($self->session,substr($current->get("lineage"),0, ($self->get("startPoint") + 1) * 6)); + if ($self->startType eq "specificUrl") { + $start = WebGUI::Asset->newByUrl($self->session,$self->startPoint); + } elsif ($self->startType eq "relativeToRoot") { + unless (($self->startPoint+1) >= $current->getLineageLength) { + $start = WebGUI::Asset->newByLineage($self->session,substr($current->lineage,0, ($self->startPoint + 1) * 6)); } - } elsif ($self->get("startType") eq "relativeToCurrentUrl") { - $start = WebGUI::Asset->newByLineage($self->session,substr($current->get("lineage"),0, ($current->getLineageLength + $self->get("startPoint")) * 6)); + } elsif ($self->startType eq "relativeToCurrentUrl") { + $start = WebGUI::Asset->newByLineage($self->session,substr($current->lineage,0, ($current->getLineageLength + $self->startPoint) * 6)); } $start = $current unless (defined $start); # if none of the above results in a start point, then the current page must be it - my @includedRelationships = split("\n",$self->get("assetsToInclude")); + my @includedRelationships = split("\n",$self->assetsToInclude); my %rules; $rules{returnObjects} = 1; - $rules{endingLineageLength} = $start->getLineageLength+$self->get("descendantEndPoint"); + $rules{endingLineageLength} = $start->getLineageLength+$self->descendantEndPoint; $rules{assetToPedigree} = $current if (isIn("pedigree",@includedRelationships)); - $rules{ancestorLimit} = $self->get("ancestorEndPoint"); - $rules{orderByClause} = 'rpad(asset.lineage, 255, 9) desc' if ($self->get('reversePageLoop')); + $rules{ancestorLimit} = $self->ancestorEndPoint; + $rules{orderByClause} = 'rpad(asset.lineage, 255, 9) desc' if ($self->reversePageLoop); my @interestingProperties = ('assetId', 'parentId', 'ownerUserId', 'synopsis', 'newWindow'); my $assets = $start->getLineage(\@includedRelationships,\%rules); my $var = {'page_loop' => []}; foreach my $property (@interestingProperties) { - $var->{'currentPage.'.$property} = $current->get($property); + $var->{'currentPage.'.$property} = $current->$property; } $var->{'currentPage.menuTitle'} = $current->getMenuTitle; $var->{'currentPage.title'} = $current->getTitle; @@ -407,7 +407,7 @@ sub view { $var->{'currentPage.hasChild'} = $current->hasChildren; $var->{'currentPage.rank'} = $current->getRank; $var->{'currentPage.rankIs'.$current->getRank} = 1; - my $currentLineage = $current->get("lineage"); + my $currentLineage = $current->lineage; my $lineageToSkip = "noskip"; my $absoluteDepthOfLastPage; my $absoluteDepthOfFirstPage; # Will set on first iteration of loop, below @@ -417,18 +417,18 @@ sub view { foreach my $asset (@{$assets}) { # skip pages we shouldn't see - my $pageLineage = $asset->get("lineage"); + my $pageLineage = $asset->lineage; next if ($pageLineage =~ m/^$lineageToSkip/); - if ($asset->get("isHidden") && !$self->get("showHiddenPages")) { + if ($asset->isHidden && !$self->showHiddenPages) { $lineageToSkip = $pageLineage unless ($pageLineage eq "000001"); next; } - if ($asset->get("isSystem") && !$self->get("showSystemPages")) { + if ($asset->isSystem && !$self->showSystemPages) { $lineageToSkip = $pageLineage unless ($pageLineage eq "000001"); next; } - unless ($self->get("showUnprivilegedPages") || $asset->canView) { + unless ($self->showUnprivilegedPages || $asset->canView) { $lineageToSkip = $pageLineage unless ($pageLineage eq "000001"); next; } @@ -450,11 +450,11 @@ sub view { $pageData->{"page.rank"} = $asset->getRank; $pageData->{"page.absDepth"} = $asset->getLineageLength; $pageData->{"page.relDepth"} = $asset->getLineageLength - $absoluteDepthOfFirstPage; - $pageData->{"page.isSystem"} = $asset->get("isSystem"); - $pageData->{"page.isHidden"} = $asset->get("isHidden"); + $pageData->{"page.isSystem"} = $asset->isSystem; + $pageData->{"page.isHidden"} = $asset->isHidden; $pageData->{"page.isViewable"} = $asset->canView; - $pageData->{'page.isContainer'} = $self->session->config->get("assets/".$asset->get("className")."/isContainer"); - $pageData->{'page.isUtility'} = $self->session->config->get("assets/".$asset->get("className")."/category") eq "utilities"; + $pageData->{'page.isContainer'} = $self->session->config->get("assets/".$asset->className."/isContainer"); + $pageData->{'page.isUtility'} = $self->session->config->get("assets/".$asset->className."/category") eq "utilities"; $pageData->{"page.url"} = $asset->getUrl; my $indent = $asset->getLineageLength - $absoluteDepthOfFirstPage; $pageData->{"page.indent_loop"} = []; @@ -462,15 +462,15 @@ sub view { $pageData->{"page.indent"} = "   " x $indent; $pageData->{"page.isBranchRoot"} = ($pageData->{"page.absDepth"} == 1); $pageData->{"page.isTopOfBranch"} = ($pageData->{"page.absDepth"} == 2); - $pageData->{"page.isChild"} = ($asset->get("parentId") eq $current->getId); - $pageData->{"page.isParent"} = ($asset->getId eq $current->get("parentId")); + $pageData->{"page.isChild"} = ($asset->parentId eq $current->getId); + $pageData->{"page.isParent"} = ($asset->getId eq $current->parentId); $pageData->{"page.isCurrent"} = ($asset->getId eq $current->getId); $pageData->{"page.isDescendant"} = ( $pageLineage =~ m/^$currentLineage/ && !$pageData->{"page.isCurrent"}); $pageData->{"page.isAncestor"} = ( $currentLineage =~ m/^$pageLineage/ && !$pageData->{"page.isCurrent"}); my $currentBranchLineage = substr($currentLineage,0,12); $pageData->{"page.inBranchRoot"} = ($pageLineage =~ m/^$currentBranchLineage/); $pageData->{"page.isSibling"} = ( - $asset->get("parentId") eq $current->get("parentId") && + $asset->parentId eq $current->parentId && $asset->getId ne $current->getId ); $pageData->{"page.inBranch"} = ( @@ -499,7 +499,7 @@ sub view { my $parent = $asset->getParent; if (defined $parent) { foreach my $property (@interestingProperties) { - $pageData->{"page.parent.".$property} = $parent->get($property); + $pageData->{"page.parent.".$property} = $parent->$property; } $pageData->{'page.parent.menuTitle'} = $parent->getMenuTitle; $pageData->{'page.parent.title'} = $parent->getTitle; diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index 3ba41e5dc..59ef0bec5 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -483,7 +483,7 @@ Returns the number of Asset members in an Asset's lineage. sub getLineageLength { my $self = shift; - return length($self->get("lineage"))/6; + return length($self->lineage)/6; } #------------------------------------------------------------------- @@ -773,7 +773,7 @@ Optional specified lineage. sub getRank { my $self = shift; - my $lineage = shift || $self->get("lineage"); + my $lineage = shift || $self->lineage; $lineage =~ m/(.{6})$/; my $rank = $1 - 0; # gets rid of preceeding 0s. return $rank; diff --git a/lib/WebGUI/Session/Url.pm b/lib/WebGUI/Session/Url.pm index 750b68d4a..34d7ecb10 100644 --- a/lib/WebGUI/Session/Url.pm +++ b/lib/WebGUI/Session/Url.pm @@ -456,7 +456,7 @@ sub page { if ($useFullUrl) { $url = $self->getSiteURL(); } - my $path = $self->session->asset ? $self->session->asset->get("url") : URI::Escape::uri_escape_utf8($self->getRequestedUrl, "^A-Za-z0-9\-_.!~*'()/"); + my $path = $self->session->asset ? $self->session->asset->url : URI::Escape::uri_escape_utf8($self->getRequestedUrl, "^A-Za-z0-9\-_.!~*'()/"); $url .= $self->gateway($path, $pairs, $skipPreventProxyCache); return $url; } From a1d8dbd67a974d701cfb56ff3b5c7a71340d2502 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Sun, 18 Apr 2010 18:48:59 -0500 Subject: [PATCH 20/36] more object destruction cleanups --- lib/WebGUI/Asset.pm | 21 --------------------- lib/WebGUI/Asset/Post.pm | 9 ++++----- lib/WebGUI/Asset/Post/Thread.pm | 13 ++++++------- lib/WebGUI/Asset/Wobject/GalleryAlbum.pm | 2 +- 4 files changed, 11 insertions(+), 34 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 90888c497..80a9b9a1c 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -669,27 +669,6 @@ sub drawExtraHeadTags { }); } - -#------------------------------------------------------------------- - -=head2 DESTROY ( ) - -Completely remove an asset from existence. - -=cut - -sub DESTROY { - my $self = shift; - - # Let the parent be garbage collected if no one else is referencing - # him. firstChild and lastChild are weak references, so no need to - # worry about them here. - delete $self->{_parent}; - - $self = undef; -} - - #------------------------------------------------------------------- =head2 extraHeadTags ( value ) diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index 80b7e6ff2..05c5e734a 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -321,11 +321,10 @@ Extend the base method to delete the locally cached thread object. =cut -override DESTROY => sub { - my $self = shift; - $self->{_thread}->DESTROY if (exists $self->{_thread} && ref $self->{_thread} =~ /Thread/); - super(); -}; +sub DEMOLISH { + my $self = shift; + $self->{_thread}->DESTROY if (exists $self->{_thread} && ref $self->{_thread} =~ /Thread/); +} #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index 01d1bc773..cb555d1e8 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -238,13 +238,12 @@ and next threads, and to delete the parent CS. =cut -override DESTROY => sub { - my $self = shift; - return undef unless defined $self; - $self->{_next}->DESTROY if (defined $self->{_next}); - $self->{_previous}->DESTROY if (defined $self->{_previous}); - super(); -}; +sub DEMOLISH { + my $self = shift; + return undef unless defined $self; + $self->{_next}->DESTROY if (defined $self->{_next}); + $self->{_previous}->DESTROY if (defined $self->{_previous}); +} #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm index 75a18c667..c0ed7a479 100644 --- a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm +++ b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm @@ -312,7 +312,7 @@ Destroy the cached assets =cut -sub DESTROY { +sub DEMOLISH { my $self = shift; for my $key ( qw/ _nextAlbum _prevAlbum / ) { my $asset = delete $self->{ $key }; From 0efa62a73c778e9834af8963c2af6a9250f2224d Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Sun, 18 Apr 2010 18:50:56 -0500 Subject: [PATCH 21/36] asset immutability --- lib/WebGUI/Asset.pm | 1 + lib/WebGUI/Asset/Event.pm | 1 + lib/WebGUI/Asset/File.pm | 2 +- lib/WebGUI/Asset/File/GalleryFile.pm | 1 + lib/WebGUI/Asset/File/GalleryFile/Photo.pm | 1 + lib/WebGUI/Asset/File/Image.pm | 1 + lib/WebGUI/Asset/File/ZipArchive.pm | 1 + lib/WebGUI/Asset/FilePile.pm | 1 + lib/WebGUI/Asset/MapPoint.pm | 1 + lib/WebGUI/Asset/MatrixListing.pm | 2 ++ lib/WebGUI/Asset/Post.pm | 2 +- lib/WebGUI/Asset/Post/Thread.pm | 1 + lib/WebGUI/Asset/Redirect.pm | 1 + lib/WebGUI/Asset/RichEdit.pm | 2 +- lib/WebGUI/Asset/Shortcut.pm | 1 + lib/WebGUI/Asset/Sku.pm | 1 + lib/WebGUI/Asset/Sku/Ad.pm | 1 + lib/WebGUI/Asset/Sku/Donation.pm | 1 + lib/WebGUI/Asset/Sku/EMSBadge.pm | 1 + lib/WebGUI/Asset/Sku/EMSRibbon.pm | 1 + lib/WebGUI/Asset/Sku/EMSTicket.pm | 1 + lib/WebGUI/Asset/Sku/EMSToken.pm | 1 + lib/WebGUI/Asset/Sku/FlatDiscount.pm | 1 + lib/WebGUI/Asset/Sku/Product.pm | 1 + lib/WebGUI/Asset/Sku/Subscription.pm | 1 + lib/WebGUI/Asset/Sku/ThingyRecord.pm | 1 + lib/WebGUI/Asset/Snippet.pm | 2 +- lib/WebGUI/Asset/Story.pm | 1 + lib/WebGUI/Asset/Template.pm | 1 + lib/WebGUI/Asset/WikiPage.pm | 2 +- lib/WebGUI/Asset/Wobject.pm | 1 + lib/WebGUI/Asset/Wobject/Article.pm | 1 + lib/WebGUI/Asset/Wobject/Calendar.pm | 1 + lib/WebGUI/Asset/Wobject/Carousel.pm | 1 + lib/WebGUI/Asset/Wobject/Collaboration.pm | 1 + lib/WebGUI/Asset/Wobject/Collaboration/Newsletter.pm | 1 + lib/WebGUI/Asset/Wobject/Dashboard.pm | 1 + lib/WebGUI/Asset/Wobject/DataForm.pm | 1 + lib/WebGUI/Asset/Wobject/DataTable.pm | 1 + lib/WebGUI/Asset/Wobject/EventManagementSystem.pm | 1 + lib/WebGUI/Asset/Wobject/Folder.pm | 1 + lib/WebGUI/Asset/Wobject/Gallery.pm | 1 + lib/WebGUI/Asset/Wobject/GalleryAlbum.pm | 1 + lib/WebGUI/Asset/Wobject/HttpProxy.pm | 1 + lib/WebGUI/Asset/Wobject/InOutBoard.pm | 1 + lib/WebGUI/Asset/Wobject/Layout.pm | 1 + lib/WebGUI/Asset/Wobject/Map.pm | 1 + lib/WebGUI/Asset/Wobject/Matrix.pm | 1 + lib/WebGUI/Asset/Wobject/MessageBoard.pm | 1 + lib/WebGUI/Asset/Wobject/MultiSearch.pm | 1 + lib/WebGUI/Asset/Wobject/Navigation.pm | 1 + lib/WebGUI/Asset/Wobject/Poll.pm | 1 + lib/WebGUI/Asset/Wobject/ProjectManager.pm | 2 +- lib/WebGUI/Asset/Wobject/SQLReport.pm | 1 + lib/WebGUI/Asset/Wobject/Search.pm | 1 + lib/WebGUI/Asset/Wobject/Shelf.pm | 1 + lib/WebGUI/Asset/Wobject/StockData.pm | 1 + lib/WebGUI/Asset/Wobject/StoryArchive.pm | 1 + lib/WebGUI/Asset/Wobject/StoryTopic.pm | 1 + lib/WebGUI/Asset/Wobject/Survey.pm | 1 + lib/WebGUI/Asset/Wobject/SyndicatedContent.pm | 1 + lib/WebGUI/Asset/Wobject/Thingy.pm | 1 + lib/WebGUI/Asset/Wobject/TimeTracking.pm | 1 + lib/WebGUI/Asset/Wobject/UserList.pm | 1 + lib/WebGUI/Asset/Wobject/WeatherData.pm | 1 + lib/WebGUI/Asset/Wobject/WikiMaster.pm | 1 + lib/WebGUI/Definition/Meta/Asset.pm | 10 +++++++++- lib/WebGUI/Definition/Meta/Class.pm | 8 ++++++++ 68 files changed, 84 insertions(+), 7 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 80a9b9a1c..114976400 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -2844,4 +2844,5 @@ sub www_widgetView { return $self->outputWidgetMarkup($width, $height, $templateId, $styleTemplateId); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index 6f46b5665..9022b8cad 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -2360,5 +2360,6 @@ equal and then choose by assetId. =cut +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index 5c181e97e..fc054cf3b 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -649,5 +649,5 @@ sub www_view { return 'chunked'; } - +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/File/GalleryFile.pm b/lib/WebGUI/Asset/File/GalleryFile.pm index 3325cdb6a..a22eb2292 100644 --- a/lib/WebGUI/Asset/File/GalleryFile.pm +++ b/lib/WebGUI/Asset/File/GalleryFile.pm @@ -1171,4 +1171,5 @@ sub setPrivileges { } +__PACKAGE__->meta->make_immutable; 1; # Who knew the truth would be so obvious? diff --git a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm index fd30cb0f1..c288a6f3b 100644 --- a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm +++ b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm @@ -585,4 +585,5 @@ sub www_showConfirmation { ); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/File/Image.pm b/lib/WebGUI/Asset/File/Image.pm index 05900df9a..e80ab2fc0 100644 --- a/lib/WebGUI/Asset/File/Image.pm +++ b/lib/WebGUI/Asset/File/Image.pm @@ -824,4 +824,5 @@ sub www_crop { return $self->getAdminConsole->render($f->print.$image,$i18n->get("crop image")); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/File/ZipArchive.pm b/lib/WebGUI/Asset/File/ZipArchive.pm index 431cf1080..237018691 100644 --- a/lib/WebGUI/Asset/File/ZipArchive.pm +++ b/lib/WebGUI/Asset/File/ZipArchive.pm @@ -252,5 +252,6 @@ sub www_view { } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/FilePile.pm b/lib/WebGUI/Asset/FilePile.pm index 22cef39fe..17b9ac227 100644 --- a/lib/WebGUI/Asset/FilePile.pm +++ b/lib/WebGUI/Asset/FilePile.pm @@ -270,5 +270,6 @@ sub www_edit { } } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/MapPoint.pm b/lib/WebGUI/Asset/MapPoint.pm index 616c24e08..85bfff70d 100644 --- a/lib/WebGUI/Asset/MapPoint.pm +++ b/lib/WebGUI/Asset/MapPoint.pm @@ -390,6 +390,7 @@ sub www_view { return "redirect"; } +__PACKAGE__->meta->make_immutable; 1; #vim:ft=perl diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm index 921039b10..2cb7893a8 100644 --- a/lib/WebGUI/Asset/MatrixListing.pm +++ b/lib/WebGUI/Asset/MatrixListing.pm @@ -1090,6 +1090,8 @@ sub www_viewScreenshots { return $self->processTemplate($var,$self->getParent->get("screenshotsTemplateId")); } + +__PACKAGE__->meta->make_immutable; 1; #vim:ft=perl diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index 05c5e734a..10183ed42 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -1818,6 +1818,6 @@ sub www_view { return $self->getThread->www_view($self); } - +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index cb555d1e8..1a6f11821 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -1394,5 +1394,6 @@ sub www_view { +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Redirect.pm b/lib/WebGUI/Asset/Redirect.pm index 77369912d..a5ad06223 100644 --- a/lib/WebGUI/Asset/Redirect.pm +++ b/lib/WebGUI/Asset/Redirect.pm @@ -136,5 +136,6 @@ sub www_view { return $i18n->get('self_referential'); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/RichEdit.pm b/lib/WebGUI/Asset/RichEdit.pm index b583f8395..490e192e7 100644 --- a/lib/WebGUI/Asset/RichEdit.pm +++ b/lib/WebGUI/Asset/RichEdit.pm @@ -676,6 +676,6 @@ sub www_edit { } - +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index 9fc0ea56a..f49af90c7 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -1288,5 +1288,6 @@ sub getShortcutsForAssetId { return WebGUI::Asset->getRoot($session)->getLineage(['descendants'], $properties); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Sku.pm b/lib/WebGUI/Asset/Sku.pm index d6a2498a6..d9f16f7d5 100644 --- a/lib/WebGUI/Asset/Sku.pm +++ b/lib/WebGUI/Asset/Sku.pm @@ -672,4 +672,5 @@ sub www_view { return "chunked"; } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Sku/Ad.pm b/lib/WebGUI/Asset/Sku/Ad.pm index 02e925d49..b3a7dcd26 100644 --- a/lib/WebGUI/Asset/Sku/Ad.pm +++ b/lib/WebGUI/Asset/Sku/Ad.pm @@ -622,5 +622,6 @@ sub www_renew { return $self->www_view; } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Sku/Donation.pm b/lib/WebGUI/Asset/Sku/Donation.pm index a3e2db681..485e340a6 100644 --- a/lib/WebGUI/Asset/Sku/Donation.pm +++ b/lib/WebGUI/Asset/Sku/Donation.pm @@ -187,4 +187,5 @@ sub www_donate { return $self->www_view; } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Sku/EMSBadge.pm b/lib/WebGUI/Asset/Sku/EMSBadge.pm index 9777ce689..12422c2b9 100644 --- a/lib/WebGUI/Asset/Sku/EMSBadge.pm +++ b/lib/WebGUI/Asset/Sku/EMSBadge.pm @@ -519,4 +519,5 @@ sub www_edit { return $self->processStyle('

'.$i18n->get('ems badge').'

'.$self->getEditForm->print); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Sku/EMSRibbon.pm b/lib/WebGUI/Asset/Sku/EMSRibbon.pm index 6aebc89d6..b510b2de9 100644 --- a/lib/WebGUI/Asset/Sku/EMSRibbon.pm +++ b/lib/WebGUI/Asset/Sku/EMSRibbon.pm @@ -287,4 +287,5 @@ sub www_viewAll { } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Sku/EMSTicket.pm b/lib/WebGUI/Asset/Sku/EMSTicket.pm index 5b7dd8411..23688db94 100644 --- a/lib/WebGUI/Asset/Sku/EMSTicket.pm +++ b/lib/WebGUI/Asset/Sku/EMSTicket.pm @@ -591,4 +591,5 @@ sub www_viewAll { +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Sku/EMSToken.pm b/lib/WebGUI/Asset/Sku/EMSToken.pm index 1cb38e7d7..5ecb9c084 100644 --- a/lib/WebGUI/Asset/Sku/EMSToken.pm +++ b/lib/WebGUI/Asset/Sku/EMSToken.pm @@ -281,4 +281,5 @@ sub www_viewAll { } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Sku/FlatDiscount.pm b/lib/WebGUI/Asset/Sku/FlatDiscount.pm index 770119c4a..f25926bab 100644 --- a/lib/WebGUI/Asset/Sku/FlatDiscount.pm +++ b/lib/WebGUI/Asset/Sku/FlatDiscount.pm @@ -239,4 +239,5 @@ sub www_addToCart { return $self->www_view; } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index 2e3344c1d..9a81a967f 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -1879,5 +1879,6 @@ override www_view => sub { super(); }; +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Sku/Subscription.pm b/lib/WebGUI/Asset/Sku/Subscription.pm index b6f88bd88..9d89dd4ec 100644 --- a/lib/WebGUI/Asset/Sku/Subscription.pm +++ b/lib/WebGUI/Asset/Sku/Subscription.pm @@ -1011,5 +1011,6 @@ sub www_redeemSubscriptionCode { return $self->processStyle($self->processTemplate($var, $self->redeemSubscriptionCodeTemplateId)); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Sku/ThingyRecord.pm b/lib/WebGUI/Asset/Sku/ThingyRecord.pm index a87725a21..d510325cd 100644 --- a/lib/WebGUI/Asset/Sku/ThingyRecord.pm +++ b/lib/WebGUI/Asset/Sku/ThingyRecord.pm @@ -721,6 +721,7 @@ sub www_renew { return $self->www_editRecord( { message => $i18n->get('renewal added to cart') . ' ^ViewCart;' } ); } ## end sub www_renew +__PACKAGE__->meta->make_immutable; 1; #vim:ft=perl diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm index 1948a6424..44323415e 100644 --- a/lib/WebGUI/Asset/Snippet.pm +++ b/lib/WebGUI/Asset/Snippet.pm @@ -288,6 +288,6 @@ sub www_view { return $output; } - +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Story.pm b/lib/WebGUI/Asset/Story.pm index 648c1852f..fe4dcbdc9 100644 --- a/lib/WebGUI/Asset/Story.pm +++ b/lib/WebGUI/Asset/Story.pm @@ -920,6 +920,7 @@ sub www_view { } +__PACKAGE__->meta->make_immutable; 1; #vim:ft=perl diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index 1864e9968..397a01bc4 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -1174,5 +1174,6 @@ sub www_view { } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/WikiPage.pm b/lib/WebGUI/Asset/WikiPage.pm index a8c22fb1e..caa5ac6a7 100644 --- a/lib/WebGUI/Asset/WikiPage.pm +++ b/lib/WebGUI/Asset/WikiPage.pm @@ -647,5 +647,5 @@ sub www_view { } - +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject.pm b/lib/WebGUI/Asset/Wobject.pm index 1b35dcaed..13313f0f4 100644 --- a/lib/WebGUI/Asset/Wobject.pm +++ b/lib/WebGUI/Asset/Wobject.pm @@ -517,5 +517,6 @@ sub www_view { return "chunked"; } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Article.pm b/lib/WebGUI/Asset/Wobject/Article.pm index d744b7635..6d5f51324 100644 --- a/lib/WebGUI/Asset/Wobject/Article.pm +++ b/lib/WebGUI/Asset/Wobject/Article.pm @@ -438,5 +438,6 @@ override www_view => sub { }; +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Calendar.pm b/lib/WebGUI/Asset/Wobject/Calendar.pm index db9b43e68..d88ea0004 100644 --- a/lib/WebGUI/Asset/Wobject/Calendar.pm +++ b/lib/WebGUI/Asset/Wobject/Calendar.pm @@ -2200,5 +2200,6 @@ toUserTimeZone methods of WebGUI::DateTime for to make less confusion. =cut +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Carousel.pm b/lib/WebGUI/Asset/Wobject/Carousel.pm index 963660eb4..61bc36be3 100644 --- a/lib/WebGUI/Asset/Wobject/Carousel.pm +++ b/lib/WebGUI/Asset/Wobject/Carousel.pm @@ -217,5 +217,6 @@ sub view { return $self->processTemplate($var, undef, $self->{_viewTemplate}); } +__PACKAGE__->meta->make_immutable; 1; #vim:ft=perl diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index 656d265b1..c8610b39c 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -1750,5 +1750,6 @@ sub www_viewRSS { return $self->www_viewRss; } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Collaboration/Newsletter.pm b/lib/WebGUI/Asset/Wobject/Collaboration/Newsletter.pm index 8d5ab9436..6bbeecb90 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration/Newsletter.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration/Newsletter.pm @@ -230,4 +230,5 @@ sub www_mySubscriptionsSave { return $self->www_view; } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Dashboard.pm b/lib/WebGUI/Asset/Wobject/Dashboard.pm index aa8113a49..951bd6cce 100644 --- a/lib/WebGUI/Asset/Wobject/Dashboard.pm +++ b/lib/WebGUI/Asset/Wobject/Dashboard.pm @@ -435,4 +435,5 @@ sub www_view { +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/DataForm.pm b/lib/WebGUI/Asset/Wobject/DataForm.pm index 1cde30a3b..6049abea5 100644 --- a/lib/WebGUI/Asset/Wobject/DataForm.pm +++ b/lib/WebGUI/Asset/Wobject/DataForm.pm @@ -2185,5 +2185,6 @@ sub www_process { return ''; } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/DataTable.pm b/lib/WebGUI/Asset/Wobject/DataTable.pm index 9c0f570cc..adbd3e061 100644 --- a/lib/WebGUI/Asset/Wobject/DataTable.pm +++ b/lib/WebGUI/Asset/Wobject/DataTable.pm @@ -278,4 +278,5 @@ sub www_ajaxUpdateData { return $data; } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm index 0457c7713..83a726f78 100644 --- a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm +++ b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm @@ -2766,5 +2766,6 @@ sub www_viewSubmissionQueue { $self->processTemplate( $params, $self->get('eventSubmissionMainTemplateId'))); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Folder.pm b/lib/WebGUI/Asset/Wobject/Folder.pm index baa2102e3..0374ec9e6 100644 --- a/lib/WebGUI/Asset/Wobject/Folder.pm +++ b/lib/WebGUI/Asset/Wobject/Folder.pm @@ -296,5 +296,6 @@ override www_view => sub { }; +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Gallery.pm b/lib/WebGUI/Asset/Wobject/Gallery.pm index 385d8d61f..3e8ef732b 100644 --- a/lib/WebGUI/Asset/Wobject/Gallery.pm +++ b/lib/WebGUI/Asset/Wobject/Gallery.pm @@ -1552,4 +1552,5 @@ sub www_listFilesForUserRss { return $self->processTemplate( $var, $self->templateIdListFilesForUserRss ); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm index c0ed7a479..132d92206 100644 --- a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm +++ b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm @@ -1612,4 +1612,5 @@ sub www_viewRss { return $self->processTemplate( $var, $self->getParent->templateIdViewAlbumRss ); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/HttpProxy.pm b/lib/WebGUI/Asset/Wobject/HttpProxy.pm index 032d84541..ab2a6e42a 100644 --- a/lib/WebGUI/Asset/Wobject/HttpProxy.pm +++ b/lib/WebGUI/Asset/Wobject/HttpProxy.pm @@ -508,4 +508,5 @@ sub www_view { } } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/InOutBoard.pm b/lib/WebGUI/Asset/Wobject/InOutBoard.pm index 88e62ca0b..dcc168bd4 100644 --- a/lib/WebGUI/Asset/Wobject/InOutBoard.pm +++ b/lib/WebGUI/Asset/Wobject/InOutBoard.pm @@ -566,5 +566,6 @@ order by department, lastName, firstName, InOutBoard_statusLog.dateStamp"; return $self->processStyle($self->processTemplate(\%var, $self->reportTemplateId)); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Layout.pm b/lib/WebGUI/Asset/Wobject/Layout.pm index 87cf0ec5e..5e5c0ea6a 100644 --- a/lib/WebGUI/Asset/Wobject/Layout.pm +++ b/lib/WebGUI/Asset/Wobject/Layout.pm @@ -443,5 +443,6 @@ override www_view => sub { return super(); }; +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Map.pm b/lib/WebGUI/Asset/Wobject/Map.pm index a9a3fe036..d05193c6d 100644 --- a/lib/WebGUI/Asset/Wobject/Map.pm +++ b/lib/WebGUI/Asset/Wobject/Map.pm @@ -631,6 +631,7 @@ sub www_ajaxSetPointLocation { return JSON->new->encode( {message => $i18n->get("message set point location")} ); } +__PACKAGE__->meta->make_immutable; 1; #vim:ft=perl diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index 8907288c3..d9140b4a0 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -1447,4 +1447,5 @@ sub www_setStickied { return undef; } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/MessageBoard.pm b/lib/WebGUI/Asset/Wobject/MessageBoard.pm index a241a7191..91f4aef7e 100644 --- a/lib/WebGUI/Asset/Wobject/MessageBoard.pm +++ b/lib/WebGUI/Asset/Wobject/MessageBoard.pm @@ -172,6 +172,7 @@ override www_view => sub { super(); }; +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/MultiSearch.pm b/lib/WebGUI/Asset/Wobject/MultiSearch.pm index 1c342d421..c18588d5e 100644 --- a/lib/WebGUI/Asset/Wobject/MultiSearch.pm +++ b/lib/WebGUI/Asset/Wobject/MultiSearch.pm @@ -132,4 +132,5 @@ override www_view => sub { super(); }; +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Navigation.pm b/lib/WebGUI/Asset/Wobject/Navigation.pm index 67308aa29..7926ef82d 100644 --- a/lib/WebGUI/Asset/Wobject/Navigation.pm +++ b/lib/WebGUI/Asset/Wobject/Navigation.pm @@ -557,5 +557,6 @@ override www_view => sub { } }; +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Poll.pm b/lib/WebGUI/Asset/Wobject/Poll.pm index 98b1aacc3..b56132443 100644 --- a/lib/WebGUI/Asset/Wobject/Poll.pm +++ b/lib/WebGUI/Asset/Wobject/Poll.pm @@ -557,5 +557,6 @@ sub www_vote { +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/ProjectManager.pm b/lib/WebGUI/Asset/Wobject/ProjectManager.pm index fdb67c27d..d048b73a3 100644 --- a/lib/WebGUI/Asset/Wobject/ProjectManager.pm +++ b/lib/WebGUI/Asset/Wobject/ProjectManager.pm @@ -1985,5 +1985,5 @@ sub www_viewProject { return $self->processStyle($self->processTemplate($var,$self->projectDisplayTemplateId)); } - +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/SQLReport.pm b/lib/WebGUI/Asset/Wobject/SQLReport.pm index 63d42eb5a..d16967245 100644 --- a/lib/WebGUI/Asset/Wobject/SQLReport.pm +++ b/lib/WebGUI/Asset/Wobject/SQLReport.pm @@ -869,5 +869,6 @@ override www_view => sub { super(); }; +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Search.pm b/lib/WebGUI/Asset/Wobject/Search.pm index ce5329e13..33c14728b 100644 --- a/lib/WebGUI/Asset/Wobject/Search.pm +++ b/lib/WebGUI/Asset/Wobject/Search.pm @@ -208,5 +208,6 @@ sub view { return $self->processTemplate(\%var, undef, $self->{_viewTemplate}); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Shelf.pm b/lib/WebGUI/Asset/Wobject/Shelf.pm index c4bffd4e7..a46ca7ec1 100644 --- a/lib/WebGUI/Asset/Wobject/Shelf.pm +++ b/lib/WebGUI/Asset/Wobject/Shelf.pm @@ -419,4 +419,5 @@ sub www_importProducts { } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/StockData.pm b/lib/WebGUI/Asset/Wobject/StockData.pm index 6a4a17031..f71b53a2d 100644 --- a/lib/WebGUI/Asset/Wobject/StockData.pm +++ b/lib/WebGUI/Asset/Wobject/StockData.pm @@ -401,4 +401,5 @@ sub www_displayStock { } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/StoryArchive.pm b/lib/WebGUI/Asset/Wobject/StoryArchive.pm index fd51f84b2..8b381d3ca 100644 --- a/lib/WebGUI/Asset/Wobject/StoryArchive.pm +++ b/lib/WebGUI/Asset/Wobject/StoryArchive.pm @@ -602,5 +602,6 @@ sub www_add { $todayFolder->www_add; } +__PACKAGE__->meta->make_immutable; 1; #vim:ft=perl diff --git a/lib/WebGUI/Asset/Wobject/StoryTopic.pm b/lib/WebGUI/Asset/Wobject/StoryTopic.pm index 620648c77..53aaf03cd 100644 --- a/lib/WebGUI/Asset/Wobject/StoryTopic.pm +++ b/lib/WebGUI/Asset/Wobject/StoryTopic.pm @@ -256,5 +256,6 @@ sub www_viewStory { } +__PACKAGE__->meta->make_immutable; 1; #vim:ft=perl diff --git a/lib/WebGUI/Asset/Wobject/Survey.pm b/lib/WebGUI/Asset/Wobject/Survey.pm index e6625b054..551eb0aae 100644 --- a/lib/WebGUI/Asset/Wobject/Survey.pm +++ b/lib/WebGUI/Asset/Wobject/Survey.pm @@ -3091,4 +3091,5 @@ END_SUMMARY } } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm index 161de15a0..e268629ab 100644 --- a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm +++ b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm @@ -416,5 +416,6 @@ sub www_viewRSS20 { return $self->www_viewRss; } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index d6e09c4b2..bbbae3c20 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -3574,4 +3574,5 @@ sub www_viewThingDataViaAjax { } } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/TimeTracking.pm b/lib/WebGUI/Asset/Wobject/TimeTracking.pm index 4a39e8a5c..faf8915d0 100644 --- a/lib/WebGUI/Asset/Wobject/TimeTracking.pm +++ b/lib/WebGUI/Asset/Wobject/TimeTracking.pm @@ -883,4 +883,5 @@ sub _buildRow { } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/UserList.pm b/lib/WebGUI/Asset/Wobject/UserList.pm index 86c896cb1..3d155c858 100644 --- a/lib/WebGUI/Asset/Wobject/UserList.pm +++ b/lib/WebGUI/Asset/Wobject/UserList.pm @@ -618,4 +618,5 @@ sub view { } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/WeatherData.pm b/lib/WebGUI/Asset/Wobject/WeatherData.pm index 194fcace4..344f938a5 100644 --- a/lib/WebGUI/Asset/Wobject/WeatherData.pm +++ b/lib/WebGUI/Asset/Wobject/WeatherData.pm @@ -141,4 +141,5 @@ sub view { return $self->processTemplate(\%var, undef, $self->{_viewTemplate}); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Asset/Wobject/WikiMaster.pm b/lib/WebGUI/Asset/Wobject/WikiMaster.pm index 6320c18e3..746bfa27d 100644 --- a/lib/WebGUI/Asset/Wobject/WikiMaster.pm +++ b/lib/WebGUI/Asset/Wobject/WikiMaster.pm @@ -751,4 +751,5 @@ sub www_search { return $self->processStyle($self->processTemplate($var, $self->searchTemplateId)); } +__PACKAGE__->meta->make_immutable; 1; diff --git a/lib/WebGUI/Definition/Meta/Asset.pm b/lib/WebGUI/Definition/Meta/Asset.pm index 3e70971bc..1627b958c 100644 --- a/lib/WebGUI/Definition/Meta/Asset.pm +++ b/lib/WebGUI/Definition/Meta/Asset.pm @@ -76,9 +76,17 @@ Returns an array of the names of all tables in every class used by this class. =cut sub get_tables { + my $self = shift; + if ($self->is_immutable) { + return @{ $self->{__immutable}{get_tables_methods} ||= [ $self->_get_tables ] }; + } + goto &_get_tables; +} + +sub _get_tables { my $self = shift; my %seen = (); - my @tables = + my @tables = grep { ! $seen{$_}++ } map { $_->tableName } $self->get_all_properties diff --git a/lib/WebGUI/Definition/Meta/Class.pm b/lib/WebGUI/Definition/Meta/Class.pm index 98797db3f..1b2bab583 100644 --- a/lib/WebGUI/Definition/Meta/Class.pm +++ b/lib/WebGUI/Definition/Meta/Class.pm @@ -76,6 +76,14 @@ Returns an array of all attribute names across all meta classes. =cut sub get_all_attributes_list { + my $self = shift; + if ($self->is_immutable) { + return @{ $self->{__immutable}{get_all_attributes_list} ||= [ $self->_get_all_attributes_list ] }; + } + goto &_get_all_attributes_list; +} + +sub _get_all_attributes_list { my $self = shift; my @attributes = (); CLASS: foreach my $meta ($self->get_all_class_metas) { From aba7dd7be43862b33653e4780d505cab7cd8fbeb Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Sun, 18 Apr 2010 18:51:25 -0500 Subject: [PATCH 22/36] make sure pluggable passes through exceptions --- lib/WebGUI/Pluggable.pm | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/Pluggable.pm b/lib/WebGUI/Pluggable.pm index c5608288c..80a95df9c 100644 --- a/lib/WebGUI/Pluggable.pm +++ b/lib/WebGUI/Pluggable.pm @@ -193,6 +193,9 @@ object. sub instanciate { my ($module, $sub, $params) = @_; if ( ! eval { load($module); 1 } ) { + if ( ref $@ ) { + die $@; + } croak "Could not instanciate object using $sub on $module: $@"; } # Module loaded properly @@ -229,7 +232,7 @@ my %moduleError; sub load { my $module = shift; if ($moduleError{$module}) { - croak "Could not load $module because $moduleError{$module}"; + croak $moduleError{$module}; } # Try to load the module @@ -239,8 +242,13 @@ sub load { return 1; } else { - $moduleError{$module} = $@; - croak "Could not load $module because $@"; + if ( ref $@ ) { + $moduleError{$module} = $@; + } + else { + $moduleError{$module} = "Could not load $module because $@"; + } + croak $moduleError{$module}; } } @@ -267,6 +275,8 @@ An array reference of parameters to pass in to the sub routine. sub run { my ($module, $sub, $params) = @_; if (! eval { load($module); 1 }) { + die $@ + if ref $@; croak "Unable to run $sub on $module: $@"; } elsif (my $sub = $module->can($sub)) { From 6298d394ff5c95e6a6ac063a896a0bf0e01c49a8 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Sun, 18 Apr 2010 18:54:21 -0500 Subject: [PATCH 23/36] don't recompute packed template on object instantiation --- lib/WebGUI/Asset/Template.pm | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index 397a01bc4..c888b0e41 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -35,13 +35,7 @@ property template => ( sub _template_autopack { my ($self, $new, $old) = @_; return if $new eq $old; - my $packed = $new; - HTML::Packer::minify( \$packed, { - remove_comments => 1, - do_javascript => "shrink", - do_stylesheet => "minify", - } ); - $self->templatePacked($packed); + $self->_clear_templatePacked; } property isEditable => ( noFormPost => 1, @@ -78,9 +72,21 @@ property namespace => ( ); property templatePacked => ( fieldType => 'hidden', - default => undef, noFormPost => 1, + lazy => 1, + clearer => '_clear_templatePacked', + builder => '_build_templatePacked', ); +sub _build_templatePacked { + my $self = shift; + my $template = $self->template; + HTML::Packer::minify( \$template, { + remove_comments => 1, + do_javascript => 'shrink', + do_stylesheet => 'minify', + } ); +} + property usePacked => ( fieldType => 'yesNo', default => 0, From cd8456ee9923d37c5bdfb08a1d1b9d46c7ace73e Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Sun, 18 Apr 2010 18:55:38 -0500 Subject: [PATCH 24/36] speed up user instantiation --- lib/WebGUI/User.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index a7ece5df6..883978983 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -1075,7 +1075,8 @@ sub new { # Fill in dataDefault my $default = $session->db->buildHashRef( - "SELECT fieldName, dataDefault FROM userProfileField" + "SELECT fieldName, dataDefault FROM userProfileField", [], + { noOrder => 1 }, ); for my $key (keys %profile) { if (!defined $profile{$key} || $profile{$key} eq '') { From bd80af6b605270e1ed7247e8d100fc89be1f4b4d Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Mon, 19 Apr 2010 16:37:11 -0500 Subject: [PATCH 25/36] fix packing in templates and snippets --- lib/WebGUI/Asset/Snippet.pm | 58 ++++++++++++++++++++---------------- lib/WebGUI/Asset/Template.pm | 1 + 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm index 44323415e..8567c0ad8 100644 --- a/lib/WebGUI/Asset/Snippet.pm +++ b/lib/WebGUI/Asset/Snippet.pm @@ -35,38 +35,44 @@ property snippet => ( hoverHelp => ['snippet description','Asset_Snippet'], default => undef, ); -around snippet => sub { - my $orig = shift; +sub _trigger_snippet { my $self = shift; - if (@_ > 1) { - my $packed = $_[0]; - if ( $self->mimeType eq "text/html" ) { - HTML::Packer::minify( \$packed, { - remove_comments => 1, - do_javascript => "shrink", - do_stylesheet => "minify", - } ); - } - elsif ( $self->mimeType eq "text/css" ) { - CSS::Packer::minify( \$packed, { - compress => 'minify', - }); - } - elsif ( $self->mimeType eq 'text/javascript' ) { - JavaScript::Packer::minify( \$packed, { - compress => "shrink", - }); - } - $self->snippetPacked($packed); + my ($new, $old) = @_; + if ($new ne $old) { + $self->_clear_snippetPacked; } - $self->$orig(@_); -}; - +} property snippetPacked => ( fieldType => "hidden", - default => undef, noFormPost => 1, + lazy => 1, + clearer => '_clear_snippetPacked', + builder => '_build_snippetPacked', ); + +sub _build_snippetPacked { + my $self = shift; + my $snippet = $self->snippet; + if ( $self->mimeType eq "text/html" ) { + HTML::Packer::minify( \$snippet, { + remove_comments => 1, + do_javascript => "shrink", + do_stylesheet => "minify", + } ); + } + elsif ( $self->mimeType eq "text/css" ) { + CSS::Packer::minify( \$snippet, { + compress => 'minify', + }); + } + elsif ( $self->mimeType eq 'text/javascript' ) { + JavaScript::Packer::minify( \$snippet, { + compress => "shrink", + }); + } + $snippet; +} + property usePacked => ( tab => 'properties', fieldType => 'yesNo', diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index c888b0e41..e7a9f698c 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -85,6 +85,7 @@ sub _build_templatePacked { do_javascript => 'shrink', do_stylesheet => 'minify', } ); + $template; } property usePacked => ( From 5c36973aa0fa8ca9732fcd7f1c6bf6c75e6f62f6 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 19 Apr 2010 18:58:04 -0500 Subject: [PATCH 26/36] cache: s/flush/clear/ --- lib/WebGUI/AssetLineage.pm | 2 +- lib/WebGUI/Operation/Cache.pm | 2 +- lib/WebGUI/Operation/Settings.pm | 2 +- lib/WebGUI/Session/Scratch.pm | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index 59ef0bec5..7d4441a69 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -152,7 +152,7 @@ sub cascadeLineage { [$newLineage, length($oldLineage) + 1, $oldLineage . '%'] ); if ($records > 20) { - $self->session->cache->flush; + $self->session->cache->clear; } else { my $descendants = $self->session->db->read("SELECT assetId FROM asset WHERE lineage LIKE ?", [$newLineage . '%']); diff --git a/lib/WebGUI/Operation/Cache.pm b/lib/WebGUI/Operation/Cache.pm index 1f231d1e1..11171fc44 100644 --- a/lib/WebGUI/Operation/Cache.pm +++ b/lib/WebGUI/Operation/Cache.pm @@ -92,7 +92,7 @@ sub www_flushCache { return $session->privilege->adminOnly unless canView($session); # Flush the cache - $session->cache->flush; + $session->cache->clear; return www_manageCache($session); } diff --git a/lib/WebGUI/Operation/Settings.pm b/lib/WebGUI/Operation/Settings.pm index 3961ff061..7656fd906 100644 --- a/lib/WebGUI/Operation/Settings.pm +++ b/lib/WebGUI/Operation/Settings.pm @@ -736,7 +736,7 @@ sub www_saveSettings { $session->db->write( "UPDATE userProfileData SET showMessageOnLoginSeen=0" ); - $session->cache->flush; + $session->cache->clear; } return www_editSettings($session, { errors => \@errors, message => $i18n->get("editSettings done") }); diff --git a/lib/WebGUI/Session/Scratch.pm b/lib/WebGUI/Session/Scratch.pm index 28e29555b..01e71df91 100644 --- a/lib/WebGUI/Session/Scratch.pm +++ b/lib/WebGUI/Session/Scratch.pm @@ -107,7 +107,7 @@ sub deleteName { return undef unless ($name); delete $self->{_data}{$name}; my $session = $self->session; - $session->cache->flush; + $session->cache->clear; $session->db->write("delete from userSessionScratch where name=?", [$name]); } @@ -134,7 +134,7 @@ sub deleteNameByValue { return undef unless ($name and defined $value); delete $self->{_data}{$name} if ($self->{_data}{$name} eq $value); my $session = $self->session; - $session->cache->flush; + $session->cache->clear; $session->db->write("delete from userSessionScratch where name=? and value=?", [$name,$value]); } From ea9bc5b57157d2360529da8d7f01c2da3c108065 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 20 Apr 2010 10:43:30 -0700 Subject: [PATCH 27/36] Fix WebGUI::Utility method used in WikiMaster. --- lib/WebGUI/Asset/Wobject/WikiMaster.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/WebGUI/Asset/Wobject/WikiMaster.pm b/lib/WebGUI/Asset/Wobject/WikiMaster.pm index 746bfa27d..d33d2c0e7 100644 --- a/lib/WebGUI/Asset/Wobject/WikiMaster.pm +++ b/lib/WebGUI/Asset/Wobject/WikiMaster.pm @@ -187,6 +187,7 @@ with 'WebGUI::Role::Asset::RssFeed'; use WebGUI::International; use HTML::Parser; use URI::Escape; +use WebGUI::Utility qw/isIn/; #------------------------------------------------------------------- From c214e5f6e544eb8ae3bed56f802444c57ec429d4 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 20 Apr 2010 11:01:04 -0700 Subject: [PATCH 28/36] remove some ->get calls --- lib/WebGUI/Asset.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 114976400..7fefbd645 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -2311,7 +2311,7 @@ sub publish { my $stateList = $self->session->db->quoteAndJoin($statesToPublish); my $where = ($statesToPublish) ? "and state in (".$stateList.")" : ""; - my $assetIds = $self->session->db->buildArrayRef("select assetId from asset where lineage like ".$self->session->db->quote($self->get("lineage").'%')." $where"); + my $assetIds = $self->session->db->buildArrayRef("select assetId from asset where lineage like ".$self->session->db->quote($self->lineage.'%')." $where"); my $idList = $self->session->db->quoteAndJoin($assetIds); $self->session->db->write("update asset set state='published', stateChangedBy=".$self->session->db->quote($self->session->user->userId).", stateChanged=".time()." where assetId in (".$idList.")"); @@ -2349,7 +2349,7 @@ sub purgeCache { $stow->delete('assetLineage'); $stow->delete('assetClass'); $stow->delete('assetRevision'); - $self->session->cache->remove("asset".$self->getId.$self->get("revisionDate")); + $self->session->cache->remove("asset".$self->getId.$self->revisionDate); } From 94fff8d6fb2dc21ba6fb062de8131dc6cb45ac9b Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 20 Apr 2010 11:25:07 -0700 Subject: [PATCH 29/36] Removing another ->get from AssetClipboard --- lib/WebGUI/AssetClipboard.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WebGUI/AssetClipboard.pm b/lib/WebGUI/AssetClipboard.pm index 5a29d4f9b..389f0cc09 100644 --- a/lib/WebGUI/AssetClipboard.pm +++ b/lib/WebGUI/AssetClipboard.pm @@ -64,7 +64,7 @@ sub cut { my $session = $self->session; return undef if ($self->getId eq $session->setting->get("defaultPage") || $self->getId eq $session->setting->get("notFoundPage")); $session->db->beginTransaction; - $session->db->write("update asset set state='clipboard-limbo' where lineage like ? and state='published'",[$self->get("lineage").'%']); + $session->db->write("update asset set state='clipboard-limbo' where lineage like ? and state='published'",[$self->lineage.'%']); $session->db->write("update asset set state='clipboard', stateChangedBy=?, stateChanged=? where assetId=?", [$session->user->userId, time(), $self->getId]); $session->db->commit; $self->state("clipboard"); From 3b6c4e8372a1288444c23ad225c0a42b1b433df0 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 20 Apr 2010 12:14:28 -0700 Subject: [PATCH 30/36] Set the default state of the created object to "published". --- lib/WebGUI/AssetLineage.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index 7d4441a69..960ff71b1 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -89,6 +89,7 @@ sub addChild { $session->db->commit; $properties->{assetId} = $id; $properties->{parentId} = $self->getId; + $properties->{state} = 'published'; my $temp = WebGUI::Asset->newByPropertyHashRef($session, $properties) || croak "Couldn't create a new $properties->{className} asset!"; my $newAsset = $temp->addRevision($properties, $now, $options); $self->updateHistory("added child ".$id); From 7273f705e0522eb480c127a489e5d026f8118ab2 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 20 Apr 2010 12:20:36 -0700 Subject: [PATCH 31/36] Provide defaults for the workflowId and the zoom. --- lib/WebGUI/Asset/Wobject/Map.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/WebGUI/Asset/Wobject/Map.pm b/lib/WebGUI/Asset/Wobject/Map.pm index d05193c6d..bc3bba2bc 100644 --- a/lib/WebGUI/Asset/Wobject/Map.pm +++ b/lib/WebGUI/Asset/Wobject/Map.pm @@ -85,6 +85,7 @@ property startZoom => ( maximum => 19, label => ["startZoom label", 'Asset_Map'], hoverHelp => ["startZoom description", 'Asset_Map'], + default => 1, ); property templateIdEditPoint => ( tab => "display", @@ -116,6 +117,7 @@ property workflowIdPoint => ( label => ["workflowIdPoint label", 'Asset_Map'], hoverHelp => ["workflowIdPoint description", 'Asset_Map'], type => 'WebGUI::VersionTag', + default => "pbworkflow000000000003", ); #------------------------------------------------------------------- From 92c2b4e0e87ebeb532b3e5dfee29ab0401186734 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Tue, 20 Apr 2010 11:00:05 -0500 Subject: [PATCH 32/36] initial tree view (not working) --- lib/WebGUI/Admin.pm | 92 ++++++- www/extras/admin/admin.js | 514 +++++++++++++++++++++++++++++++++----- 2 files changed, 539 insertions(+), 67 deletions(-) diff --git a/lib/WebGUI/Admin.pm b/lib/WebGUI/Admin.pm index a100ecc40..d21283b55 100644 --- a/lib/WebGUI/Admin.pm +++ b/lib/WebGUI/Admin.pm @@ -3,6 +3,7 @@ package WebGUI::Admin; # The new WebGUI Admin console use Moose; +use JSON qw( from_json to_json ); use namespace::autoclean; has 'session' => ( @@ -112,6 +113,40 @@ sub getNewContentTemplateVars { my $vars = []; } +#---------------------------------------------------------------------------- + +=head2 getTreePaginator ( $asset ) + +Get a page for the Asset Tree view. Returns a WebGUI::Paginator object +filled with asset IDs. + +=cut + +sub getTreePaginator { + my ( $self, $asset ) = @_; + my $session = $self->session; + + my $orderByColumn = $session->form->get( 'orderByColumn' ) + || "lineage" + ; + my $orderByDirection = lc $session->form->get( 'orderByDirection' ) eq "desc" + ? "DESC" + : "ASC" + ; + + my $recordOffset = $session->form->get( 'recordOffset' ) || 1; + my $rowsPerPage = $session->form->get( 'rowsPerPage' ) || 100; + my $currentPage = int ( $recordOffset / $rowsPerPage ) + 1; + + my $p = WebGUI::Paginator->new( $session, '', $rowsPerPage, 'pn', $currentPage ); + + my $orderBy = $session->db->dbh->quote_identifier( $orderByColumn ) . ' ' . $orderByDirection; + $p->setDataByArrayRef( $asset->getLineage( ['children'], { orderByClause => $orderBy } ) ); + + return $p; +} + + #---------------------------------------------------------------------- =head2 getVersionTagTemplateVars @@ -143,6 +178,61 @@ sub getVersionTagTemplateVars { #---------------------------------------------------------------------- +=head2 www_getTreeData ( ) + +Get the Tree data for a given asset URL + +=cut + +sub www_getTreeData { + my ( $self ) = @_; + my $session = $self->session; + my ( $user, $form ) = $session->quick(qw{ user form }); + + my $assetUrl = $form->get('assetUrl'); + my $asset = WebGUI::Asset->newByUrl( $session, $assetUrl ); + + my $i18n = WebGUI::International->new( $session, "Asset" ); + my $assetInfo = { assets => [] }; + my $p = $self->getTreePaginator( $asset ); + + for my $assetId ( @{ $p->getPageData } ) { + my $asset = WebGUI::Asset->newById( $session, $assetId ); + + # Populate the required fields to fill in + my %fields = ( + assetId => $asset->getId, + url => $asset->getUrl, + lineage => $asset->lineage, + title => $asset->menuTitle, + revisionDate => $asset->revisionDate, + childCount => $asset->getChildCount, + assetSize => $asset->assetSize, + lockedBy => ($asset->isLockedBy ? $asset->lockedBy->username : ''), + actions => $asset->canEdit && $asset->canEditIfLocked, + ); + + $fields{ className } = {}; + # The asset icon + $fields{ icon } = $asset->getIcon("small"); + + # The asset type (i18n name) + $fields{ className } = $asset->getName; + + push @{ $assetInfo->{ assets } }, \%fields; + } + + $assetInfo->{ totalAssets } = $p->getRowCount; + $assetInfo->{ sort } = $session->form->get( 'orderByColumn' ); + $assetInfo->{ dir } = lc $session->form->get( 'orderByDirection' ); + + $session->http->setMimeType( 'application/json' ); + + return to_json( $assetInfo ); +} + +#---------------------------------------------------------------------- + =head2 www_view ( session ) Show the main Admin console wrapper @@ -150,7 +240,7 @@ Show the main Admin console wrapper =cut sub www_view { - my ($self) = @_; + my ( $self ) = @_; my $session = $self->session; my ( $user, $url, $style ) = $session->quick(qw{ user url style }); diff --git a/www/extras/admin/admin.js b/www/extras/admin/admin.js index 696db56dd..af80cf597 100644 --- a/www/extras/admin/admin.js +++ b/www/extras/admin/admin.js @@ -7,38 +7,28 @@ if ( typeof WebGUI == "undefined" ) { WebGUI = {}; } -WebGUI.Admin = (function(){ - // Public methods +WebGUI.Admin = function(){ + // Public properties + this.cfg = cfg; + this.currentAssetDef = null; + this.viewOrTree = 0; // 0 - Last on View tab. 1 - Last on Tree tab - return function (cfg) { - // Public properties - this.cfg = cfg; - this.currentAssetDef = null; - this.viewOrTree = 0; // 0 - Last on View tab. 1 - Last on Tree tab + // Default configuration + if ( !this.cfg.locationBarId ) { + this.cfg.locationBarId = "locationBar"; + } + if ( !this.cfg.tabBarId ) { + this.cfg.tabBarId = "tabBar"; + } - // Default configuration - if ( !this.cfg.locationBarId ) { - this.cfg.locationBarId = "locationBar"; - } - if ( !this.cfg.tabBarId ) { - this.cfg.tabBarId = "tabBar"; - } + this.locationBar = new WebGUI.Admin.LocationBar( this.cfg.locationBarId ); + this.tabBar = new YAHOO.widget.TabView( this.cfg.tabBarId ); + // Keep track of View and Tree tabs + this.tabBar.getTab(0).addListener('click',this.afterShowViewTab,this,true); + this.tabBar.getTab(1).addListener('click',this.afterShowTreeTab,this,true); - // Private properties - var self = this; - - // Private methods - function _init() { - self.locationBar = new WebGUI.Admin.LocationBar( self.cfg.locationBarId ); - self.tabBar = new YAHOO.widget.TabView( self.cfg.tabBarId ); - // Keep track of View and Tree tabs - self.tabBar.getTab(0).addListener('click',self.afterShowViewTab,self,true); - self.tabBar.getTab(1).addListener('click',self.afterShowTreeTab,self,true); - } - - _init(); - }; -})(); + // Private methods +}; /** * afterShowTreeTab() @@ -111,44 +101,41 @@ WebGUI.Admin.LocationBar var self = this; var _element = document.getElementById( self.id ); - function _init () { - // Create buttons - self.btnBack = new YAHOO.widget.Button( "backButton", { - type : "split", - label : '', - disabled : true, - lazyloadmenu : false, - onclick : { fn: self.goBack, scope: self }, - menu : [] - } ); - self.btnForward = new YAHOO.widget.Button( "forwardButton", { - type : "split", - label : '', - disabled : true, - lazyloadmenu : false, - onclick : { fn: self.goForward, scope: self }, - menu : [] - } ); - self.btnSearch = new YAHOO.widget.Button( "searchButton", { - label : '', - onclick : { fn: self.clickSearchButton, scope: self } - } ); - self.btnHome = new YAHOO.widget.Button( "homeButton", { - type : "button", - label : '', - onclick : { fn: self.goHome, scope: self } - } ); - // Take control of the location input - self.klInput = new YAHOO.util.KeyListener( "locationUrl", { keys: 13 }, { - fn: self.doInputSearch, - scope: self, - correctScope: true - } ); - YAHOO.util.Event.addListener( "locationUrl", "focus", self.inputFocus, self, true ); - YAHOO.util.Event.addListener( "locationUrl", "blur", self.inputBlur, self, true ); - } + // Create buttons + this.btnBack = new YAHOO.widget.Button( "backButton", { + type : "split", + label : '', + disabled : true, + lazyloadmenu : false, + onclick : { fn: this.goBack, scope: this }, + menu : [] + } ); + this.btnForward = new YAHOO.widget.Button( "forwardButton", { + type : "split", + label : '', + disabled : true, + lazyloadmenu : false, + onclick : { fn: this.goForward, scope: this }, + menu : [] + } ); + this.btnSearch = new YAHOO.widget.Button( "searchButton", { + label : '', + onclick : { fn: this.clickSearchButton, scope: this } + } ); + this.btnHome = new YAHOO.widget.Button( "homeButton", { + type : "button", + label : '', + onclick : { fn: this.goHome, scope: this } + } ); + // Take control of the location input + this.klInput = new YAHOO.util.KeyListener( "locationUrl", { keys: 13 }, { + fn: this.doInputSearch, + scope: this, + correctScope: true + } ); + YAHOO.util.Event.addListener( "locationUrl", "focus", this.inputFocus, this, true ); + YAHOO.util.Event.addListener( "locationUrl", "blur", this.inputBlur, this, true ); - _init(); }; /** @@ -381,5 +368,400 @@ WebGUI.Admin.LocationBar.prototype.swapForwardToBack }; +/**************************************************************************** + * + * WebGUI.Admin.Tree + */ + +WebGUI.Admin.Tree = function(){ + this.moreMenusDisplayed = {}; + this.crumbMoreMenu = null; +}; + +/** + * appendToUrl( url, params ) + * Add URL components to a URL; + */ +WebGUI.Admin.Tree.prototype.appendToUrl = function ( url, params ) { + var components = [ url ]; + if (url.match(/\?/)) { + components.push(";"); + } + else { + components.push("?"); + } + components.push(params); + return components.join(''); +}; + +/** + * addHighlightToRow ( child ) + * Highlight the row containing this element by adding to it the "highlight" + * class + */ +WebGUI.Admin.Tree.prototype.addHighlightToRow = function ( child ) { + var row = this.findRow( child ); + if ( !YAHOO.util.Dom.hasClass( row, "highlight" ) ) { + YAHOO.util.Dom.addClass( row, "highlight" ); + } +}; + +/** + * buildMoreMenu ( url, linkElement ) + * Build a WebGUI style "More" menu for the asset referred to by url + */ +WebGUI.AssetManager.buildMoreMenu = function ( url, linkElement, isNotLocked ) { + var rawItems = this.moreMenuItems; + var menuItems = []; + var isLocked = !isNotLocked; + for ( var i = 0; i < rawItems.length; i++ ) { + var itemUrl = rawItems[i].url + ? this.appendToUrl(url, rawItems[i].url) + : url + ; + if (! (itemUrl.match( /func=edit;/) && isLocked )) { + menuItems.push( { "url" : itemUrl, "text" : rawItems[i].label } ); + } + } + var options = { + "zindex" : 1000, + "clicktohide" : true, + "position" : "dynamic", + "context" : [ linkElement, "tl", "bl", ["beforeShow", "windowResize"] ], + "itemdata" : menuItems + }; + + return options; +}; + +/** + * findRow ( child ) + * Find the row that contains this child element. + */ +WebGUI.Admin.Tree.prototype.findRow = function ( child ) { + var node = child; + while ( node ) { + if ( node.tagName == "TR" ) { + return node; + } + node = node.parentNode; + } +}; + +/** + * formatActions ( ) + * Format the Edit and More links for the row + */ +WebGUI.AssetManager.formatActions = function ( elCell, oRecord, oColumn, orderNumber ) { + if ( oRecord.getData( 'actions' ) ) { + elCell.innerHTML + = '' + + WebGUI.AssetManager.i18n.get('Asset', 'edit') + '' + + ' | ' + ; + } + else { + elCell.innerHTML = ""; + } + var more = document.createElement( 'a' ); + elCell.appendChild( more ); + more.appendChild( document.createTextNode( WebGUI.AssetManager.i18n.get('Asset','More' ) ) ); + more.href = '#'; + + // Delete the old menu + if ( document.getElementById( 'moreMenu' + oRecord.getData( 'assetId' ) ) ) { + var oldMenu = document.getElementById( 'moreMenu' + oRecord.getData( 'assetId' ) ); + oldMenu.parentNode.removeChild( oldMenu ); + } + + var options = WebGUI.AssetManager.buildMoreMenu(oRecord.getData( 'url' ), more, oRecord.getData( 'actions' )); + + var menu = new YAHOO.widget.Menu( "moreMenu" + oRecord.getData( 'assetId' ), options ); + YAHOO.util.Event.onDOMReady( function () { menu.render( document.getElementById( 'assetManager' ) ); } ); + YAHOO.util.Event.addListener( more, "click", function (e) { YAHOO.util.Event.stopEvent(e); menu.show(); menu.focus(); }, null, menu ); +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.formatAssetIdCheckbox ( ) + Format the checkbox for the asset ID. +*/ +WebGUI.AssetManager.formatAssetIdCheckbox = function ( elCell, oRecord, oColumn, orderNumber ) { + elCell.innerHTML = ''; +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.formatAssetSize ( ) + Format the asset class name +*/ +WebGUI.AssetManager.formatAssetSize = function ( elCell, oRecord, oColumn, orderNumber ) { + elCell.innerHTML = oRecord.getData( "assetSize" ); +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.formatClassName ( ) + Format the asset class name +*/ +WebGUI.AssetManager.formatClassName = function ( elCell, oRecord, oColumn, orderNumber ) { + elCell.innerHTML = ' ' + + oRecord.getData( "className" ); +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.formatLockedBy ( ) + Format the asset class name +*/ +WebGUI.AssetManager.formatLockedBy = function ( elCell, oRecord, oColumn, orderNumber ) { + var extras = getWebguiProperty('extrasURL'); + elCell.innerHTML + = oRecord.getData( 'lockedBy' ) + ? '' + + '' + WebGUI.AssetManager.i18n.get('WebGUI', 'locked by') + ' ' + oRecord.getData( 'lockedBy' ) + '' + + '' + : '' + + '' + WebGUI.AssetManager.i18n.get('Asset', 'unlocked') + '' + + '' + ; +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.formatRank ( ) + Format the input for the rank box +*/ +WebGUI.AssetManager.formatRank = function ( elCell, oRecord, oColumn, orderNumber ) { + var rank = oRecord.getData("lineage").match(/[1-9][0-9]{0,5}$/); + elCell.innerHTML = ''; +}; + + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.DefaultSortedBy ( ) +*/ +WebGUI.AssetManager.DefaultSortedBy = { + "key" : "lineage", + "dir" : YAHOO.widget.DataTable.CLASS_ASC +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.BuildQueryString ( ) +*/ +WebGUI.AssetManager.BuildQueryString = function ( state, dt ) { + var query = "recordOffset=" + state.pagination.recordOffset + + ';orderByDirection=' + ((state.sortedBy.dir === YAHOO.widget.DataTable.CLASS_DESC) ? "DESC" : "ASC") + + ';rowsPerPage=' + state.pagination.rowsPerPage + + ';orderByColumn=' + state.sortedBy.key + ; + return query; + }; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.formatRevisionDate ( ) + Format the asset class name +*/ +WebGUI.AssetManager.formatRevisionDate = function ( elCell, oRecord, oColumn, orderNumber ) { + var revisionDate = new Date( oRecord.getData( "revisionDate" ) * 1000 ); + var minutes = revisionDate.getMinutes(); + if (minutes < 10) { + minutes = "0" + minutes; + } + elCell.innerHTML = revisionDate.getFullYear() + '-' + ( revisionDate.getMonth() + 1 ) + + '-' + revisionDate.getDate() + ' ' + ( revisionDate.getHours() ) + + ':' + minutes + ; +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.formatTitle ( ) + Format the link for the title +*/ +WebGUI.AssetManager.formatTitle = function ( elCell, oRecord, oColumn, orderNumber ) { + elCell.innerHTML = '' + + ( oRecord.getData( 'childCount' ) > 0 ? "+" : " " ) + + ' ' + + oRecord.getData( 'title' ) + + '' + ; +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.initManager ( ) + Initialize the i18n interface +*/ +WebGUI.AssetManager.initManager = function (o) { + WebGUI.AssetManager.i18n + = new WebGUI.i18n( { + namespaces : { + 'Asset' : [ + "edit", + "More", + "unlocked", + "locked by" + ], + 'WebGUI' : [ + "< prev", + "next >" + ] + }, + onpreload : { + fn : WebGUI.AssetManager.initDataTable + } + } ); +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.initDataTable ( ) + Initialize the www_manage page +*/ +WebGUI.AssetManager.initDataTable = function (o) { + var assetPaginator = new YAHOO.widget.Paginator({ + containers : ['pagination'], + pageLinks : 7, + rowsPerPage : 100, + previousPageLinkLabel : WebGUI.AssetManager.i18n.get('WebGUI', '< prev'), + nextPageLinkLabel : WebGUI.AssetManager.i18n.get('WebGUI', 'next >'), + template : "{CurrentPageReport} {PreviousPageLink} {PageLinks} {NextPageLink}" + }); + + + // initialize the data source + WebGUI.AssetManager.DataSource + = new YAHOO.util.DataSource( '?op=assetManager;method=ajaxGetManagerPage;',{connTimeout:30000} ); + WebGUI.AssetManager.DataSource.responseType + = YAHOO.util.DataSource.TYPE_JSON; + WebGUI.AssetManager.DataSource.responseSchema + = { + resultsList: 'assets', + fields: [ + { key: 'assetId' }, + { key: 'lineage' }, + { key: 'actions' }, + { key: 'title' }, + { key: 'className' }, + { key: 'revisionDate' }, + { key: 'assetSize' }, + { key: 'lockedBy' }, + { key: 'icon' }, + { key: 'url' }, + { key: 'childCount' } + ], + metaFields: { + totalRecords: "totalAssets" // Access to value in the server response + } + }; + + + + // Initialize the data table + WebGUI.AssetManager.DataTable + = new YAHOO.widget.DataTable( 'dataTableContainer', + WebGUI.AssetManager.ColumnDefs, + WebGUI.AssetManager.DataSource, + { + initialRequest : 'recordOffset=0', + dynamicData : true, + paginator : assetPaginator, + sortedBy : WebGUI.AssetManager.DefaultSortedBy, + generateRequest : WebGUI.AssetManager.BuildQueryString + } + ); + + WebGUI.AssetManager.DataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) { + oPayload.totalRecords = oResponse.meta.totalRecords; + return oPayload; + }; + +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.removeHighlightFromRow ( child ) + Remove the highlight from a row by removing the "highlight" class. +*/ +WebGUI.AssetManager.removeHighlightFromRow = function ( child ) { + var row = WebGUI.AssetManager.findRow( child ); + if ( YAHOO.util.Dom.hasClass( row, "highlight" ) ) { + YAHOO.util.Dom.removeClass( row, "highlight" ); + } +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.selectRow ( child ) + Check the assetId checkbox in the row that contains the given child. + Used when something in the row changes. +*/ +WebGUI.AssetManager.selectRow = function ( child ) { + // First find the row + var node = WebGUI.AssetManager.findRow( child ); + WebGUI.AssetManager.addHighlightToRow( child ); + + // Now find the assetId checkbox in the first element + var inputs = node.getElementsByTagName( "input" ); + for ( var i = 0; i < inputs.length; i++ ) { + if ( inputs[i].name == "assetId" ) { + inputs[i].checked = true; + break; + } + } +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.showMoreMenu ( url, linkTextId ) + Build a More menu for the last element of the Crumb trail +*/ +WebGUI.AssetManager.showMoreMenu += function ( url, linkTextId, isNotLocked ) { + + var menu; + if ( typeof WebGUI.AssetManager.CrumbMoreMenu == "undefined" ) { + var more = document.getElementById(linkTextId); + var options = WebGUI.AssetManager.buildMoreMenu(url, more, isNotLocked); + menu = new YAHOO.widget.Menu( "crumbMoreMenu", options ); + menu.render( document.getElementById( 'assetManager' ) ); + WebGUI.AssetManager.CrumbMoreMenu = menu; + } + else { + menu = WebGUI.AssetManager.CrumbMoreMenu; + } + menu.show(); + menu.focus(); +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.toggleHighlightForRow ( checkbox ) + Toggle the highlight for the row based on the state of the checkbox +*/ +WebGUI.AssetManager.toggleHighlightForRow = function ( checkbox ) { + if ( checkbox.checked ) { + WebGUI.AssetManager.addHighlightToRow( checkbox ); + } + else { + WebGUI.AssetManager.removeHighlightFromRow( checkbox ); + } +}; + +/*--------------------------------------------------------------------------- + WebGUI.AssetManager.toggleRow ( child ) + Toggles the entire row by finding the checkbox and doing what needs to be + done. +*/ +WebGUI.AssetManager.toggleRow = function ( child ) { + var row = WebGUI.AssetManager.findRow( child ); + + // Find the checkbox + var inputs = row.getElementsByTagName( "input" ); + for ( var i = 0; i < inputs.length; i++ ) { + if ( inputs[i].name == "assetId" ) { + inputs[i].checked = inputs[i].checked + ? false + : true + ; + WebGUI.AssetManager.toggleHighlightForRow( inputs[i] ); + break; + } + } +}; From 8d432c8be66d0af901cc006dfca93b97ec184feb Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Tue, 20 Apr 2010 19:15:35 -0500 Subject: [PATCH 33/36] starting on tree tab (asset manager) --- lib/WebGUI/Admin.pm | 19 +- lib/WebGUI/Content/Admin.pm | 9 +- www/extras/admin/admin.js | 699 ++++++++++++++++++++---------------- 3 files changed, 412 insertions(+), 315 deletions(-) diff --git a/lib/WebGUI/Admin.pm b/lib/WebGUI/Admin.pm index d21283b55..0da88726b 100644 --- a/lib/WebGUI/Admin.pm +++ b/lib/WebGUI/Admin.pm @@ -273,6 +273,10 @@ sub www_view { $style->setLink( $url->extras('yui/build/button/assets/skins/sam/button.css'), {type=>"text/css",rel=>"stylesheet"}); $style->setLink( $url->extras('yui/build/menu/assets/skins/sam/menu.css'), {type=>"text/css",rel=>"stylesheet"}); $style->setLink( $url->extras('yui/build/tabview/assets/skins/sam/tabview.css'), {type=>"text/css",rel=>"stylesheet"}); + $style->setLink( $url->extras('yui/build/paginator/assets/skins/sam/paginator.css'), {rel=>'stylesheet', type=>'text/css'}); + $style->setLink( $url->extras('yui/build/datatable/assets/skins/sam/datatable.css'), {rel=>'stylesheet', type=>'text/css'}); + $style->setLink( $url->extras('yui/build/menu/assets/skins/sam/menu.css'), {rel=>'stylesheet', type=>'text/css'}); + $style->setLink( $url->extras('yui-webgui/build/assetManager/assetManager.css' ), { rel => "stylesheet", type => 'text/css' } ); $style->setLink( $url->extras('macro/AdminBar/slidePanel.css'), {type=>'text/css', rel=>'stylesheet'}); $style->setLink( $url->extras('admin/admin.css'), { type=>'text/css', rel=>'stylesheet'} ); $style->setScript($url->extras('yui/build/yahoo-dom-event/yahoo-dom-event.js'), {type=>'text/javascript'}); @@ -280,11 +284,17 @@ sub www_view { $style->setScript($url->extras('accordion/accordion.js'), {type=>'text/javascript'}); $style->setScript($url->extras('admin/admin.js'), {type=>'text/javascript'}); $style->setScript($url->extras('yui/build/element/element-min.js'), {type=>"text/javascript"}); + $style->setScript( $url->extras( 'yui/build/paginator/paginator-min.js ' ) ); + $style->setScript( $url->extras( 'yui/build/datasource/datasource-min.js ' ) ); + $style->setScript( $url->extras( 'yui/build/datatable/datatable-min.js ' ) ); + $style->setScript( $url->extras( 'yui/build/container/container-min.js' ) ); $style->setScript($url->extras('yui/build/tabview/tabview-min.js'), {type=>"text/javascript"}); - $style->setScript($url->extras('yui/build/container/container_core-min.js'), {type=>"text/javascript"}); $style->setScript($url->extras('yui/build/menu/menu-min.js'), {type=>"text/javascript"}); $style->setScript($url->extras('yui/build/button/button-min.js'), {type=>"text/javascript"}); + $style->setScript( $url->extras( 'yui/build/json/json-min.js' ) ); + $style->setScript( $url->extras( 'yui-webgui/build/i18n/i18n.js' ) ); + # Use the template in our __DATA__ block my $tmpl = WebGUI::Asset::Template::HTMLTemplate->new( $session ); @@ -346,7 +356,12 @@ __DATA__
-

Tab Two Content

+
+
+
+
+
+
diff --git a/lib/WebGUI/Content/Admin.pm b/lib/WebGUI/Content/Admin.pm index 1d830ac23..79bb973a9 100644 --- a/lib/WebGUI/Content/Admin.pm +++ b/lib/WebGUI/Content/Admin.pm @@ -53,7 +53,14 @@ sub handler { } else { my $admin = WebGUI::Admin->new( $session ); - return $admin->www_view; + my $method = $session->form->get('method') || "view"; + + if ( $admin->can( "www_" . $method ) ) { + return $admin->can( "www_" . $method )->($admin); + } + else { + return $admin->www_view; + } } } diff --git a/www/extras/admin/admin.js b/www/extras/admin/admin.js index af80cf597..fe66f64c6 100644 --- a/www/extras/admin/admin.js +++ b/www/extras/admin/admin.js @@ -7,11 +7,12 @@ if ( typeof WebGUI == "undefined" ) { WebGUI = {}; } -WebGUI.Admin = function(){ +WebGUI.Admin = function(cfg){ // Public properties this.cfg = cfg; this.currentAssetDef = null; - this.viewOrTree = 0; // 0 - Last on View tab. 1 - Last on Tree tab + this.currentTab = "view"; // "view" or "tree" or other ID + this.treeDirty = true; // Default configuration if ( !this.cfg.locationBarId ) { @@ -21,13 +22,30 @@ WebGUI.Admin = function(){ this.cfg.tabBarId = "tabBar"; } - this.locationBar = new WebGUI.Admin.LocationBar( this.cfg.locationBarId ); - this.tabBar = new YAHOO.widget.TabView( this.cfg.tabBarId ); - // Keep track of View and Tree tabs - this.tabBar.getTab(0).addListener('click',this.afterShowViewTab,this,true); - this.tabBar.getTab(1).addListener('click',this.afterShowTreeTab,this,true); - // Private methods + var self = this; + // Initialize these things AFTER the i18n is fetched + var _init = function () { + self.locationBar = new WebGUI.Admin.LocationBar( self.cfg.locationBarId ); + self.tree = new WebGUI.Admin.Tree(); + self.tabBar = new YAHOO.widget.TabView( self.cfg.tabBarId ); + // Keep track of View and Tree tabs + self.tabBar.getTab(0).addListener('click',self.afterShowViewTab,self,true); + self.tabBar.getTab(1).addListener('click',self.afterShowTreeTab,self,true); + }; + + // Get I18N + this.i18n = new WebGUI.i18n( { + namespaces : { + 'WebGUI' : [ '< prev', 'next >', 'locked by' ], + 'Asset' : [ 'rank', '99', 'type', 'revision date', 'size', 'locked', 'More', 'unlocked', 'edit' ] + }, + onpreload : { + fn : _init + } + } ); + + }; /** @@ -37,8 +55,12 @@ WebGUI.Admin = function(){ WebGUI.Admin.prototype.afterShowTreeTab = function () { // Refresh if necessary + if ( this.treeDirty ) { + this.tree.goto( this.currentAssetDef.url ); + this.treeDirty = 0; + } // Update last shown view/tree - this.viewOrTree = 1; + this.currentTab = "tree"; }; /** @@ -48,8 +70,12 @@ WebGUI.Admin.prototype.afterShowTreeTab WebGUI.Admin.prototype.afterShowViewTab = function () { // Refresh if necessary + if ( this.viewDirty ) { + window.frames[ "view" ].location.href = this.currentAssetDef.url; + this.viewDirty = 0; + } // Update last shown view/tree - this.viewOrTree = 0; + this.currentTab = "view"; }; /** @@ -64,7 +90,15 @@ WebGUI.Admin.prototype.afterShowViewTab */ WebGUI.Admin.prototype.gotoAsset = function ( url ) { - window.frames[ "view" ].location.href = url; + if ( this.currentTab == "view" ) { + window.frames[ "view" ].location.href = url; + this.treeDirty = 1; + } + else if ( this.currentTab == "tree" ) { + // Make tree request + this.tree.goto( this.currentAssetDef.url ); + this.viewDirty = 1; + } }; /** @@ -78,11 +112,17 @@ WebGUI.Admin.prototype.navigate if ( this.currentAssetDef && this.currentAssetDef.assetId == assetDef.assetId ) { return; } - + + // Defer until the locationBar is created + if ( !this.locationBar ) { + var self = this; // Scope correction + return setTimeout( function(){ self.navigate( assetDef ) }, 1000 ); + } + // Update the location bar this.locationBar.navigate( assetDef ); - // Mark the other frame dirty + this.currentAssetDef = assetDef; }; /**************************************************************************** @@ -373,266 +413,30 @@ WebGUI.Admin.LocationBar.prototype.swapForwardToBack * WebGUI.Admin.Tree */ -WebGUI.Admin.Tree = function(){ +WebGUI.Admin.Tree += function(){ this.moreMenusDisplayed = {}; this.crumbMoreMenu = null; -}; - -/** - * appendToUrl( url, params ) - * Add URL components to a URL; - */ -WebGUI.Admin.Tree.prototype.appendToUrl = function ( url, params ) { - var components = [ url ]; - if (url.match(/\?/)) { - components.push(";"); - } - else { - components.push("?"); - } - components.push(params); - return components.join(''); -}; - -/** - * addHighlightToRow ( child ) - * Highlight the row containing this element by adding to it the "highlight" - * class - */ -WebGUI.Admin.Tree.prototype.addHighlightToRow = function ( child ) { - var row = this.findRow( child ); - if ( !YAHOO.util.Dom.hasClass( row, "highlight" ) ) { - YAHOO.util.Dom.addClass( row, "highlight" ); - } -}; - -/** - * buildMoreMenu ( url, linkElement ) - * Build a WebGUI style "More" menu for the asset referred to by url - */ -WebGUI.AssetManager.buildMoreMenu = function ( url, linkElement, isNotLocked ) { - var rawItems = this.moreMenuItems; - var menuItems = []; - var isLocked = !isNotLocked; - for ( var i = 0; i < rawItems.length; i++ ) { - var itemUrl = rawItems[i].url - ? this.appendToUrl(url, rawItems[i].url) - : url - ; - if (! (itemUrl.match( /func=edit;/) && isLocked )) { - menuItems.push( { "url" : itemUrl, "text" : rawItems[i].label } ); - } - } - var options = { - "zindex" : 1000, - "clicktohide" : true, - "position" : "dynamic", - "context" : [ linkElement, "tl", "bl", ["beforeShow", "windowResize"] ], - "itemdata" : menuItems + this.defaultSortBy = { + "key" : "lineage", + "dir" : YAHOO.widget.DataTable.CLASS_ASC }; - return options; -}; - -/** - * findRow ( child ) - * Find the row that contains this child element. - */ -WebGUI.Admin.Tree.prototype.findRow = function ( child ) { - var node = child; - while ( node ) { - if ( node.tagName == "TR" ) { - return node; - } - node = node.parentNode; - } -}; - -/** - * formatActions ( ) - * Format the Edit and More links for the row - */ -WebGUI.AssetManager.formatActions = function ( elCell, oRecord, oColumn, orderNumber ) { - if ( oRecord.getData( 'actions' ) ) { - elCell.innerHTML - = '' - + WebGUI.AssetManager.i18n.get('Asset', 'edit') + '' - + ' | ' - ; - } - else { - elCell.innerHTML = ""; - } - var more = document.createElement( 'a' ); - elCell.appendChild( more ); - more.appendChild( document.createTextNode( WebGUI.AssetManager.i18n.get('Asset','More' ) ) ); - more.href = '#'; - - // Delete the old menu - if ( document.getElementById( 'moreMenu' + oRecord.getData( 'assetId' ) ) ) { - var oldMenu = document.getElementById( 'moreMenu' + oRecord.getData( 'assetId' ) ); - oldMenu.parentNode.removeChild( oldMenu ); - } - - var options = WebGUI.AssetManager.buildMoreMenu(oRecord.getData( 'url' ), more, oRecord.getData( 'actions' )); - - var menu = new YAHOO.widget.Menu( "moreMenu" + oRecord.getData( 'assetId' ), options ); - YAHOO.util.Event.onDOMReady( function () { menu.render( document.getElementById( 'assetManager' ) ); } ); - YAHOO.util.Event.addListener( more, "click", function (e) { YAHOO.util.Event.stopEvent(e); menu.show(); menu.focus(); }, null, menu ); -}; - -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.formatAssetIdCheckbox ( ) - Format the checkbox for the asset ID. -*/ -WebGUI.AssetManager.formatAssetIdCheckbox = function ( elCell, oRecord, oColumn, orderNumber ) { - elCell.innerHTML = ''; -}; - -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.formatAssetSize ( ) - Format the asset class name -*/ -WebGUI.AssetManager.formatAssetSize = function ( elCell, oRecord, oColumn, orderNumber ) { - elCell.innerHTML = oRecord.getData( "assetSize" ); -}; - -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.formatClassName ( ) - Format the asset class name -*/ -WebGUI.AssetManager.formatClassName = function ( elCell, oRecord, oColumn, orderNumber ) { - elCell.innerHTML = ' ' - + oRecord.getData( "className" ); -}; - -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.formatLockedBy ( ) - Format the asset class name -*/ -WebGUI.AssetManager.formatLockedBy = function ( elCell, oRecord, oColumn, orderNumber ) { - var extras = getWebguiProperty('extrasURL'); - elCell.innerHTML - = oRecord.getData( 'lockedBy' ) - ? '' - + '' + WebGUI.AssetManager.i18n.get('WebGUI', 'locked by') + ' ' + oRecord.getData( 'lockedBy' ) + '' - + '' - : '' - + '' + WebGUI.AssetManager.i18n.get('Asset', 'unlocked') + '' - + '' - ; -}; - -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.formatRank ( ) - Format the input for the rank box -*/ -WebGUI.AssetManager.formatRank = function ( elCell, oRecord, oColumn, orderNumber ) { - var rank = oRecord.getData("lineage").match(/[1-9][0-9]{0,5}$/); - elCell.innerHTML = ''; -}; - - -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.DefaultSortedBy ( ) -*/ -WebGUI.AssetManager.DefaultSortedBy = { - "key" : "lineage", - "dir" : YAHOO.widget.DataTable.CLASS_ASC -}; - -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.BuildQueryString ( ) -*/ -WebGUI.AssetManager.BuildQueryString = function ( state, dt ) { - var query = "recordOffset=" + state.pagination.recordOffset - + ';orderByDirection=' + ((state.sortedBy.dir === YAHOO.widget.DataTable.CLASS_DESC) ? "DESC" : "ASC") - + ';rowsPerPage=' + state.pagination.rowsPerPage - + ';orderByColumn=' + state.sortedBy.key - ; - return query; - }; - -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.formatRevisionDate ( ) - Format the asset class name -*/ -WebGUI.AssetManager.formatRevisionDate = function ( elCell, oRecord, oColumn, orderNumber ) { - var revisionDate = new Date( oRecord.getData( "revisionDate" ) * 1000 ); - var minutes = revisionDate.getMinutes(); - if (minutes < 10) { - minutes = "0" + minutes; - } - elCell.innerHTML = revisionDate.getFullYear() + '-' + ( revisionDate.getMonth() + 1 ) - + '-' + revisionDate.getDate() + ' ' + ( revisionDate.getHours() ) - + ':' + minutes - ; -}; - -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.formatTitle ( ) - Format the link for the title -*/ -WebGUI.AssetManager.formatTitle = function ( elCell, oRecord, oColumn, orderNumber ) { - elCell.innerHTML = '' - + ( oRecord.getData( 'childCount' ) > 0 ? "+" : " " ) - + ' ' - + oRecord.getData( 'title' ) - + '' - ; -}; - -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.initManager ( ) - Initialize the i18n interface -*/ -WebGUI.AssetManager.initManager = function (o) { - WebGUI.AssetManager.i18n - = new WebGUI.i18n( { - namespaces : { - 'Asset' : [ - "edit", - "More", - "unlocked", - "locked by" - ], - 'WebGUI' : [ - "< prev", - "next >" - ] - }, - onpreload : { - fn : WebGUI.AssetManager.initDataTable - } - } ); -}; - -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.initDataTable ( ) - Initialize the www_manage page -*/ -WebGUI.AssetManager.initDataTable = function (o) { var assetPaginator = new YAHOO.widget.Paginator({ - containers : ['pagination'], + containers : ['treePagination'], pageLinks : 7, rowsPerPage : 100, - previousPageLinkLabel : WebGUI.AssetManager.i18n.get('WebGUI', '< prev'), - nextPageLinkLabel : WebGUI.AssetManager.i18n.get('WebGUI', 'next >'), + previousPageLinkLabel : window.admin.i18n.get('WebGUI', '< prev'), + nextPageLinkLabel : window.admin.i18n.get('WebGUI', 'next >'), template : "{CurrentPageReport} {PreviousPageLink} {PageLinks} {NextPageLink}" }); - // initialize the data source - WebGUI.AssetManager.DataSource - = new YAHOO.util.DataSource( '?op=assetManager;method=ajaxGetManagerPage;',{connTimeout:30000} ); - WebGUI.AssetManager.DataSource.responseType + this.dataSource + = new YAHOO.util.DataSource( '?op=admin;method=getTreeData;', {connTimeout:30000} ); + this.dataSource.responseType = YAHOO.util.DataSource.TYPE_JSON; - WebGUI.AssetManager.DataSource.responseSchema + this.dataSource.responseSchema = { resultsList: 'assets', fields: [ @@ -653,49 +457,319 @@ WebGUI.AssetManager.initDataTable = function (o) { } }; - + this.columnDefs + = [ + { key: 'assetId', label: 'Select All Button', formatter: this.formatAssetIdCheckbox }, + { key: 'lineage', label: window.admin.i18n.get('Asset','rank'), sortable: true, formatter: this.formatRank }, + { key: 'actions', label: "", formatter: this.formatActions }, + { key: 'title', label: window.admin.i18n.get('Asset', '99'), formatter: this.formatTitle, sortable: true }, + { key: 'className', label: window.admin.i18n.get('Asset','type'), sortable: true, formatter: this.formatClassName }, + { key: 'revisionDate', label: window.admin.i18n.get('Asset','revision date' ), formatter: this.formatRevisionDate, sortable: true }, + { key: 'assetSize', label: window.admin.i18n.get('Asset','size' ), formatter: this.formatAssetSize, sortable: true }, + { key: 'lockedBy', label: window.admin.i18n.get('Asset','locked' ), formatter: this.formatLockedBy } + ]; // Initialize the data table - WebGUI.AssetManager.DataTable - = new YAHOO.widget.DataTable( 'dataTableContainer', - WebGUI.AssetManager.ColumnDefs, - WebGUI.AssetManager.DataSource, + this.dataTable + = new YAHOO.widget.DataTable( 'treeDataTableContainer', + this.columnDefs, + this.dataSource, { - initialRequest : 'recordOffset=0', + initialLoad : false, dynamicData : true, paginator : assetPaginator, - sortedBy : WebGUI.AssetManager.DefaultSortedBy, - generateRequest : WebGUI.AssetManager.BuildQueryString + sortedBy : this.defaultSortedBy, + generateRequest : this.buildQueryString } ); + // Save the Tree + this.dataTable.tree = this; - WebGUI.AssetManager.DataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) { - oPayload.totalRecords = oResponse.meta.totalRecords; - return oPayload; - }; + this.dataTable.handleDataReturnPayload + = function(oRequest, oResponse, oPayload) { + oPayload.totalRecords = oResponse.meta.totalRecords; + return oPayload; + }; }; -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.removeHighlightFromRow ( child ) - Remove the highlight from a row by removing the "highlight" class. -*/ -WebGUI.AssetManager.removeHighlightFromRow = function ( child ) { - var row = WebGUI.AssetManager.findRow( child ); +/** + * appendToUrl( url, params ) + * Add URL components to a URL; + */ +appendToUrl += function ( url, params ) { + var components = [ url ]; + if (url.match(/\?/)) { + components.push(";"); + } + else { + components.push("?"); + } + components.push(params); + return components.join(''); +}; + +/** + * addHighlightToRow ( child ) + * Highlight the row containing this element by adding to it the "highlight" + * class + */ +WebGUI.Admin.Tree.prototype.addHighlightToRow += function ( child ) { + var row = this.findRow( child ); + if ( !YAHOO.util.Dom.hasClass( row, "highlight" ) ) { + YAHOO.util.Dom.addClass( row, "highlight" ); + } +}; + +/** + * buildMoreMenu ( url, linkElement ) + * Build a WebGUI style "More" menu for the asset referred to by url + */ +WebGUI.Admin.Tree.prototype.buildMoreMenu += function ( url, linkElement, isNotLocked ) { + var rawItems = this.moreMenuItems; + var menuItems = []; + var isLocked = !isNotLocked; + for ( var i = 0; i < rawItems.length; i++ ) { + var itemUrl = rawItems[i].url + ? appendToUrl(url, rawItems[i].url) + : url + ; + if (! (itemUrl.match( /func=edit;/) && isLocked )) { + menuItems.push( { "url" : itemUrl, "text" : rawItems[i].label } ); + } + } + var options = { + "zindex" : 1000, + "clicktohide" : true, + "position" : "dynamic", + "context" : [ linkElement, "tl", "bl", ["beforeShow", "windowResize"] ], + "itemdata" : menuItems + }; + + return options; +}; + +/** + * buildQueryString ( ) + * Build a query string + */ +WebGUI.Admin.Tree.prototype.buildQueryString += function ( state, dt, newUrl ) { + var assetUrl; + if ( !newUrl ) { + assetUrl = window.admin.currentAssetDef.url; + } + else { + assetUrl = newUrl; + } + + var recordOffset = state.pagination ? state.pagination.recordOffset : 0; + var rowsPerPage = state.pagination ? state.pagination.rowsPerPage : 0; + var orderByColumn = state.sortedBy ? state.sortedBy.key : "lineage"; + var orderByDir = state.sortedBy + ? ( (state.sortedBy.dir === YAHOO.widget.DataTable.CLASS_DESC) ? "DESC" : "ASC" ) + : "ASC" + ; + + var query = "assetUrl=" + assetUrl + + ";recordOffset=" + recordOffset + + ';orderByDirection=' + orderByDir + + ';rowsPerPage=' + rowsPerPage + + ';orderByColumn=' + orderByColumn + ; + + return query; +}; + +/** + * findRow ( child ) + * Find the row that contains this child element. + */ +WebGUI.Admin.Tree.prototype.findRow += function ( child ) { + var node = child; + while ( node ) { + if ( node.tagName == "TR" ) { + return node; + } + node = node.parentNode; + } +}; + +/** + * formatActions ( ) + * Format the Edit and More links for the row + */ +WebGUI.Admin.Tree.prototype.formatActions += function ( elCell, oRecord, oColumn, orderNumber ) { + if ( oRecord.getData( 'actions' ) ) { + elCell.innerHTML + = '' + + window.admin.i18n.get('Asset', 'edit') + '' + + ' | ' + ; + } + else { + elCell.innerHTML = ""; + } + return; // TODO + var more = document.createElement( 'a' ); + elCell.appendChild( more ); + more.appendChild( document.createTextNode( window.admin.i18n.get('Asset','More' ) ) ); + more.href = '#'; + + // Delete the old menu + if ( document.getElementById( 'moreMenu' + oRecord.getData( 'assetId' ) ) ) { + var oldMenu = document.getElementById( 'moreMenu' + oRecord.getData( 'assetId' ) ); + oldMenu.parentNode.removeChild( oldMenu ); + } + + var options = this.buildMoreMenu(oRecord.getData( 'url' ), more, oRecord.getData( 'actions' )); + + var menu = new YAHOO.widget.Menu( "moreMenu" + oRecord.getData( 'assetId' ), options ); + YAHOO.util.Event.onDOMReady( function () { menu.render( document.getElementById( 'assetManager' ) ); } ); + YAHOO.util.Event.addListener( more, "click", function (e) { YAHOO.util.Event.stopEvent(e); menu.show(); menu.focus(); }, null, menu ); +}; + +/** + * formatAssetIdCheckbox ( ) + * Format the checkbox for the asset ID. + */ +WebGUI.Admin.Tree.prototype.formatAssetIdCheckbox += function ( elCell, oRecord, oColumn, orderNumber ) { + elCell.innerHTML = ''; + // TODO: Add onchange handler to toggle checkbox +}; + +/** + * formatAssetSize ( ) + * Format the asset class name + */ +WebGUI.Admin.Tree.prototype.formatAssetSize += function ( elCell, oRecord, oColumn, orderNumber ) { + elCell.innerHTML = oRecord.getData( "assetSize" ); +}; + +/** + * formatClassName ( ) + * Format the asset class name + */ +WebGUI.Admin.Tree.prototype.formatClassName += function ( elCell, oRecord, oColumn, orderNumber ) { + elCell.innerHTML = ' ' + + oRecord.getData( "className" ); +}; + +/** + * formatLockedBy ( ) + * Format the locked icon + */ +WebGUI.Admin.Tree.prototype.formatLockedBy += function ( elCell, oRecord, oColumn, orderNumber ) { + var extras = getWebguiProperty('extrasURL'); + elCell.innerHTML + = oRecord.getData( 'lockedBy' ) + ? '' + + '' + window.admin.i18n.get('WebGUI', 'locked by') + ' ' + oRecord.getData( 'lockedBy' ) + '' + + '' + : '' + + '' + window.admin.i18n.get('Asset', 'unlocked') + '' + + '' + ; +}; + +/** + * formatRank ( ) + * Format the input for the rank box + */ +WebGUI.Admin.Tree.prototype.formatRank += function ( elCell, oRecord, oColumn, orderNumber ) { + var rank = oRecord.getData("lineage").match(/[1-9][0-9]{0,5}$/); + elCell.innerHTML = ''; + // TODO: Add onchange handler to select row +}; + +/** + * formatRevisionDate ( ) + * Format the asset class name + */ +WebGUI.Admin.Tree.prototype.formatRevisionDate += function ( elCell, oRecord, oColumn, orderNumber ) { + var revisionDate = new Date( oRecord.getData( "revisionDate" ) * 1000 ); + var minutes = revisionDate.getMinutes(); + if (minutes < 10) { + minutes = "0" + minutes; + } + elCell.innerHTML + = revisionDate.getFullYear() + '-' + ( revisionDate.getMonth() + 1 ) + + '-' + revisionDate.getDate() + ' ' + ( revisionDate.getHours() ) + + ':' + minutes + ; +}; + +/** + * formatTitle ( ) + * Format the link for the title + */ +WebGUI.Admin.Tree.prototype.formatTitle += function ( elCell, oRecord, oColumn, orderNumber ) { + elCell.innerHTML = '' + + ( oRecord.getData( 'childCount' ) > 0 ? "+" : " " ) + + ' ' + + oRecord.getData( 'title' ) + + '' + ; +}; + +WebGUI.Admin.Tree.prototype.goto += function ( assetUrl ) { + var callback = { + success : this.dataTable.onDataReturnInitializeTable, + failure : this.dataTable.onDataReturnInitializeTable, + scope : this.dataTable, + argument: this.dataTable.getState() + }; + + this.dataSource.sendRequest( + this.buildQueryString( + this.dataTable.getState(), + this.dataTable, + assetUrl + ), + callback + ); +}; + +/** + * removeHighlightFromRow ( child ) + * Remove the highlight from a row by removing the "highlight" class. + */ +WebGUI.Admin.Tree.prototype.removeHighlightFromRow += function ( child ) { + var row = this.findRow( child ); if ( YAHOO.util.Dom.hasClass( row, "highlight" ) ) { YAHOO.util.Dom.removeClass( row, "highlight" ); } }; -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.selectRow ( child ) - Check the assetId checkbox in the row that contains the given child. - Used when something in the row changes. -*/ -WebGUI.AssetManager.selectRow = function ( child ) { +/** + * selectRow ( child ) + * Check the assetId checkbox in the row that contains the given child. + * Used when something in the row changes. + */ +WebGUI.Admin.Tree.prototype.selectRow += function ( child ) { // First find the row - var node = WebGUI.AssetManager.findRow( child ); - WebGUI.AssetManager.addHighlightToRow( child ); + var node = this.findRow( child ); + this.addHighlightToRow( child ); // Now find the assetId checkbox in the first element var inputs = node.getElementsByTagName( "input" ); @@ -707,48 +781,49 @@ WebGUI.AssetManager.selectRow = function ( child ) { } }; -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.showMoreMenu ( url, linkTextId ) - Build a More menu for the last element of the Crumb trail -*/ -WebGUI.AssetManager.showMoreMenu +/** + * showMoreMenu ( url, linkTextId ) + * Build a More menu for the last element of the Crumb trail + */ +WebGUI.Admin.Tree.prototype.showMoreMenu = function ( url, linkTextId, isNotLocked ) { - + return; // TODO var menu; - if ( typeof WebGUI.AssetManager.CrumbMoreMenu == "undefined" ) { + if ( typeof this.crumbMoreMenu == "undefined" ) { var more = document.getElementById(linkTextId); - var options = WebGUI.AssetManager.buildMoreMenu(url, more, isNotLocked); + var options = this.buildMoreMenu(url, more, isNotLocked); menu = new YAHOO.widget.Menu( "crumbMoreMenu", options ); menu.render( document.getElementById( 'assetManager' ) ); - WebGUI.AssetManager.CrumbMoreMenu = menu; + this.crumbMoreMenu = menu; } else { - menu = WebGUI.AssetManager.CrumbMoreMenu; + menu = this.crumbMoreMenu; } menu.show(); menu.focus(); }; -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.toggleHighlightForRow ( checkbox ) - Toggle the highlight for the row based on the state of the checkbox -*/ -WebGUI.AssetManager.toggleHighlightForRow = function ( checkbox ) { +/** + * toggleHighlightForRow ( checkbox ) + * Toggle the highlight for the row based on the state of the checkbox + */ +WebGUI.Admin.Tree.prototype.toggleHighlightForRow += function ( checkbox ) { if ( checkbox.checked ) { - WebGUI.AssetManager.addHighlightToRow( checkbox ); + this.addHighlightToRow( checkbox ); } else { - WebGUI.AssetManager.removeHighlightFromRow( checkbox ); + this.removeHighlightFromRow( checkbox ); } }; -/*--------------------------------------------------------------------------- - WebGUI.AssetManager.toggleRow ( child ) - Toggles the entire row by finding the checkbox and doing what needs to be - done. -*/ -WebGUI.AssetManager.toggleRow = function ( child ) { - var row = WebGUI.AssetManager.findRow( child ); +/** + * toggleRow ( child ) + * Toggles the entire row by finding the checkbox and doing what needs to be + * done. + */ +WebGUI.Admin.Tree.prototype.toggleRow = function ( child ) { + var row = this.findRow( child ); // Find the checkbox var inputs = row.getElementsByTagName( "input" ); @@ -758,7 +833,7 @@ WebGUI.AssetManager.toggleRow = function ( child ) { ? false : true ; - WebGUI.AssetManager.toggleHighlightForRow( inputs[i] ); + this.toggleHighlightForRow( inputs[i] ); break; } } From a9ff59d7b2ff91cd736f7dbfa9ec73d444f75a92 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Wed, 21 Apr 2010 11:20:22 -0500 Subject: [PATCH 34/36] started asset helpers --- lib/WebGUI/Admin.pm | 17 +++++++++++++---- lib/WebGUI/Asset.pm | 28 ++++++++++++++++++++++++++++ www/extras/admin/admin.js | 20 +++++++++++++++----- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/lib/WebGUI/Admin.pm b/lib/WebGUI/Admin.pm index 0da88726b..1484da1fd 100644 --- a/lib/WebGUI/Admin.pm +++ b/lib/WebGUI/Admin.pm @@ -210,6 +210,7 @@ sub www_getTreeData { assetSize => $asset->assetSize, lockedBy => ($asset->isLockedBy ? $asset->lockedBy->username : ''), actions => $asset->canEdit && $asset->canEditIfLocked, + helpers => $asset->getHelpers, ); $fields{ className } = {}; @@ -225,6 +226,15 @@ sub www_getTreeData { $assetInfo->{ totalAssets } = $p->getRowCount; $assetInfo->{ sort } = $session->form->get( 'orderByColumn' ); $assetInfo->{ dir } = lc $session->form->get( 'orderByDirection' ); + $assetInfo->{ currentAsset } = { title => $asset->getTitle, helpers => $asset->getHelpers }; + + $assetInfo->{ crumbtrail } = []; + for my $asset ( @{ $asset->getLineage( ['ancestors'], { returnObjects => 1 } ) } ) { + push @{ $assetInfo->{crumbtrail} }, { + title => $asset->getTitle, + url => $asset->getUrl + }; + } $session->http->setMimeType( 'application/json' ); @@ -357,10 +367,9 @@ __DATA__
-
-
-
-
+
+
+
diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 7fefbd645..3d9ae1fad 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1172,6 +1172,34 @@ sub getExtraHeadTags { ; } +#---------------------------------------------------------------------------- + +=head2 getHelpers ( ) + +Get the AssetHelpers for this asset. + +=cut + +sub getHelpers { + my ( $self ) = @_; + + my $default = [ + { + class => 'WebGUI::AssetHelper::EditBranch', + label => 'Edit Branch', + }, + { + url => $self->getUrl( 'func=edit' ), + label => 'Edit', + }, + { + url => $self->getUrl( 'func=view' ), + label => 'View', + }, + ]; + + return $default; +} #------------------------------------------------------------------- diff --git a/www/extras/admin/admin.js b/www/extras/admin/admin.js index fe66f64c6..71928eef7 100644 --- a/www/extras/admin/admin.js +++ b/www/extras/admin/admin.js @@ -723,18 +723,18 @@ WebGUI.Admin.Tree.prototype.formatTitle = function ( elCell, oRecord, oColumn, orderNumber ) { elCell.innerHTML = '' + ( oRecord.getData( 'childCount' ) > 0 ? "+" : " " ) - + ' ' + + ' ' + oRecord.getData( 'title' ) - + '' + + '' ; }; WebGUI.Admin.Tree.prototype.goto = function ( assetUrl ) { var callback = { - success : this.dataTable.onDataReturnInitializeTable, - failure : this.dataTable.onDataReturnInitializeTable, - scope : this.dataTable, + success : this.onDataReturnInitializeTable, + failure : this.onDataReturnInitializeTable, + scope : this, argument: this.dataTable.getState() }; @@ -748,6 +748,16 @@ WebGUI.Admin.Tree.prototype.goto ); }; +/** + * onDataReturnInitializeTable ( sRequest, oResponse, oPayload ) + * Initialize the table with a new response from the server + */ +WebGUI.Admin.Tree.prototype.onDataReturnInitializeTable += function ( sRequest, oResponse, oPayload ) { + this.dataTable.onDataReturnInitializeTable.call( this.dataTable, sRequest, oResponse, oPayload ); + +}; + /** * removeHighlightFromRow ( child ) * Remove the highlight from a row by removing the "highlight" class. From 69a7e172a5662977160ba77bc3e7d8a59c707e27 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Wed, 21 Apr 2010 12:06:18 -0500 Subject: [PATCH 35/36] fix varname in operation/statistics --- lib/WebGUI/Operation/Statistics.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WebGUI/Operation/Statistics.pm b/lib/WebGUI/Operation/Statistics.pm index 659ecb458..7511f3ff9 100644 --- a/lib/WebGUI/Operation/Statistics.pm +++ b/lib/WebGUI/Operation/Statistics.pm @@ -186,7 +186,7 @@ sub www_viewStatistics { # Get the latest WebGUI version my $url = "http://update.webgui.org/latest-version.txt"; my $cache = $session->cache; - my $value = $cache->compute( $url, sub { + my $version = $cache->compute( $url, sub { my $ua = LWP::UserAgent->new( env_proxy => 1, agent => "WebGUI/" . $WebGUI::VERSION, From beb2f2cf59551c341e5153a2bed0b8df18319266 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Wed, 21 Apr 2010 12:40:50 -0500 Subject: [PATCH 36/36] set a root_dir so forked servers use same cache --- var/upgrades/upgrade_7.9.3-8.0.0.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/var/upgrades/upgrade_7.9.3-8.0.0.pl b/var/upgrades/upgrade_7.9.3-8.0.0.pl index ce8f29cbe..ef8bf701b 100644 --- a/var/upgrades/upgrade_7.9.3-8.0.0.pl +++ b/var/upgrades/upgrade_7.9.3-8.0.0.pl @@ -43,6 +43,7 @@ sub migrateToNewCache { $config->set("cache", { "driver" => "FastMmap", "expires_variance" => "0.10", + "root_dir" => "/tmp/WebGUICache", }); $config->set("hotSessionFlushToDb", 600); $config->delete("disableCache");
'.$i18n->get(145).':'.$WebGUI::VERSION.'-'.$WebGUI::STATUS.'