summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2004-07-30 04:54:41 +0000
committerivan <ivan>2004-07-30 04:54:41 +0000
commit918bbc9ce36a3dc5943f521e26751ea94a5a5539 (patch)
tree813ee68a86715499f673f884799b6c226f324845 /FS
parentc69dd0d922bba433b16e3408f71f1cac0e16a069 (diff)
svcpart changes now trigger all necessary export actions, manual svcpart changing on svc_acct view, linking changes svcpart if you ask it to, closes: Bug#671, Bug#644
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Conf.pm2
-rw-r--r--FS/FS/cust_svc.pm14
-rw-r--r--FS/FS/svc_Common.pm44
3 files changed, 49 insertions, 11 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index c4b214845..bfef62807 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -1237,7 +1237,7 @@ httemplate/docs/config.html
{
'key' => 'cust_pkg-change_svcpart',
'section' => '',
- 'description' => "When changing packages, move services even if svcparts don't match between old and new pacakge definitions. Use with caution! No provision is made for export differences between the old and new service definitions. Probably only should be used when your exports for all service definitions of a given svcdb are identical.",
+ 'description' => "When changing packages, move services even if svcparts don't match between old and new pacakge definitions.",
'type' => 'checkbox',
},
diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm
index 7ee9b3f40..118ab79d2 100644
--- a/FS/FS/cust_svc.pm
+++ b/FS/FS/cust_svc.pm
@@ -172,15 +172,9 @@ sub replace {
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
- my $error = $new->SUPER::replace($old);
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error if $error;
- }
-
if ( $new->svcpart != $old->svcpart ) {
my $svc_x = $new->svc_x;
- my $new_svc_x = ref($svc_x)->new({$svc_x->hash});
+ my $new_svc_x = ref($svc_x)->new({$svc_x->hash, svcpart=>$new->svcpart });
my $error = $new_svc_x->replace($svc_x);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
@@ -188,6 +182,12 @@ sub replace {
}
}
+ my $error = $new->SUPER::replace($old);
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error if $error;
+ }
+
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
''; #no error
diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm
index a22326696..38e656cd4 100644
--- a/FS/FS/svc_Common.pm
+++ b/FS/FS/svc_Common.pm
@@ -302,14 +302,52 @@ sub replace {
#new-style exports!
unless ( $noexport_hack ) {
- foreach my $part_export ( $new->cust_svc->part_svc->part_export ) {
- my $error = $part_export->export_replace($new,$old);
+
+ #not quite false laziness, but same pattern as FS::svc_acct::replace and
+ #FS::part_export::sqlradius::_export_replace. List::Compare or something
+ #would be useful but too much of a pain in the ass to deploy
+
+ my @old_part_export = $old->cust_svc->part_svc->part_export;
+ my %old_exportnum = map { $_->exportnum => 1 } @old_part_export;
+ my @new_part_export =
+ $new->svcpart
+ ? qsearchs('part_svc', { svcpart=>$new->svcpart } )->part_export
+ : $new->cust_svc->part_svc->part_export;
+ my %new_exportnum = map { $_->exportnum => 1 } @new_part_export;
+
+ foreach my $delete_part_export (
+ grep { ! $new_exportnum{$_->exportnum} } @old_part_export
+ ) {
+ my $error = $delete_part_export->export_delete($old);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
- return "error exporting to ". $part_export->exporttype.
+ return "error deleting, export to ". $delete_part_export->exporttype.
+ " (transaction rolled back): $error";
+ }
+ }
+
+ foreach my $replace_part_export (
+ grep { $old_exportnum{$_->exportnum} } @new_part_export
+ ) {
+ my $error = $replace_part_export->export_replace($new,$old);
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "error exporting to ". $replace_part_export->exporttype.
" (transaction rolled back): $error";
}
}
+
+ foreach my $insert_part_export (
+ grep { ! $old_exportnum{$_->exportnum} } @new_part_export
+ ) {
+ my $error = $insert_part_export->export_insert($new);
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "error inserting export to ". $insert_part_export->exporttype.
+ " (transaction rolled back): $error";
+ }
+ }
+
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;