From 6524a3c815587cf60c1d9c292e70fea4baa15e34 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 19 Jul 2007 23:08:02 +0000 Subject: [PATCH] Asset properties that have default values are now enforced by the API as they always have been by the user interface. --- lib/WebGUI/Asset.pm | 42 ++++++++++++++++++++++++++++++++----- lib/WebGUI/Asset/Wobject.pm | 4 ++-- lib/WebGUI/AssetLineage.pm | 5 ----- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 81986c456..8c8b52273 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -40,7 +40,7 @@ Package WebGUI::Asset =head1 DESCRIPTION -Package to manipulate items in WebGUI's asset system. Replaces Collateral. +Package to manipulate items in WebGUI's asset system. =head1 SYNOPSIS @@ -310,7 +310,7 @@ sub definition { uiLevel=>1, fieldType=>'text', filter=>'fixTitle', - defaultValue=>undef + defaultValue=>'Untitled', }, url=>{ tab=>"properties", @@ -489,7 +489,11 @@ Any text string. Most likely will have been the Asset's name or title. sub fixTitle { my $self = shift; - return WebGUI::HTML::filter(shift || $self->getValue("title") || 'Untitled', 'all'); + my $string = shift; + if (lc($string) eq "untitled" || $string eq "") { + $string = $self->getValue("title") || 'Untitled'; + } + return WebGUI::HTML::filter($string, 'all'); } @@ -1992,27 +1996,55 @@ Hash reference of properties and values to set. sub update { my $self = shift; my $properties = shift; + + # if keywords were specified, then let's set them the right way if (exists $properties->{keywords}) { WebGUI::Keyword->new($self->session)->setKeywordsForAsset( {keywords=>$properties->{keywords}, asset=>$self}); } - foreach my $definition (@{$self->definition($self->session)}) { + + # check the definition of all properties against what was given to us + foreach my $definition (reverse @{$self->definition($self->session)}) { my @setPairs; + + # deal with all the properties in this part of the definition foreach my $property (keys %{$definition->{properties}}) { - next unless (exists $properties->{$property}); + + # skip a property unless it was specified to be set by the properties field or has a default value + next unless (exists $properties->{$property} || exists $definition->{properties}{$property}{defaultValue}); + # use the update value my $value = $properties->{$property}; + # use the current value because the update value was undef + unless (defined $value) { + $value = $self->get($property); + } + + # apply filter logic on a property to validate or fix it's value if (exists $definition->{properties}{$property}{filter}) { my $filter = $definition->{properties}{$property}{filter}; $value = $self->$filter($value, $property); } + + # use the default value because default and update were both undef + unless (defined $value) { + $value = $definition->{properties}{$property}{defaultValue}; + } + + # set the property $self->{_properties}{$property} = $value; push(@setPairs, $property."=".$self->session->db->quote($value)); } + + # if there's anything to update, then do so if (scalar(@setPairs) > 0) { $self->session->db->write("update ".$definition->{tableName}." set ".join(",",@setPairs)." where assetId=".$self->session->db->quote($self->getId)." and revisionDate=".$self->get("revisionDate")); } } + + # we've changed something so we need to update our size $self->setSize(); + + # we've changed something so cache is no longer valid $self->purgeCache; } diff --git a/lib/WebGUI/Asset/Wobject.pm b/lib/WebGUI/Asset/Wobject.pm index 27eaa7407..2978c3286 100644 --- a/lib/WebGUI/Asset/Wobject.pm +++ b/lib/WebGUI/Asset/Wobject.pm @@ -84,7 +84,7 @@ sub definition { }, styleTemplateId=>{ fieldType=>'template', - defaultValue=>undef, + defaultValue=>'PBtmpl0000000000000060', tab=>"display", label=>$i18n->get(1073), hoverHelp=>$i18n->get('1073 description'), @@ -93,7 +93,7 @@ sub definition { }, printableStyleTemplateId=>{ fieldType=>'template', - defaultValue=>undef, + defaultValue=>'PBtmpl0000000000000060', tab=>"display", label=>$i18n->get(1079), hoverHelp=>$i18n->get('1079 description'), diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index 6bc41d242..c440c3c8d 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -68,11 +68,6 @@ sub addChild { my $id = shift || $self->session->id->generate(); my $now = shift || $self->session->datetime->time(); my $options = shift; - # add a few things just in case the creator forgets - $properties->{ownerUserId} ||= '3'; - $properties->{groupIdEdit} ||= '12'; - $properties->{groupIdView} ||= '7'; - $properties->{styleTemplateId} ||= 'PBtmpl0000000000000060'; # Check if it is possible to add a child to this asset. If not add it as a sibling of this asset. if (length($self->get("lineage")) >= 252) {