diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 277cdcfd7..34aa7ac28 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1588,12 +1588,7 @@ sub new { my $placeHolders = [$assetId]; # join all the tables - my %tables; - foreach my $property ($class->getProperties) { - my $definition = $class->getProperty($property); - %tables{$definition->{tableName}} = 1; - } - foreach my $table (keys %tables) { + foreach my $table ($self->getTables) { $sql .= ",".$definition->{tableName}; $where .= " and (asset.assetId=".$definition->{tableName}.".assetId and ".$definition->{tableName}.".revisionDate=".$revisionDate.")"; } @@ -2439,12 +2434,11 @@ sub www_add { return $self->session->privilege->insufficient() unless ($class->canAdd($self->session)); if ($self->session->form->process('prototype')) { my $prototype = WebGUI::Asset->new($self->session, $self->session->form->process("prototype"),$class); - foreach my $definition (@{$prototype->definition($self->session)}) { # cycle through rather than copying properties to avoid grabbing stuff we shouldn't grab - foreach my $property (keys %{$definition->{properties}}) { - next if (isIn($property,qw(title menuTitle url isPrototype isPackage))); - next if ($definition->{properties}{$property}{noFormPost}); - $prototypeProperties{$property} = $prototype->get($property); - } + foreach my $property ($prototype->getProperties) { # cycle through rather than copying properties to avoid grabbing stuff we shouldn't grab + my $definition = $prototype->getProperty($property); + next if (isIn($property,qw(title menuTitle url isPrototype isPackage))); + next if ($definition->{noFormPost}); + $prototypeProperties{$property} = $prototype->get($property); } } my %properties = ( diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index cc9a1c444..dc3898912 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -617,10 +617,9 @@ sub getLineageSql { if ( ! eval { require $module; 1 }) { $self->session->errorHandler->fatal("Couldn't compile asset package: ".$className.". Root cause: ".$@) if ($@); } - foreach my $definition (@{$className->definition($self->session)}) { - unless ($definition->{tableName} eq "asset" || $definition->{tableName} eq "assetData") { - my $tableName = $definition->{tableName}; - $tables .= " left join $tableName on assetData.assetId=".$tableName.".assetId and assetData.revisionDate=".$tableName.".revisionDate"; + foreach my $table ($self->getTables) { + unless ($table eq "asset" || $table eq "assetData") { + $tables .= " left join $table on assetData.assetId=".$table.".assetId and assetData.revisionDate=".$table.".revisionDate"; } } } diff --git a/lib/WebGUI/Definition.pm b/lib/WebGUI/Definition.pm index 117997b34..fb33d2c60 100644 --- a/lib/WebGUI/Definition.pm +++ b/lib/WebGUI/Definition.pm @@ -202,6 +202,18 @@ sub _gen_instantiate { __END__ +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2009 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + =head1 NAME WebGUI::Definition - Define properties for a class diff --git a/lib/WebGUI/Definition/Asset.pm b/lib/WebGUI/Definition/Asset.pm index 1f532aec1..8b2920c55 100644 --- a/lib/WebGUI/Definition/Asset.pm +++ b/lib/WebGUI/Definition/Asset.pm @@ -22,6 +22,7 @@ use WebGUI::International; our $VERSION = '0.0.1'; +#------------------------------------------------------------------- sub import { my $class = shift; if (! @_) { @@ -34,6 +35,7 @@ sub import { $properties->[$i]{tableName} ||= $table; } } + $class->_install($super, 'getTables', $class->_gen_getTables()); # WebGUI::Definition->import uses caller, so avoid the extra entry in the call stack my $next = $class->next::can; @@ -41,6 +43,21 @@ sub import { goto $next; } +#------------------------------------------------------------------- +sub _gen_getTables { + my $class = shift; + return sub { + my $self = shift; + my %tables; + foreach my $property ($self->getProperties) { + my $definition = $self->getProperty($property); + %tables{$definition->{tableName}} = 1; + } + return keys %tables; + }; +} + +#------------------------------------------------------------------- sub _gen_getProperty { my $class = shift; my $superGetProperty = $class->next::method(@_); @@ -59,3 +76,40 @@ sub _gen_getProperty { 1; +__END__ + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2009 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=head1 NAME + +WebGUI::Definition::Asset + +=head1 DESCRIPTION + +Extends WebGUI::Definition with asset specific methods and convienences. It automatically inserts the tableName attribute as an element of each property if the property doesn't explicitly set it. + +=head1 METHODS + +The following methods are exposed through this class. + +=head2 getProperty ( property ) + +Extends getProperty() method generated by WebGUI::Definition by automatically converting the label and hoverHelp elements into strings. + +=head2 getTables ( ) + +Returns a list of the tables that this asset's properties are stored in. + +=cut + +