- my ($self, $r, $params, $no_classify) = @_;
- $self->_croak( "update_from_cgi can only be called as an object method")
- unless ref $self;
- my ($errors, $validated, $wanted);
- $self->{_cgi_update_error} = {};
-
- #print "*** update_from_cgi talking ***\n\n";
- # FromCGI interface compatibility params are ($h, $wanted)
- if ($r->isa('CGI::Untaint')) {
- # REHASH the $wanted for updating:
- # 1: we ignore any fields we dont have parmeter for. (safe ?)
- # 2: we dont want to update fields unless they change
-
- my ($h, $wanted) = ($r, $params);
- my @ignore = @{$wanted->{ignore} || []};
- push @ignore, $self->primary_column->name;
- my $raw = $h->raw_data;
- #print "*** raw data ****" . Dumper($raw);
- foreach my $field ($self->columns) {
- #print "*** field is $field ***\n";
- if (not defined $raw->{$field}) {
- push @ignore, $field->name;
- #print "*** ignoring $field because it is not present ***\n";
- next;
-
- }
- # stupid inflation , cant get at raw db value easy, must call
- # deflate ***FIXME****
- my $cur_val = ref $self->$field ? $self->$field->id : $self->$field;
- if ($raw->{$field} eq $cur_val) {
- #print "*** ignoring $field because unchanged ***\n";
- push @ignore, $field->name;
- }
- }
-
- $wanted->{ignore} = \@ignore;
- #print "*** wanted ****" . Dumper($wanted);
- ($errors, $validated) = $self->_validate($h,$wanted,1);
- #print "*** validated data ****" . Dumper($validated);
- #print "*** errors ****" . Dumper($errors);
- }
- else {
- $params ||= $r->params;
- my $classified = $no_classify ? {%$params}:$self->classify_form_inputs($params);
- ($errors, $validated) = $self->validate_all($r, $classified,1);
- #print "*** errors for validate all ****" . Dumper($errors);
- }
+ my ($self, $r, $opts) = @_;
+ $self->_croak( "update_from_cgi can only be called as an object method") unless ref $self;
+ my ($errors, $validated);
+ $self->{_cgi_update_error} = {};
+ $opts->{updating} = 1;
+
+ # FromCGI interface compatibility
+ if ($r->isa('CGI::Untaint')) {
+ # REHASH the $opts for updating:
+ # 1: we ignore any fields we dont have parmeter for. (safe ?)
+ # 2: we dont want to update fields unless they change
+
+ my @ignore = @{$opts->{ignore} || []};
+ push @ignore, $self->primary_column->name;
+ my $raw = $r->raw_data;
+ #print "*** raw data ****" . Dumper($raw);
+ foreach my $field ($self->columns) {
+ #print "*** field is $field ***\n";
+ if (not defined $raw->{$field}) {
+ push @ignore, $field->name;
+ #print "*** ignoring $field because it is not present ***\n";
+ next;
+ }
+ # stupid inflation , cant get at raw db value easy, must call
+ # deflate ***FIXME****
+ my $cur_val = ref $self->$field ? $self->$field->id : $self->$field;
+ if ($raw->{$field} eq $cur_val) {
+ #print "*** ignoring $field because unchanged ***\n";
+ push @ignore, "$field";
+ }
+ }
+ $opts->{ignore} = \@ignore;
+ ($validated, $errors) = $self->validate_inputs($r,$opts);
+ } else {
+ my $params = $opts->{params} || $r->params;
+ $opts->{params} = $self->classify_form_inputs($params);
+ ($validated, $errors) = $self->validate_all($r, $opts);
+ #print "*** errors for validate all ****" . Dumper($errors);
+ }
+
+ if (keys %$errors) {
+ #print "*** we have errors ****" . Dumper($errors);
+ $self->{_cgi_update_error} = $errors;
+ return;
+ }
+
+ # Update all the data
+ my ($obj, $err ) = $self->_do_update_all($validated);
+ if ($err) {
+ $self->{_cgi_update_error} = $err;
+ return;
+ }
+ return 1;
+}