|
From: Chris M. <Chr...@te...> - 2002-01-22 07:14:08
|
Hello,
Looking over this code, I'm noticing that it's awfully messy, but I'm hoping
someone can help me out. In the code below is the save routine from the
package I'm working on. It branches near the end for new records and
updates. Anyway, the save works in the case of a new record, but not an
update. The only error I get is:
Can't call method "save" on unblessed reference at
/var/www/testsite/pkg/monitoring-0.01/testsite/Handler/Monitoring.pm line
410.
The error log simply adds that it died, and the above was what was left.
And here is the code...
The form displays multiple records for editing, hence the loop and the
counter...
sub save {
my $class = shift;
my $p = shift;
my $R = OpenInteract::Request->instance;
my $apr = $R->apache;
my $done;
my $i = 1;
my $search_host;
my $host = $R->host->new;
until ($done == 1) {
undef $host;
undef $search_host;
if ($apr->param("host".$i)) {
# , customer_id int(11) not null
# , host varchar(255) not null
# , ping_type varchar(25) not null
# , is_alive varchar(1) not null
# , email varchar(255)
# , pager_number varchar(15)
# , pager_configuration_id int(11)
if ($apr->param("sqltype") =~ /update/ ) {
$search_host =
$apr->param("monitored_host_id").$i;
$host = $R->host->fetch($search_host);
} else {
$host = $R->host->new;
$host->{is_alive} = "n";
}
$host->{customer_id} =
$R->{auth}->{user}->{customer_id};
$host->{host} = $apr->param("host".$i);
$host->{ping_type} = $apr->param("ping_type".$i);
$host->{email} = $apr->param("email".$i);
$host->{pager_number} =
$apr->param("pager_number".$i);
$host->{paging_configuration_id} =
$apr->param("paging_configuration_id".$i);
if ($apr->param("delete".$i) eq "yes") {
$host->remove({DEBUG => 5});
} else {
$host->save({DEBUG => 5});
}
$i ++;
} else {
$done = 1;
}
}
my $params = { main_script => '/Monitoring', error_msg =>
$p->{error_msg} };
return $R->template->handler( {}, $params, { db => 'view_options',
package => 'monitoring' } );
}
Thanks!
Chris McDaniel
|