summaryrefslogtreecommitdiff
path: root/FS/FS/sched_item.pm
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2014-04-05 16:46:14 -0700
committerIvan Kohler <ivan@freeside.biz>2014-04-05 16:46:14 -0700
commita57c537ff9ef2a57de3225fbd49772be4b81e74c (patch)
tree538fc696500b9402806bca35861f2dafaba6f54b /FS/FS/sched_item.pm
parent7c0748c7e439cdbc14ced38c21e782f4669f9b15 (diff)
installers, RT#16584
Diffstat (limited to 'FS/FS/sched_item.pm')
-rw-r--r--FS/FS/sched_item.pm40
1 files changed, 39 insertions, 1 deletions
diff --git a/FS/FS/sched_item.pm b/FS/FS/sched_item.pm
index 5f55188..de792a3 100644
--- a/FS/FS/sched_item.pm
+++ b/FS/FS/sched_item.pm
@@ -2,7 +2,8 @@ package FS::sched_item;
use base qw( FS::Record );
use strict;
-#use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( dbh ); # qsearch qsearchs );
+use FS::sched_avail;
=head1 NAME
@@ -109,6 +110,43 @@ sub name {
$access_user ? $access_user->name : $self->itemname;
}
+=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