--- Everything.pm.orig 2004-09-13 15:29:13.318740800 -0700 +++ Everything.pm 2004-09-14 09:23:15.763673600 -0700 @@ -258,16 +258,13 @@ ############################################################################# -sub getVars +sub unpackVars { - my ($NODE) = @_; - getRef $NODE; - - return if ($NODE == -1); + my ($vars) = @_; - return {} unless $NODE->{vars}; + return {} unless $vars; - my %vars = map { split /=/ } split (/&/, $$NODE{vars}); + my %vars = map { split /=/ } split (/&/, $vars); foreach (keys %vars) { unescape $vars{$_}; if ($vars{$_} eq ' ') { $vars{$_} = ""; } @@ -277,46 +274,69 @@ } ############################################################################# +sub getVars +{ + my ($NODE, $field) = @_; + getRef $NODE; + + return if ($NODE == -1); + + $field ||= "vars"; + + return unpackVars( $NODE->{$field} ); +} + +############################################################################# +sub packVars +{ + my ($varsref) = @_; + + # Clean out the keys that have do not have a value. + foreach (sort keys %$varsref) { + $$varsref{$_} = " " unless $$varsref{$_}; + } + + return join("&", map( $_."=".escape($$varsref{$_}), keys %$varsref) ); +} + +############################################################################# # Sub # setVars # # Purpose -# This takes a hash of variables and assigns it to the 'vars' of the -# given node. If the new vars are different, we will update the -# node. +# This takes a hash of variables and assigns it to a field of the +# given node. If the field is changed, we will update the node. # # Parameters -# $NODE - a node id or hash of a node that joins on the +# $NODE - a node id or hash of a node, usually one that joins on the # "settings" table which has a "vars" field to assign the vars to. # $varsref - the hashref to get the vars from +# $field - the field in which to put the vars; defaults to "vars" # # Returns # Nothing # sub setVars { - my ($NODE, $varsref) = @_; - my $str; + my ($NODE, $varsref, $field) = @_; + $field ||= "vars"; getRef($NODE); - unless (exists $$NODE{vars}) { - warn ("setVars:\t'vars' field does not exist for node ".getId($NODE)." - perhaps it doesn't join on the settings table?\n"); - } - - # Clean out the keys that have do not have a value. - foreach (keys %$varsref) { - $$varsref{$_} = " " unless $$varsref{$_}; + unless (exists $$NODE{$field}) { + warn ("setVars:\t'$field' field does not exist for node " + . getId($NODE) . "\n"); + warn ("\t\tperhaps it doesn't join on the settings table?\n") + if $field eq "vars"; } - $str = join("&", map( $_."=".escape($$varsref{$_}), keys %$varsref) ); + my $str = packVars( $varsref ); - return unless ($str ne $$NODE{vars}); #we don't need to update... + return unless ($str ne $$NODE{$field}); #we don't need to update... # The new vars are different from what this user node contains, force # an update on the user info. - $$NODE{vars} = $str; + $$NODE{$field} = $str; my $superuser = -1; $DB->updateNode($NODE, $superuser); }