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

@ -9,9 +9,10 @@
- fix: the fileImport script did not resize vertical images. (Martin Kamerbeek / Oqapi) - fix: the fileImport script did not resize vertical images. (Martin Kamerbeek / Oqapi)
- fix: TrashClipboard.pm (thanks to Erik Svanberg for the patch) - fix: TrashClipboard.pm (thanks to Erik Svanberg for the patch)
- fix: Manage events in time tracker goofed up (perlDreamer Consulting, LLC) - fix: Manage events in time tracker goofed up (perlDreamer Consulting, LLC)
- fix: Clipboard to trash (perlDreamer Consulting, LLC) - fix: Clipboard to trash (and TrashClipboard Workflow Activity) (perlDreamer Consulting, LLC)
- fix: Fixed the left column template, which still used the RawHeadTags - fix: Fixed the left column template, which still used the RawHeadTags
macro. (perlDreamer Consulting, LLC) macro. (perlDreamer Consulting, LLC)
- Fixed a bad module name in the updated WeatherData asset (perlDreamer Consulting, LLC)
7.3.11 7.3.11
- Added an option for enabling coverage tests to testCodebase.pl. - Added an option for enabling coverage tests to testCodebase.pl.

View file

@ -15,7 +15,7 @@ package WebGUI::Asset::Wobject::WeatherData;
=cut =cut
use strict; use strict;
use Weather::Com::Simple; use Weather::Simple;
use WebGUI::International; use WebGUI::International;
use base 'WebGUI::Asset::Wobject'; use base 'WebGUI::Asset::Wobject';
use WebGUI::Utility; 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 =head3 limitToUser
If True, only return assets last updated by userId. If True, only return assets last updated by userId, specified below.
=head3 userId =head3 userId
If not specified, uses current user. If not specified, uses current user.
=head3 expireTime
If defined, then uses expireTime to limit returned assets to only include those
before expireTime.
=cut =cut
sub getAssetsInClipboard { sub getAssetsInClipboard {
@ -108,34 +114,27 @@ sub getAssetsInClipboard {
my $session = $self->session; my $session = $self->session;
my $limitToUser = shift; my $limitToUser = shift;
my $userId = shift || $session->user->userId; my $userId = shift || $session->user->userId;
my @assets; my $expireTime = shift;
my $limit;
my @limits = ();
if ($limitToUser) { if ($limitToUser) {
$limit = "and asset.stateChangedBy=".$session->db->quote($userId); push @limits, "asset.stateChangedBy=".$session->db->quote($userId);
} }
my $sth = $self->session->db->read(" if (defined $expireTime) {
select push @limits, "stateChanged < ".$expireTime;
asset.assetId, }
assetData.revisionDate,
asset.className my $limit = join ' and ', @limits;
from
asset my $root = WebGUI::Asset->getRoot($self->session);
left join return $root->getLineage(
assetData on asset.assetId=assetData.assetId ["descendents", ],
where {
asset.state='clipboard' statesToInclude => ["clipboard"],
and assetData.revisionDate=(SELECT max(revisionDate) from assetData where assetData.assetId=asset.assetId and (assetData.status='approved' or assetData.tagId=?)) returnObjects => 1,
$limit whereClause => $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;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

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

View file

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