I'm inclined toward number 3.--- 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 %$varsre +f) ); +} + +##################################################################### +######## # Sub # setVars # # Purpose -# This takes a hash of variables and assigns it to the 'vars' o +f the -# given node. If the new vars are different, we will update th +e -# node. +# This takes a hash of variables and assigns it to a field of t +he +# 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 o +n 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 "var +s" # # 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 %$varsre +f) ); + 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, f +orce # an update on the user info. - $$NODE{vars} = $str; + $$NODE{$field} = $str; my $superuser = -1; $DB->updateNode($NODE, $superuser); }
Once that's resolved, the rest is pretty easy; it will work differently from other patches in a couple of ways. First, there will be just a "Create Patch" button on the setting display page, not a form (since I don't see an easy way to feed op=new an editvars form). Second, it will just display the new settings, not a diff, at least until I figure out diff_strings enough to hack it to the purpose.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: patchable settings (factor)
by tye (Sage) on Sep 13, 2004 at 23:52 UTC | |
by ysth (Canon) on Sep 13, 2004 at 23:56 UTC | |
|
Re: patchable settings
by ysth (Canon) on Sep 14, 2004 at 19:41 UTC | |
|
Re: patchable settings
by demerphq (Chancellor) on Sep 28, 2004 at 01:45 UTC | |
by ysth (Canon) on Sep 28, 2004 at 03:34 UTC | |
by demerphq (Chancellor) on Sep 28, 2004 at 07:30 UTC | |
by ysth (Canon) on Sep 28, 2004 at 07:42 UTC | |
by demerphq (Chancellor) on Sep 28, 2004 at 07:57 UTC | |
| |
by ysth (Canon) on Oct 05, 2004 at 19:03 UTC | |
by demerphq (Chancellor) on Oct 06, 2004 at 09:20 UTC | |
| |
|
Re: patchable settings
by demerphq (Chancellor) on Sep 14, 2004 at 08:00 UTC | |
|
Re: patchable settings
by ysth (Canon) on Oct 15, 2004 at 06:40 UTC | |
by demerphq (Chancellor) on Oct 16, 2004 at 10:58 UTC | |
by ysth (Canon) on Oct 17, 2004 at 10:45 UTC | |
by demerphq (Chancellor) on Oct 17, 2004 at 17:13 UTC | |
by tye (Sage) on Oct 16, 2004 at 16:48 UTC | |
by demerphq (Chancellor) on Oct 17, 2004 at 07:29 UTC | |
by demerphq (Chancellor) on Oct 17, 2004 at 17:17 UTC | |
by tye (Sage) on Oct 17, 2004 at 19:18 UTC | |
| |
by ysth (Canon) on Oct 17, 2004 at 02:38 UTC | |
by demerphq (Chancellor) on Oct 17, 2004 at 07:31 UTC | |
|
Re: patchable settings
by ysth (Canon) on Sep 24, 2004 at 06:13 UTC |