Move get_tables from Meta/Class into Meta/Asset. s/getTables/meta->get_tables/;

This commit is contained in:
Colin Kuskie 2010-01-04 15:34:24 -08:00
parent b72e3a1cd1
commit ce3edcf743
8 changed files with 74 additions and 38 deletions

View file

@ -21,9 +21,9 @@ use JSON;
use HTML::Packer;
use WebGUI::Definition::Asset;
attribute assetName => 'asset',
attribute tableName => 'assetData',
attribute icon => 'assets.gif',
attribute assetName => 'asset';
attribute tableName => 'assetData';
attribute icon => 'assets.gif';
property title => (
tab => "properties",
label => ['99','Asset'],
@ -288,7 +288,7 @@ around BUILDARGS => sub {
my $placeHolders = [$assetId];
# join all the tables
foreach my $table ($className->getTables) {
foreach my $table ($className->meta->get_tables) {
$sql .= ",".$table;
$where .= " and (asset.assetId=".$table.".assetId and ".$table.".revisionDate=".$revisionDate.")";
}

View file

@ -617,7 +617,7 @@ sub getLineageSql {
if ( ! eval { require $module; 1 }) {
$self->session->errorHandler->fatal("Couldn't compile asset package: ".$className.". Root cause: ".$@) if ($@);
}
foreach my $table ($self->getTables) {
foreach my $table ($self->meta->get_tables) {
unless ($table eq "asset" || $table eq "assetData") {
$tables .= " left join $table on assetData.assetId=".$table.".assetId and assetData.revisionDate=".$table.".revisionDate";
}

View file

@ -197,7 +197,7 @@ sub purge {
$outputSub->($i18n->get('Clearing asset tables'));
$session->db->beginTransaction;
$session->db->write("delete from metaData_values where assetId = ?",[$self->getId]);
foreach my $table ($self->getTables) {
foreach my $table ($self->meta->get_tables) {
$session->db->write("delete from ".$table." where assetId=?", [$self->getId]);
}
$session->db->write("delete from asset where assetId=?", [$self->getId]);

View file

@ -131,7 +131,7 @@ sub addRevision {
}
# prime the tables
foreach my $table ($self->getTables) {
foreach my $table ($self->meta->get_tables) {
unless ($table eq "assetData") {
$self->session->db->write( "insert into ".$table." (assetId,revisionDate) values (?,?)", [$self->getId, $now]);
}
@ -355,7 +355,7 @@ sub purgeRevision {
if ($self->getRevisionCount > 1) {
my $db = $self->session->db;
$db->beginTransaction;
foreach my $table ($self->getTables) {
foreach my $table ($self->meta->get_tables) {
$db->write("delete from ".$table." where assetId=? and revisionDate=?",[$self->getId, $self->get("revisionDate")]);
}
my $count = $db->quickScalar("select count(*) from assetData where assetId=? and status='pending'",[$self->getId]);

View file

@ -86,6 +86,25 @@ The second is the i18n namespace to find the asset's name.
=cut
#-------------------------------------------------------------------
=head2 get_tables ( )
Returns an array of the names of all tables in every class used by
this Class.
=cut
sub get_tables {
my $self = shift;
my @properties = ();
my %seen = ();
push @properties,
grep { ! $seen{$_}++ }
map { $_->tableName }
$self->get_all_properties
;
return @properties;
}
1;

View file

@ -106,27 +106,6 @@ sub get_property_list {
#-------------------------------------------------------------------
=head2 get_tables ( )
Returns an array of the names of all tables in every class used by
this Class.
=cut
sub get_tables {
my $self = shift;
my @properties = ();
my %seen = ();
push @properties,
grep { ! $seen{$_}++ }
map { $_->tableName }
$self->get_all_properties
;
return @properties;
}
#-------------------------------------------------------------------
=head2 property_meta ( )
Returns the name of the class for properties.

View file

@ -20,13 +20,13 @@ use Test::More;
use Test::Deep;
use Test::Exception;
plan tests => 26;
plan tests => 29;
my $session = WebGUI::Test->session;
{
note "session and title";
note "new, session and title";
my $asset = WebGUI::Asset->new({session => $session, });
isa_ok $asset, 'WebGUI::Asset';
@ -102,6 +102,24 @@ my $session = WebGUI::Test->session;
isa_ok $asset, 'WebGUI::Asset::Snippet';
}
{
note "Property inspection";
my $asset = WebGUI::Asset->new({
session => $session,
});
cmp_deeply(
[$asset->meta->get_all_properties],
array_each(
methods(
tableName => 'assetData',
)
),
'all properties have the right tableName'
);
}
{
note "getClassById";
my $class;
@ -114,3 +132,11 @@ my $session = WebGUI::Test->session;
$class = WebGUI::Asset->getClassById($session, 'noIdHereBoss');
is $class, undef, '... returns undef if the class cannot be found';
}
{
note "new, fetching from db";
my $asset;
$asset = WebGUI::Asset->new($session, 'PBasset000000000000001');
isa_ok $asset, 'WebGUI::Asset';
is $asset->title, 'Root', 'got the right asset';
}

View file

@ -128,6 +128,12 @@ use WebGUI::Test;
my $object2 = __PACKAGE__->new(tableName => 'notAsset');
::is $object2->tableName, 'asset', 'tableName ignored in constructor';
::cmp_deeply(
[ __PACKAGE__->meta->get_tables ],
[qw/asset/],
'get_tables works for a simple asset'
);
}
{
@ -188,6 +194,18 @@ use WebGUI::Test;
'checking inheritance of properties by name, insertion order'
);
::cmp_deeply(
[ WGT::Class::AlsoAsset->meta->get_tables ],
[qw/asset/],
'get_tables: checking inheritance'
);
::cmp_deeply(
[ WGT::Class::Asset::Snippet->meta->get_tables ],
[qw/asset snippet/],
'get_tables: checking inheritance on subclass'
);
}
{
@ -214,10 +232,4 @@ use WebGUI::Test;
'checking inheritance of properties by name, insertion order with an overridden property'
);
cmp_deeply(
[WGT::Class::Asset::NotherOne->meta->get_tables],
[qw/asset snippet/],
'get_tables returns both tables'
);
}