OK, here's some code:
# systems
my @statuses;
my (@systems) = Lib::Systems->search( cid => $cid );
unless (@systems) { $self->model->log('debug', "systems for '$cid' not found"); $self->context->throw( 'systems.not_found', 'Systems not found' ); };
my $systems_profile = Lib::Profiles->system;
foreach my $sys (@systems) {
# reassign params from form names
my %tmp = map { $_ => $params{$_.'_'.$sys->sysid} } Lib::Systems->columns;
my ($data, $errors) = $self->model->validate($systems_profile, \%tmp);
if (@$errors) {
$self->context->throw( 'required', { fields => [EMAIL PROTECTED] } );
} else {
my (@relen_ips, @add_ips);
# establish status
my $status = 1;
if ($sys->cancel_date) { $status = 3; }
if ($sys->stop_date) { $status = 9; }
# process a change in status my $newstatus; if ($sys->cancel_date < 1 && $tmp{'cancel_date'}) { $self->model->log('info', 'cancelling system '.$sys->sysid); $newstatus = 3; $status = 3; } if ($sys->stop_date < 1 && $tmp{'stop_date'}) { $self->model->log('info', 'stopping system '.$sys->sysid); $newstatus = 9; $status = 9; }
# store status so we can look at all and determine a cust status push @statuses, $status;
# if status 9, add existing system's IPs to relen list
if ($newstatus == 9) {
my @ipobj = Lib::Ipmap->search( sysid => $sys->sysid, status => 1 );
foreach (@ipobj) { push @relen_ips, $_->ip; }
}
$self->model->log('info', "updating values for system ".$sys->sysid);
while (my($key, $value) = each %$data) {
# we add this next line in case the client sends extra
# fields which we don't want to update. like the web
# client does
next unless ( Lib::Systems->find_column( $key ) );
$self->model->log('info', "setting $key to $value" );
eval { $sys->$key( $value ) }; if ($@) { $self->context->throw( 'set value', $@ ); } } # end while push @toupdate, $sys;
# IPs
# add new
if ($params{'ip_'.$sys->sysid.'_new'}) {
my $assign_date = $self->model->{'time'}->ymd;
my $relen_date = 0;
# REMOVE WHEN WE GO LIVE AND ALL 2nd SYSTEMS ARE ADDED TO RECORDS #
$assign_date = $sys->start_date;
# END REMOVE #
# if stopping server at same time assigning new ips
# we assume they were supposed to be there all the time so we set
# assign date to sys start date. also, set relen_date
if ($newstatus == 9) { $assign_date = $sys->start_date; $relen_date = $self->model->{'time'}->ymd; }
push @toupdate, update_ip($self, $sys->sysid, $cid, $assign_date, $relen_date, split /[\s\,]/, $params{'ip_'.$sys->sysid.'_new'});
$self->model->set('ip_'.$sys->sysid.'_new','');
} # end new ip if
# get rid of ips
my $relen_date = $self->model->{'time'}->ymd;
push @relen_ips, $self->model->input('ip_'.$sys->sysid);
push @toupdate, update_ip($self, $sys->sysid, $cid, undef, $relen_date, @relen_ips);
} # end update sys else
} # end sys foreach
---SNIP---
# process updates foreach my $obj (@toupdate) { $self->model->log('info', "updating obj:"); $self->model->log_dumper('info', $obj); eval { $obj->update }; if ($@) { $self->model->log('info', 'update failed, rolling back'); foreach my $o (@created) { $o->dbi_rollback; } $self->context->throw( 'update', $@ ); } else { push @created, $obj; } }
# if we made it this far, commit everything foreach my $obj (@toupdate) { $obj->dbi_commit; }
$self->model->set('addsystem',''); $self->model->set('addcontact',''); $self->model->set('do_update',''); return;
Thanks! At 03:40 PM 5/1/2004, Perrin Harkins wrote:
Dave Boodman wrote:I'm seeing an issue where I do an insert and upon subsequent requests, certain children are not returning the newly-inserted data (row), while others are. Restarting apache fixes this as does waiting for some length of time.
Sounds like you have a scoping problem. You are probably accidentally creating a closure somewhere that is holding onto old values. If you can reduce your code down to an example small enough to post here, we can try to spot it for you.
- Perrin
-- Report problems: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html