service dependencies: UI, RT#33685
[freeside.git] / FS / FS / part_svc_link.pm
1 package FS::part_svc_link;
2 use base qw( FS::Record );
3
4 use strict;
5 use FS::Record qw( qsearchs ); # qw( qsearch qsearchs );
6
7 =head1 NAME
8
9 FS::part_svc_link - Object methods for part_svc_link records
10
11 =head1 SYNOPSIS
12
13   use FS::part_svc_link;
14
15   $record = new FS::part_svc_link \%hash;
16   $record = new FS::part_svc_link { 'column' => 'value' };
17
18   $error = $record->insert;
19
20   $error = $new_record->replace($old_record);
21
22   $error = $record->delete;
23
24   $error = $record->check;
25
26 =head1 DESCRIPTION
27
28 An FS::part_svc_link object represents an service definition dependency.
29 FS::part_svc_link inherits from FS::Record.  The following fields are currently
30 supported:
31
32 =over 4
33
34 =item svclinknum
35
36 primary key
37
38 =cut
39
40 #=item linkname
41 #
42 #Dependency name
43
44 =item agentnum
45
46 Empty for global dependencies, or agentnum (see L<FS::agent>) for
47 agent-specific dependencies
48
49 =item src_svcpart
50
51 Source service definition (see L<FS::part_svc>)
52
53 =item dst_svcpart
54
55 Destination service definition (see L<FS::part_svc>)
56
57 =item link_type
58
59 Link type:
60
61 =over 4
62
63 =cut
64
65 # XXX false laziness w/edit/part_svc_link.html
66
67 =item part_svc_restrict
68
69 In package defintions, require the destination service definition when the
70 source service definition is included
71
72 =item part_svc_restrict_soft
73
74 Soft order block: in package definitions, warn if the destination service
75 definition is included without the source service definition
76
77 =item cust_svc_provision_restrict
78
79 Require the destination service to be provisioned before the source service
80
81 =item cust_svc_unprovision_restrict
82
83 Require the destination service to be unprovisioned before the source service
84
85 =item cust_svc_unprovision_cascade
86
87 Automatically unprovision the destination service when the source service is
88 unprovisioned
89
90 =item cust_svc_suspend_cascade
91
92 Suspend the destination service before the source service
93
94 =back
95
96 =back
97
98 =head1 METHODS
99
100 =over 4
101
102 =item new HASHREF
103
104 Creates a new record.  To add the record to the database, see L<"insert">.
105
106 Note that this stores the hash reference, not a distinct copy of the hash it
107 points to.  You can ask the object for a copy with the I<hash> method.
108
109 =cut
110
111 # the new method can be inherited from FS::Record, if a table method is defined
112
113 sub table { 'part_svc_link'; }
114
115 =item insert
116
117 Adds this record to the database.  If there is an error, returns the error,
118 otherwise returns false.
119
120 =item delete
121
122 Delete this record from the database.
123
124 =item replace OLD_RECORD
125
126 Replaces the OLD_RECORD with this one in the database.  If there is an error,
127 returns the error, otherwise returns false.
128
129 =item check
130
131 Checks all fields to make sure this is a valid record.  If there is
132 an error, returns the error, otherwise returns false.  Called by the insert
133 and replace methods.
134
135 =cut
136
137 sub check {
138   my $self = shift;
139
140   my $error = 
141     $self->ut_numbern('svclinknum')
142     #|| $self->ut_textn('linkname')
143     || $self->ut_number('src_svcpart')
144     || $self->ut_number('dst_svcpart')
145     || $self->ut_text('link_type')
146     || $self->ut_enum('disabled', [ '', 'Y' ])
147   ;
148   return $error if $error;
149
150   $self->SUPER::check;
151 }
152
153 =item description
154
155 Returns an extended description of this dependency, including.  Exact wording
156 depends on I<link_type>.
157
158 =cut
159
160 sub description {
161   my $self = shift;
162
163   my $src = $self->src_part_svc->svc;
164   my $dst = $self->dst_part_svc->svc;
165
166   #maybe sub-classes with overrides at some point
167   #  (and hooks each place we have manual checks for the various rules)
168   # but this will do for now
169
170   $self->link_type eq 'part_svc_restrict'
171    and return "In package definitions, $dst is required when $src is included";
172
173   $self->link_type eq 'part_svc_restrict_soft'
174    and return "In package definitions, $dst is suggested when $src is included";
175
176   $self->link_type eq 'cust_svc_provision_restrict'
177    and return "Require $dst provisioning before $src";
178
179   $self->link_type eq 'cust_svc_unprovision_restrict'
180    and return "Require $dst unprovisioning before $src";
181
182   $self->link_type eq 'cust_svc_unprovision_cascade'
183    and return "Automatically unprovision $dst when $src is unprovisioned";
184
185   $self->link_type eq 'cust_svc_suspend_cascade'
186    and return "Suspend $dst before $src";
187
188   warn "WARNING: unknown part_svc_link.link_type ". $self->link_type. "\n";
189   return "$src (unknown link_type ". $self->link_type. ") $dst";
190
191 }
192
193 =item src_part_svc 
194
195 Returns the source service definition, as an FS::part_svc object (see
196 L<FS::part_svc>).
197
198 =cut
199
200 sub src_part_svc {
201   my $self = shift;
202   qsearchs('part_svc', { svcpart=>$self->src_svcpart } );
203 }
204
205 =item src_svc
206
207 Returns the source service definition name (part_svc.svc).
208
209 =cut
210
211 sub src_svc {
212   shift->src_part_svc->svc;
213 }
214
215 =item dst_part_svc
216
217 Returns the destination service definition, as an FS::part_svc object (see
218 L<FS::part_svc>).
219
220 =cut
221
222
223 sub dst_part_svc {
224   my $self = shift;
225   qsearchs('part_svc', { svcpart=>$self->dst_svcpart } );
226 }
227
228 =item dst_svc
229
230 Returns the destination service definition name (part_svc.svc).
231
232 =cut
233
234 sub dst_svc {
235   shift->src_part_svc->svc;
236 }
237
238 =back
239
240 =head1 BUGS
241
242 =head1 SEE ALSO
243
244 L<FS::part_svc>, L<FS::Record>
245
246 =cut
247
248 1;
249