From: Dobrica Pavlinusic Date: Tue, 1 Jun 2010 15:36:02 +0000 (+0200) Subject: save changes which change data X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=df63a3ab5bd8d85990e763fbe917dd9370dee8bd;p=MojoFacets.git save changes which change data This is real modification log (you might say diff) which should allow loading of different data set and application of changes to it --- diff --git a/lib/MojoFacets/Data.pm b/lib/MojoFacets/Data.pm index b13f7a0..b029185 100644 --- a/lib/MojoFacets/Data.pm +++ b/lib/MojoFacets/Data.pm @@ -12,6 +12,7 @@ use Encode; use locale; use File::Find; use Storable; +use Time::HiRes qw(time); our $loaded; our $filters; @@ -709,7 +710,22 @@ sub edit { if ( $old ne $new && ! ( $old eq 'undef' && length($content) == 0 ) # new value empty, previous undef ) { - warn "# update $path $i $old -> $new\n"; + my $change = { + path => $path, + column => $name, + pos => $i, + old => $loaded->{$path}->{data}->{items}->[$i]->{$name}, + new => $v, + time => $self->param('time') || time(), + user => $self->param('user') || $ENV{'LOGNAME'}, + }; + my $change_path = $self->app->home->rel_dir('data') . '/' . $path . '.changes'; + mkdir $change_path unless -d $change_path; + $change_path .= '/' . $change->{time}; + store $change, $change_path; + warn "# $change_path ", dump($change); + + warn "# change $path $i $old -> $new\n"; $loaded->{$path}->{data}->{items}->[$i]->{$name} = $v; if ( defined $loaded->{$path}->{sorted}->{$name} ) {