1) Fixed a bad module name that prevented the updated WeatherData from running.

2) Heavy refactor of getAssetsInClipboard to make it use getLineage instead of
custom SQL.

Made Workflow/Activity/TrashClipboard use the same method.

Updated getLineage so that the whereClause key must not only exist, but actually
have something in it.  Otherwise it generates an empty pair of parens, which is
a SQL error.
This commit is contained in:
Colin Kuskie 2007-03-05 17:47:30 +00:00
parent 70e156542a
commit c3052fcd67
5 changed files with 39 additions and 38 deletions

View file

@ -15,7 +15,7 @@ package WebGUI::Asset::Wobject::WeatherData;
=cut
use strict;
use Weather::Com::Simple;
use Weather::Simple;
use WebGUI::International;
use base 'WebGUI::Asset::Wobject';
use WebGUI::Utility;

View file

@ -89,18 +89,24 @@ sub duplicate {
#-------------------------------------------------------------------
=head2 getAssetsInClipboard ( [limitToUser,userId] )
=head2 getAssetsInClipboard ( [limitToUser,userId,expireTime] )
Returns an array reference of title, assetId, and classname to the assets in the clipboard.
Returns an array reference of assets that are in the clipboard. Only assets that are committed
or that are under the current user's version tag are returned.
=head3 limitToUser
If True, only return assets last updated by userId.
If True, only return assets last updated by userId, specified below.
=head3 userId
If not specified, uses current user.
=head3 expireTime
If defined, then uses expireTime to limit returned assets to only include those
before expireTime.
=cut
sub getAssetsInClipboard {
@ -108,34 +114,27 @@ sub getAssetsInClipboard {
my $session = $self->session;
my $limitToUser = shift;
my $userId = shift || $session->user->userId;
my @assets;
my $limit;
my $expireTime = shift;
my @limits = ();
if ($limitToUser) {
$limit = "and asset.stateChangedBy=".$session->db->quote($userId);
push @limits, "asset.stateChangedBy=".$session->db->quote($userId);
}
my $sth = $self->session->db->read("
select
asset.assetId,
assetData.revisionDate,
asset.className
from
asset
left join
assetData on asset.assetId=assetData.assetId
where
asset.state='clipboard'
and assetData.revisionDate=(SELECT max(revisionDate) from assetData where assetData.assetId=asset.assetId and (assetData.status='approved' or assetData.tagId=?))
$limit
group by
assetData.assetId
order by
assetData.title desc
", [$session->scratch->get("versionTag")]);
while (my ($id, $date, $class) = $sth->array) {
push(@assets, WebGUI::Asset->new($session,$id,$class,$date));
}
$sth->finish;
return \@assets;
if (defined $expireTime) {
push @limits, "stateChanged < ".$expireTime;
}
my $limit = join ' and ', @limits;
my $root = WebGUI::Asset->getRoot($self->session);
return $root->getLineage(
["descendents", ],
{
statesToInclude => ["clipboard"],
returnObjects => 1,
whereClause => $limit,
}
);
}
#-------------------------------------------------------------------

View file

@ -422,7 +422,7 @@ sub getLineage {
}
## finish up our where clause
$where .= ' and ('.join(" or ",@whereModifiers).')' if (scalar(@whereModifiers));
if (exists $rules->{whereClause}) {
if (exists $rules->{whereClause} && $rules->{whereClause}) {
$where .= ' and ('.$rules->{whereClause}.')';
}
# based upon all available criteria, let's get some assets

View file

@ -17,6 +17,8 @@ package WebGUI::Workflow::Activity::TrashClipboard;
use strict;
use base 'WebGUI::Workflow::Activity';
use WebGUI::Asset;
use WebGUI::AssetClipboard;
=head1 NAME
@ -74,13 +76,12 @@ See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my $self = shift;
my $expireDate = (time()-$self->get("trashAfter"));
my $sth = $self->session->db->read("select assetId,className from asset where state='clipboard' and stateChanged < ?", [$expireDate]);
while (my ($id, $class) = $sth->array) {
my $asset = WebGUI::Asset->new($self->session,$id,$class);
my $self = shift;
my $expireDate = (time()-$self->get("trashAfter"));
my $root = WebGUI::Asset->getRoot($self->session);
foreach my $asset ( @{ $root->getAssetsInClipboard('', '', $expireDate) } ) {
$asset->trash;
}
}
return $self->COMPLETE;
}