From 7901e1d398df4155679e5f04938ad23d1eeae902 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 26 Jun 2009 22:42:15 +0000 Subject: [PATCH] Fix the Post handling Metadata possibleValues differently from other Assets. --- docs/changelog/7.x.x.txt | 1 + docs/gotcha.txt | 10 ++++++++- docs/upgrades/upgrade_7.7.12-7.7.13.pl | 24 +++++++++++++++++++- lib/WebGUI/Asset/Post.pm | 31 ++++++++------------------ 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index f109d87b5..5f19fa9b5 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,6 @@ 7.7.13 - fixed #10574: Creating Calendar Entry + - fixed #10522: Metadata value & label problem 7.7.12 - Updated auth to allow sending back of non-text/html mime types. diff --git a/docs/gotcha.txt b/docs/gotcha.txt index a41ca5242..4dd815ae6 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -13,6 +13,12 @@ save you many hours of grief. * Due to changes in the userSession database table, you must upgrade to 7.7.13 before upgrading to 7.7.14 or beyond. + * WebGUI has allowed metadata possible values to be processed differently + by Posts than from other Assets. This causes problems when metadata is + shared between Posts and other Assets. To rememdy this, all metadata + possible values are being moved into the standard "pipe format", and + the Post will no longer process data in the other format. + 7.7.8 -------------------------------------------------------------------- * A basic behavior of the Inbox has been changed. If a message is @@ -125,7 +131,9 @@ save you many hours of grief. Tags field. Extra Head Tags are now added for all templates and assets included on a page, except for Style templates, which do not have Extra Head Tags. Existing Extra Head Tags for Style - templates have been removed. + templates will be lost. If your current Style template uses + the Head Block please put any content from there directly into your + style template inside the tags. * Web Services Client is no longer part of the official distribution of WebGUI, but is still available to be maintained by third-parties. However, diff --git a/docs/upgrades/upgrade_7.7.12-7.7.13.pl b/docs/upgrades/upgrade_7.7.12-7.7.13.pl index 87d1cd8f5..ecc02751d 100644 --- a/docs/upgrades/upgrade_7.7.12-7.7.13.pl +++ b/docs/upgrades/upgrade_7.7.12-7.7.13.pl @@ -32,6 +32,7 @@ my $session = start(); # this line required # upgrade functions go here addSessionTokenId($session); +correctPostMetaData($session); finish($session); # this line required @@ -46,7 +47,6 @@ finish($session); # this line required #} #---------------------------------------------------------------------------- -# Describe what our function does sub addSessionTokenId { my $session = shift; print "\tAdding CSRF token to userSession, if needed... " unless $quiet; @@ -58,6 +58,28 @@ sub addSessionTokenId { print "DONE!\n" unless $quiet; } +#---------------------------------------------------------------------------- +sub correctPostMetaData { + my $session = shift; + my $root = WebGUI::Asset->getRoot($session); + print "\tPutting metadata associated with posts into the standard metadata possibleValues format... " unless $quiet; + # and here's our code + my $meta = $root->getMetaDataFields(); + FIELD: foreach my $field (keys %{ $meta }) { + next FIELD unless $meta->{$field}->{possibleValues} && $meta->{$field}->{possibleValues} =~ m/\}/; + my $values = WebGUI::Operation::Shared::secureEval($session, $meta->{$field}->{possibleValues}); + next FIELD unless ref $values eq 'HASH'; + my $newValues = ''; + while (my ($key, $value) = each %{ $values }) { + $newValues .= join '|', $key, $value; + $newValues .= "\n"; + } + print "\n\t\tUpdating ".$meta->{$field}->{fieldName}; + $root->addMetaDataField(@{ $meta->{$field} }{ qw/fieldId fieldName defaultValue description fieldType/ }, $newValues); + } + print "DONE!\n" unless $quiet; +} + # -------------- DO NOT EDIT BELOW THIS LINE -------------------------------- diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index 1cf389df8..353ae656f 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -1473,32 +1473,19 @@ sub www_edit { my @meta_loop = (); foreach my $field (keys %{ $meta }) { my $fieldType = $meta->{$field}{fieldType} || "Text"; - my %options; - tie %options, 'Tie::IxHash'; - if ($meta->{$field}{possibleValues}){ - my $values = WebGUI::Operation::Shared::secureEval($self->session,$meta->{$field}{possibleValues}); - if (ref $values eq 'HASH') { - %options = %{$values}; - } - else{ - foreach (split(/\n/x, $meta->{$field}{possibleValues})) { - s/\s+$//x; # remove trailing spaces - $options{$_} = $_; - } - } - } + my $options = $meta->{$field}{possibleValues}; # Add a "Select..." option on top of a select list to prevent from # saving the value on top of the list when no choice is made. - if($fieldType eq "selectBox") { - %options = ("" => $i18n->get("Select", "Asset"),%options); + if("\l$fieldType" eq "selectBox") { + $options = "|" . $i18n->get("Select") . "\n" . $options; } my $form = WebGUI::Form::DynamicField->new($session, - name=>"metadata_".$meta->{$field}{fieldId}, - uiLevel=>5, - value=>$meta->{$field}{value}, - extras=>qq/title="$meta->{$field}{description}"/, - options=>\%options, - fieldType=>$fieldType, + name => "metadata_".$meta->{$field}{fieldId}, + uiLevel => 5, + value => $meta->{$field}{value}, + extras => qq/title="$meta->{$field}{description}"/, + options => $options, + fieldType => $fieldType, )->toHtml; push @meta_loop, { field => $form,