fixed some Gallery tests failing. removed some unnecessary ones. still bunch more to go...

This commit is contained in:
Doug Bell 2007-12-19 16:41:39 +00:00
parent 17e815281f
commit 01c6379224
8 changed files with 189 additions and 227 deletions

View file

@ -15,6 +15,7 @@ package WebGUI::Asset;
=cut
use Carp qw( croak confess );
use Scalar::Util qw( blessed );
use WebGUI::AssetBranch;
use WebGUI::AssetClipboard;
@ -1686,50 +1687,52 @@ no revision date is available it will return undef.
=cut
sub new {
my $class = shift;
my $session = shift;
my $assetId = shift;
my $className = shift;
my $class = shift;
my $session = shift;
my $assetId = shift;
my $className = shift;
my $revisionDate = shift || $class->getCurrentRevisionDate($session, $assetId);
unless (defined $assetId) {
$session->errorHandler->error("Asset constructor new() requires an assetId.");
return;
}
unless (defined $assetId) {
$session->errorHandler->error("Asset constructor new() requires an assetId.");
return;
}
my $revisionDate = shift || $class->getCurrentRevisionDate($session, $assetId);
return unless ($revisionDate);
return unless ($revisionDate);
unless ($class ne 'WebGUI::Asset' or defined $className) {
($className) = $session->db->quickArray("select className from asset where assetId=?", [$assetId]);
unless ($className) {
$session->errorHandler->error("Couldn't instantiate asset: ".$assetId. ": couldn't find class name");
return;
}
}
unless ($class ne 'WebGUI::Asset' or defined $className) {
($className) = $session->db->quickArray("select className from asset where assetId=?", [$assetId]);
unless ($className) {
$session->errorHandler->error("Couldn't instantiate asset: ".$assetId. ": couldn't find class name");
return;
}
}
if ($className) {
$class = $class->loadModule($session, $className);
return unless (defined $class);
}
}
my $cache = WebGUI::Cache->new($session, ["asset",$assetId,$revisionDate]);
my $properties = $cache->get;
if (exists $properties->{assetId}) {
# got properties from cache
} else {
$properties = WebGUI::Asset->assetDbProperties($session, $assetId, $class, $revisionDate);
unless (exists $properties->{assetId}) {
$session->errorHandler->error("Asset $assetId $class $revisionDate is missing properties. Consult your database tables for corruption. ");
return;
}
$cache->set($properties,60*60*24);
}
if (defined $properties) {
my $object = { _session=>$session, _properties => $properties };
bless $object, $class;
return $object;
}
return;
my $cache = WebGUI::Cache->new($session, ["asset",$assetId,$revisionDate]);
my $properties = $cache->get;
if (exists $properties->{assetId}) {
# got properties from cache
}
else {
$properties = WebGUI::Asset->assetDbProperties($session, $assetId, $class, $revisionDate);
unless (exists $properties->{assetId}) {
$session->errorHandler->error("Asset $assetId $class $revisionDate is missing properties. Consult your database tables for corruption. ");
return;
}
$cache->set($properties,60*60*24);
}
if (defined $properties) {
my $object = { _session=>$session, _properties => $properties };
bless $object, $class;
return $object;
}
$session->errorHandler->error("Something went wrong trying to instanciate a '$className' with assetId '$assetId', but I don't know what!");
return;
}
#-------------------------------------------------------------------
@ -1753,21 +1756,36 @@ A specific revision date for the asset to retrieve. If not specified, the most r
=cut
sub newByDynamicClass {
my $class = shift;
my $session = shift;
confess "newByDynamicClass requires WebGUI::Session" unless $session;
my $assetId = shift;
my $revisionDate = shift;
return unless defined $assetId;
my $assetClass = $session->stow->get("assetClass");
my $className = $assetClass->{$assetId};
unless ($className) {
($className) = $session->db->quickArray("select className from asset where assetId=".$session->db->quote($assetId));
$assetClass->{$assetId} = $className;
$session->stow->set("assetClass",$assetClass);
}
return unless ($className);
return WebGUI::Asset->new($session,$assetId,$className,$revisionDate);
my $class = shift;
my $session = shift;
my $assetId = shift;
my $revisionDate = shift;
confess "newByDynamicClass requires WebGUI::Session"
unless $session && blessed $session eq 'WebGUI::Session';
confess "newByDynamicClass requires assetId"
unless $assetId;
# Cache the className lookup
my $assetClass = $session->stow->get("assetClass");
my $className = $assetClass->{$assetId};
unless ($className) {
$className
= $session->db->quickScalar(
"select className from asset where assetId=?",
[$assetId]
);
$assetClass->{ $assetId } = $className;
$session->stow->set("assetClass", $assetClass);
}
unless ( $className ) {
$session->errorHandler->error("Couldn't find className for asset '$assetId'");
return;
}
return WebGUI::Asset->new($session,$assetId,$className,$revisionDate);
}

View file

@ -602,6 +602,24 @@ sub processStyle {
#----------------------------------------------------------------------------
=head2 purge ( )
Purge the asset. Remove all comments on the photo.
=cut
sub purge {
my $self = shift;
for my $commentId ( @{ $self->getCommentIds } ) {
$self->deleteComment( $commentId );
}
return $self->SUPER::purge;
}
#----------------------------------------------------------------------------
=head2 setComment ( commentId, properties )
Set a comment. If C<commentId> is C<"new">, create a new comment. C<properties>
@ -618,6 +636,11 @@ sub setComment {
unless $commentId;
croak "Photo->setComment: properties must be a hash reference"
unless $properties && ref $properties eq "HASH";
croak "Photo->setComment: properties must contain a bodyText key"
unless $properties->{ bodyText };
$properties->{ creationDate } ||= WebGUI::DateTime->new($self->session, time)->toDatabase;
$properties->{ assetId } = $self->getId;
$self->session->db->setRow(
"Photo_comment", "commentId",

View file

@ -537,10 +537,16 @@ Returns an asset hash of the parent of current Asset.
=cut
sub getParent {
my $self = shift;
return $self if ($self->getId eq "PBasset000000000000001");
$self->{_parent} = WebGUI::Asset->newByDynamicClass($self->session,$self->get("parentId")) unless (defined $self->{_parent});
return $self->{_parent};
my $self = shift;
# Root asset is its own parent
return $self if ($self->getId eq "PBasset000000000000001");
unless ( $self->{_parent} ) {
$self->{_parent} = WebGUI::Asset->newByDynamicClass($self->session,$self->get("parentId"));
}
return $self->{_parent};
}
#-------------------------------------------------------------------