From 247c607393773f899a7217c7c88c7e8930720bcf Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Tue, 1 Jun 2010 19:37:53 -0500 Subject: [PATCH] fixes for weaken and iterator --- lib/WebGUI/Asset/Wobject/Collaboration.pm | 12 +++++-- lib/WebGUI/Asset/Wobject/Dashboard.pm | 4 +-- lib/WebGUI/Asset/Wobject/Folder.pm | 4 +-- lib/WebGUI/Asset/Wobject/Gallery.pm | 3 +- lib/WebGUI/Asset/Wobject/Layout.pm | 4 +-- lib/WebGUI/Asset/Wobject/Matrix.pm | 2 +- lib/WebGUI/Asset/Wobject/MessageBoard.pm | 2 +- lib/WebGUI/Asset/Wobject/Navigation.pm | 2 +- lib/WebGUI/Asset/Wobject/StoryArchive.pm | 2 +- lib/WebGUI/Asset/Wobject/WikiMaster.pm | 4 +-- lib/WebGUI/AssetBranch.pm | 2 +- lib/WebGUI/AssetExportHtml.pm | 8 ++--- lib/WebGUI/AssetLineage.pm | 32 +++++++++++++------ lib/WebGUI/AssetPackage.pm | 11 +++++-- lib/WebGUI/AssetTrash.pm | 11 +++++-- lib/WebGUI/Config.pm | 2 +- lib/WebGUI/Form/SelectRichEditor.pm | 2 +- lib/WebGUI/Session.pm | 3 +- .../Workflow/Activity/CleanTempStorage.pm | 2 +- .../Workflow/Activity/ProcessEMSApprovals.pm | 2 ++ t/Asset/Wobject/Survey.t | 14 ++++---- t/Search/Index.t | 2 +- 22 files changed, 83 insertions(+), 47 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index 0283f1de4..eca2318af 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -27,13 +27,19 @@ use base qw(WebGUI::AssetAspect::RssFeed WebGUI::Asset::Wobject); #------------------------------------------------------------------- sub _computePostCount { my $self = shift; - return $self->getDescendantCount({includeOnlyClasses => ['WebGUI::Asset::Post']}); + return $self->getDescendantCount({ + includeOnlyClasses => ['WebGUI::Asset::Post'], + statusToInclude => ['approved'], + }); } #------------------------------------------------------------------- sub _computeThreadCount { my $self = shift; - return $self->getChildCount({includeOnlyClasses => ['WebGUI::Asset::Post::Thread']}); + return $self->getChildCount({ + includeOnlyClasses => ['WebGUI::Asset::Post::Thread'], + statusToInclude => ['approved'], + }); } #------------------------------------------------------------------- @@ -1392,7 +1398,7 @@ sub processPropertiesFromFormPost { my $descendant; eval { $descendant = $descendantIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $descendant; diff --git a/lib/WebGUI/Asset/Wobject/Dashboard.pm b/lib/WebGUI/Asset/Wobject/Dashboard.pm index 4affa91e3..0e49358df 100644 --- a/lib/WebGUI/Asset/Wobject/Dashboard.pm +++ b/lib/WebGUI/Asset/Wobject/Dashboard.pm @@ -195,7 +195,7 @@ sub getEditForm { my $child; eval { $child = $childIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $child; @@ -268,7 +268,7 @@ sub prepareView { my $child; eval { $child = $childIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $child; diff --git a/lib/WebGUI/Asset/Wobject/Folder.pm b/lib/WebGUI/Asset/Wobject/Folder.pm index 9b3ae43bf..bc63e3ebe 100644 --- a/lib/WebGUI/Asset/Wobject/Folder.pm +++ b/lib/WebGUI/Asset/Wobject/Folder.pm @@ -127,7 +127,7 @@ sub getContentLastModified { my $child; eval { $child = $childIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $child; @@ -254,7 +254,7 @@ sub view { my $child; eval { $child = $childIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $child; diff --git a/lib/WebGUI/Asset/Wobject/Gallery.pm b/lib/WebGUI/Asset/Wobject/Gallery.pm index 3b70ab365..a6000653e 100644 --- a/lib/WebGUI/Asset/Wobject/Gallery.pm +++ b/lib/WebGUI/Asset/Wobject/Gallery.pm @@ -32,6 +32,7 @@ use XML::Simple; =head1 DIAGNOSTICS =head1 METHODS + =cut #------------------------------------------------------------------- @@ -937,7 +938,7 @@ sub hasSpaceAvailable { my $file; eval { $file = $fileIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $file; diff --git a/lib/WebGUI/Asset/Wobject/Layout.pm b/lib/WebGUI/Asset/Wobject/Layout.pm index fb176ca0d..5dea30c8b 100644 --- a/lib/WebGUI/Asset/Wobject/Layout.pm +++ b/lib/WebGUI/Asset/Wobject/Layout.pm @@ -186,7 +186,7 @@ sub getEditForm { my $child; eval { $child = $childIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $child; @@ -431,7 +431,7 @@ sub getContentLastModified { my $child; eval { $child = $childIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $child; diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index dd56adace..e82078980 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -322,7 +322,7 @@ sub deleteAttribute { my $listing; eval { $listing = $listingIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $listing; diff --git a/lib/WebGUI/Asset/Wobject/MessageBoard.pm b/lib/WebGUI/Asset/Wobject/MessageBoard.pm index 02d81259d..7e4ee95dd 100644 --- a/lib/WebGUI/Asset/Wobject/MessageBoard.pm +++ b/lib/WebGUI/Asset/Wobject/MessageBoard.pm @@ -119,7 +119,7 @@ sub view { my $child; eval { $child = $childIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $child; diff --git a/lib/WebGUI/Asset/Wobject/Navigation.pm b/lib/WebGUI/Asset/Wobject/Navigation.pm index cf4d991d7..19c13a0da 100644 --- a/lib/WebGUI/Asset/Wobject/Navigation.pm +++ b/lib/WebGUI/Asset/Wobject/Navigation.pm @@ -381,6 +381,7 @@ sub view { $current = WebGUI::Asset->getDefault($self->session); } + my @interestingProperties = ('assetId', 'parentId', 'ownerUserId', 'synopsis', 'newWindow'); # Add properties from current asset foreach my $property (@interestingProperties) { $var->{'currentPage.'.$property} = $current->get($property); @@ -411,7 +412,6 @@ sub view { $rules{assetToPedigree} = $current if (isIn("pedigree",@includedRelationships)); $rules{ancestorLimit} = $self->get("ancestorEndPoint"); $rules{orderByClause} = 'rpad(asset.lineage, 255, 9) desc' if ($self->get('reversePageLoop')); - my @interestingProperties = ('assetId', 'parentId', 'ownerUserId', 'synopsis', 'newWindow'); my $assets = $start->getLineage(\@includedRelationships,\%rules); my $currentLineage = $current->get("lineage"); my $lineageToSkip = "noskip"; diff --git a/lib/WebGUI/Asset/Wobject/StoryArchive.pm b/lib/WebGUI/Asset/Wobject/StoryArchive.pm index bd80bcc77..4e966d5d6 100644 --- a/lib/WebGUI/Asset/Wobject/StoryArchive.pm +++ b/lib/WebGUI/Asset/Wobject/StoryArchive.pm @@ -411,7 +411,7 @@ sub getRssFeedItems { my $story; eval { $story = $storyIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $story; diff --git a/lib/WebGUI/Asset/Wobject/WikiMaster.pm b/lib/WebGUI/Asset/Wobject/WikiMaster.pm index b866a4c73..aa34072e4 100644 --- a/lib/WebGUI/Asset/Wobject/WikiMaster.pm +++ b/lib/WebGUI/Asset/Wobject/WikiMaster.pm @@ -84,7 +84,7 @@ sub appendMostPopular { my $asset; eval { $asset = $assetIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $asset; @@ -744,7 +744,7 @@ sub processPropertiesFromFormPost { my $child; eval { $child = $childIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $child; diff --git a/lib/WebGUI/AssetBranch.pm b/lib/WebGUI/AssetBranch.pm index 9800837d4..f13a13daf 100644 --- a/lib/WebGUI/AssetBranch.pm +++ b/lib/WebGUI/AssetBranch.pm @@ -62,7 +62,7 @@ sub duplicateBranch { my $child; eval { $child = $childIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $child; diff --git a/lib/WebGUI/AssetExportHtml.pm b/lib/WebGUI/AssetExportHtml.pm index 1408cd078..4c065af0f 100644 --- a/lib/WebGUI/AssetExportHtml.pm +++ b/lib/WebGUI/AssetExportHtml.pm @@ -452,7 +452,7 @@ sub exportCheckExportable { my $self = shift; # We have ourself already, check it first - return 0 unless $asset->get('isExportable'); + return 0 unless $self->get('isExportable'); # get this asset's ancestors. return objects as a shortcut since we'd be # instantiating them all anyway. @@ -464,7 +464,7 @@ sub exportCheckExportable { my $asset; eval { $asset = $assetIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $asset; @@ -553,8 +553,8 @@ sub exportGetDescendants { orderByClause => 'assetData.url DESC', } ); - use Data::Dumper; - warn "Assets: " . scalar( @$assetIds ); + #use Data::Dumper; + #warn "Assets: " . scalar( @$assetIds ); return $assetIds; } diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index 804823a41..49acf0283 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -226,17 +226,24 @@ only those that are published or achived are counted. Only count these classes. Arrayref of class names +=head4 statusToInclude + +Arrayref of status to include =cut sub getChildCount { my $self = shift; - my $opts = shift || {}; + my $opt = shift || {}; + $opt->{ statusToInclude } ||= [ 'approved', 'archived' ]; + + my $db = $self->session->db; my $sql = "select count(distinct asset.assetId) from asset, assetData where asset.assetId=assetData.assetId and parentId=? - and (assetData.status in ('approved', 'archived') or assetData.tagId=?)"; + and (assetData.status in (" . $db->quoteAndJoin( $opt->{statusToInclude} ) . ") + or assetData.tagId=?)"; my @params = ( $self->getId, $self->session->scratch->get('versionTag') ); if ( !$opt->{ includeTrash } ) { @@ -255,7 +262,7 @@ sub getChildCount { $sql .= "AND className IN (" . join( ',', ("?") x @classes ) . ")"; push @params, @classes; } - my ($count) = $self->session->db->quickArray($sql, \@params); + my $count = $self->session->db->quickScalar($sql, \@params); return $count; } @@ -272,19 +279,27 @@ in the clipboard or trash. Only count these classes. Arrayref of class names +=head4 statusToInclude + +Arrayref of status to include + =cut sub getDescendantCount { my $self = shift; my $opt = shift || {}; - + $opt->{ statusToInclude } ||= [ 'approved', 'archived' ]; + + my $db = $self->session->db; + my $sql = "select count(distinct asset.assetId) from asset, assetData where asset.assetId = assetData.assetId + and asset.assetId != ? and asset.state = 'published' - and assetData.status in ('approved','archived') + and assetData.status in (" . $db->quoteAndJoin( $opt->{statusToInclude} ) . ") and asset.lineage like ? "; - my @params = ( $self->get("lineage")."%" ); + my @params = ( $self->getId, $self->get("lineage")."%" ); # XXX This code is duplicated in getLineageSql and getChildCount. Merge the three ways? if ( $opt->{includeOnlyClasses} ) { @@ -299,8 +314,7 @@ sub getDescendantCount { push @params, @classes; } - my ($count) = $self->session->db->quickArray($sql, \@params); - $count--; # have to subtract self + my $count = $self->session->db->quickScalar($sql, \@params); return $count; } @@ -990,7 +1004,7 @@ sub setRank { my $sibling; eval { $sibling = $siblingIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $sibling; diff --git a/lib/WebGUI/AssetPackage.pm b/lib/WebGUI/AssetPackage.pm index a99e08a0f..a354580bc 100644 --- a/lib/WebGUI/AssetPackage.pm +++ b/lib/WebGUI/AssetPackage.pm @@ -63,8 +63,15 @@ Turns this package into a package file and returns the storage location object o sub exportPackage { my $self = shift; my $storage = WebGUI::Storage->createTemp($self->session); - my $assets = $self->getLineage(["self","descendants"],{statusToInclude=>['approved', 'archived']}) - while ( my $asset = $assets->() ) { + my $assetIter = $self->getLineageIterator(["self","descendants"],{statusToInclude=>['approved', 'archived']}); + while ( 1 ) { + my $asset; + eval { $asset = $assetIter->() }; + if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { + $self->session->log->error($x->full_message); + next; + } + last unless $asset; my $data = $asset->exportAssetData; $storage->addFileFromScalar($data->{properties}{lineage}.".json", JSON->new->utf8->pretty->encode($data)); foreach my $storageId (@{$data->{storage}}) { diff --git a/lib/WebGUI/AssetTrash.pm b/lib/WebGUI/AssetTrash.pm index 699549289..8419f5794 100644 --- a/lib/WebGUI/AssetTrash.pm +++ b/lib/WebGUI/AssetTrash.pm @@ -265,8 +265,15 @@ sub trash { return undef; } - my $assets = $self->getLineage(['self','descendants']); - while ( my $asset = $assets->() ) { + my $assetIter = $self->getLineageIterator(['self','descendants']); + while ( 1 ) { + my $asset; + eval { $asset = $assetIter->() }; + if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { + $session->log->error($x->full_message); + next; + } + last unless $asset; $outputSub->($i18n->get('Clearing search index')); my $index = WebGUI::Search::Index->new($asset); $index->delete; diff --git a/lib/WebGUI/Config.pm b/lib/WebGUI/Config.pm index e1b340752..4982a4504 100644 --- a/lib/WebGUI/Config.pm +++ b/lib/WebGUI/Config.pm @@ -171,7 +171,7 @@ sub new { my $filename = shift; my $noCache = shift; my $fullPath = Cwd::realpath($webguiPath.'/etc/'.$filename); - if (exists $config{$fullPath}) { + if ($config{$fullPath}) { return $config{$fullPath}; } else { my $self = Config::JSON->new($fullPath); diff --git a/lib/WebGUI/Form/SelectRichEditor.pm b/lib/WebGUI/Form/SelectRichEditor.pm index c5025004c..d8c60db43 100644 --- a/lib/WebGUI/Form/SelectRichEditor.pm +++ b/lib/WebGUI/Form/SelectRichEditor.pm @@ -131,7 +131,7 @@ sub getOptions { my $editor; eval { $editor = $editorIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $editor; diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index 09df92517..b25f3d80c 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -104,7 +104,6 @@ sub asset { my $asset = shift; if ($asset) { $self->{_asset} = $asset; - weaken( $self->{_asset} ); } return $self->{_asset}; } @@ -124,7 +123,7 @@ sub close { # Kill circular references. The literal list is so that the order # can be explicitly shuffled as necessary. # XXX Is this necessary when we have weakened session refs? - foreach my $key (qw/_asset _datetime _icon _slave _db _env _form _http _id _output _os _privilege _scratch _setting _stow _style _url _user _var _errorHandler _config /) { + foreach my $key (qw/_asset _datetime _icon _slave _db _env _form _http _id _output _os _privilege _scratch _setting _stow _style _url _user _var _errorHandler /) { delete $self->{$key}; } } diff --git a/lib/WebGUI/Workflow/Activity/CleanTempStorage.pm b/lib/WebGUI/Workflow/Activity/CleanTempStorage.pm index 3fb42e1ef..653467ac5 100644 --- a/lib/WebGUI/Workflow/Activity/CleanTempStorage.pm +++ b/lib/WebGUI/Workflow/Activity/CleanTempStorage.pm @@ -115,7 +115,7 @@ sub execute { my $child; eval { $child = $childIter->() }; if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) { - $session->log->error($x->full_message); + $self->session->log->error($x->full_message); next; } last unless $child; diff --git a/lib/WebGUI/Workflow/Activity/ProcessEMSApprovals.pm b/lib/WebGUI/Workflow/Activity/ProcessEMSApprovals.pm index 3064e1b39..addc4c73a 100644 --- a/lib/WebGUI/Workflow/Activity/ProcessEMSApprovals.pm +++ b/lib/WebGUI/Workflow/Activity/ProcessEMSApprovals.pm @@ -80,6 +80,7 @@ sub execute { my $list = $root->getLineage( ['descendants'], { includeOnlyClasses => ['WebGUI::Asset::EMSSubmissionForm'], + returnObjects => 1, } ); for my $emsForm ( @$list ) { @@ -88,6 +89,7 @@ sub execute { joinClass => 'WebGUI::Asset::EMSSubmission', includeOnlyClasses => ['WebGUI::Asset::EMSSubmission'], whereClause => $whereClause, + returnObjects => 1, } ); for my $submission ( @$res ) { my $properties = { className => 'WebGUI::Asset::Sku::EMSTicket' }; diff --git a/t/Asset/Wobject/Survey.t b/t/Asset/Wobject/Survey.t index 87f826eb9..8548b093c 100644 --- a/t/Asset/Wobject/Survey.t +++ b/t/Asset/Wobject/Survey.t @@ -273,37 +273,37 @@ cmp_deeply( [ { 'extras' => undef, - 'url' => '/home?func=edit', + 'url' => re('func=edit$'), 'label' => 'Edit' }, { 'extras' => undef, - 'url' => '/home?func=editSurvey', + 'url' => re('func=editSurvey$'), 'label' => 'Edit Survey' }, { 'extras' => undef, - 'url' => '/home?func=takeSurvey', + 'url' => re('func=takeSurvey$'), 'label' => 'Take Survey' }, { 'extras' => undef, - 'url' => '/home?func=graph', + 'url' => re('func=graph$'), 'label' => 'Visualize' }, { 'extras' => undef, - 'url' => '/home?func=editTestSuite', + 'url' => re('func=editTestSuite$'), 'label' => 'Test Suite' }, { 'extras' => undef, - 'url' => '/home?func=runTests', + 'url' => re('func=runTests$'), 'label' => 'Run All Tests' }, { 'extras' => undef, - 'url' => '/home?func=runTests;format=tap', + 'url' => re('func=runTests;format=tap$'), 'label' => 'Run All Tests (TAP)' } ], diff --git a/t/Search/Index.t b/t/Search/Index.t index fb63e4e49..09c85df29 100644 --- a/t/Search/Index.t +++ b/t/Search/Index.t @@ -56,7 +56,7 @@ cmp_deeply ( { assetId => $article->getId, title => $article->get('title'), - synopsis => $row->{keywords}, # synopsis defaults to value for keywords + synopsis => $article->get('synopsis') || '', url => $article->get('url'), revisionDate => $article->get('revisionDate'), creationDate => $article->get('creationDate'),