From 8c974f743b0312b5dc9ef26f403b937abb5003d3 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 30 Apr 2015 06:10:11 -0700 Subject: [PATCH] service dependencies: cust_svc_unprovision_restrict, RT#33685 --- FS/FS/cust_svc.pm | 29 +++++++++++++++++++++++++++++ FS/FS/svc_Common.pm | 3 ++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm index a7aeadaf1..2cf9103f4 100644 --- a/FS/FS/cust_svc.pm +++ b/FS/FS/cust_svc.pm @@ -456,6 +456,35 @@ sub check { $self->SUPER::check; } +=item check_part_svc_link_unprovision + +Checks service dependency unprovision rules for this service. + +If there is an error, returns the error, otherwise returns false. + +=cut + +sub check_part_svc_link_unprovision { + my $self = shift; + + foreach my $part_svc_link ( $self->part_svc_link( + link_type => 'cust_svc_unprovision_restrict', + ) + ) { + return $part_svc_link->dst_svc. ' must be unprovisioned before '. + $part_svc_link->src_svc + if qsearchs({ + 'table' => 'cust_svc', + 'hashref' => { 'pkgnum' => $self->pkgnum, + 'svcpart' => $part_svc_link->dst_svcpart, + }, + 'order_by' => 'LIMIT 1', + }); + } + + ''; +} + =item part_svc_link Returns the service dependencies (see L) for the given diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm index b1f9d146f..8d3b5353e 100644 --- a/FS/FS/svc_Common.pm +++ b/FS/FS/svc_Common.pm @@ -395,7 +395,8 @@ sub delete { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $error = $self->predelete_hook_first + my $error = $self->cust_svc->check_part_svc_link_unprovision + || $self->predelete_hook_first || $self->SUPER::delete || $self->export('delete', @$export_args) || $self->return_inventory -- 2.11.0