diff options
author | Ivan Kohler <ivan@freeside.biz> | 2014-04-05 16:46:19 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2014-04-05 16:46:19 -0700 |
commit | 2b6e316202d647312a479b72e95aaea373628d3f (patch) | |
tree | cfb216e09135321dc2bd224dc549727c4f917ec9 | |
parent | 6b1b9000d780aeb8a4978b655d4a8fdb549486d1 (diff) |
installers, RT#16584
-rw-r--r-- | FS/FS/sched_item.pm | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/FS/FS/sched_item.pm b/FS/FS/sched_item.pm index 04f25e8b8..50075a97c 100644 --- a/FS/FS/sched_item.pm +++ b/FS/FS/sched_item.pm @@ -2,7 +2,7 @@ package FS::sched_item; use base qw( FS::Record ); use strict; -use FS::Record qw( qsearch qsearchs ); +use FS::Record qw( qsearch qsearchs dbh ); use FS::access_user; use FS::sched_avail; @@ -122,6 +122,43 @@ sub sched_avail { } +=item replace_sched_avail SCHED_AVAIL, ... + +Replaces the existing availability schedule with the list of passed-in +FS::sched_avail objects + +=cut + +sub replace_sched_avail { + my( $self, @new_sched_avail ) = @_; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + foreach my $old_sched_avail ( $self->sched_avail ) { + my $error = $old_sched_avail->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + foreach my $new_sched_avail ( @new_sched_avail ) { + $new_sched_avail->itemnum( $self->itemnum ); + my $error = $new_sched_avail->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + ''; + +} + =back =head1 BUGS |