fixes for weaken and iterator
This commit is contained in:
parent
60cefb3102
commit
247c607393
22 changed files with 83 additions and 47 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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}}) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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' };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue