5 use FS::Record qw( qsearchs qsearch dbh );
8 @ISA = qw( FS::Record FS::m2m_Common );
12 FS::router - Object methods for router records
18 $record = new FS::router \%hash;
19 $record = new FS::router { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::router record describes a broadband router, such as a DSLAM or a wireless
32 access point. FS::router inherits from FS::Record. The following
33 fields are currently supported:
37 =item routernum - primary key
39 =item routername - descriptive name for the router
41 =item svcnum - svcnum of the owning FS::svc_broadband, if appropriate
43 =item manual_addr - set to 'Y' to allow services linked to this router
44 to have any IP address, rather than one in an address block belonging
55 Create a new record. To add the record to the database, see "insert".
59 sub table { 'router'; }
63 Adds this record to the database. If there is an error, returns the error,
64 otherwise returns false.
66 If the pseudo-field 'blocknum' is set to an L<FS::addr_block> number, then
67 that address block will be assigned to this router. Currently only one
68 block can be assigned this way.
73 my $oldAutoCommit = $FS::UID::AutoCommit;
74 local $FS::UID::AutoCommit = 0;
78 my $error = $self->SUPER::insert(@_);
79 return $error if $error;
80 if ( $self->blocknum ) {
81 my $block = FS::addr_block->by_key($self->blocknum);
83 if ($block->routernum) {
84 $error = "block ".$block->cidr." is already assigned to a router";
86 $block->set('routernum', $self->routernum);
87 $block->set('manual_flag', 'Y');
88 $error = $block->replace;
91 $error = "blocknum ".$self->blocknum." not found";
94 $dbh->rollback if $oldAutoCommit;
98 $dbh->commit if $oldAutoCommit;
102 =item replace OLD_RECORD
104 Replaces OLD_RECORD with this one in the database. If there is an error,
105 returns the error, otherwise returns false.
110 my $oldAutoCommit = $FS::UID::AutoCommit;
111 local $FS::UID::AutoCommit = 0;
115 my $old = shift || $self->replace_old;
116 my $error = $self->SUPER::replace($old, @_);
117 return $error if $error;
119 if ( length($self->blocknum) ) {
120 #warn "FS::router::replace: blocknum = ".$self->blocknum."\n";
121 # then release any blocks we're already holding
122 foreach my $block ($self->addr_block) {
123 $block->set('routernum', 0);
124 $block->set('manual_flag', '');
125 $error ||= $block->replace;
127 if ( !$error and $self->blocknum > 0 ) {
128 # and, if the new blocknum is a real blocknum, assign it
129 my $block = FS::addr_block->by_key($self->blocknum);
131 $block->set('routernum', $self->routernum);
132 $block->set('manual_flag', '');
133 $error ||= $block->replace;
135 $error = "blocknum ".$self->blocknum." not found";
139 $dbh->rollback if $oldAutoCommit;
143 $dbh->commit if $oldAutoCommit;
149 Checks all fields to make sure this is a valid record. If there is an error,
150 returns the error, otherwise returns false. Called by the insert and replace
159 $self->ut_numbern('routernum')
160 || $self->ut_text('routername')
161 || $self->ut_enum('manual_addr', [ '', 'Y' ])
162 || $self->ut_agentnum_acl('agentnum', 'Broadband global configuration')
163 || $self->ut_foreign_keyn('svcnum', 'cust_svc', 'svcnum')
165 return $error if $error;
172 Deallocate all address blocks from this router and delete it.
179 my $oldAutoCommit = $FS::UID::AutoCommit;
180 local $FS::UID::AutoCommit = 0;
184 foreach my $block ($self->addr_block) {
185 $block->set('manual_flag', '');
186 $block->set('routernum', 0);
187 $error ||= $block->replace;
190 $error ||= $self->SUPER::delete;
192 $dbh->rollback if $oldAutoCommit;
196 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
202 Returns a list of FS::addr_block objects (address blocks) associated
209 qsearch('addr_block', { routernum => $self->routernum });
212 =item auto_addr_block
214 Returns a list of address blocks on which auto-assignment of IP addresses
219 sub auto_addr_block {
221 return () if $self->manual_addr;
222 return qsearch('addr_block', { routernum => $self->routernum,
223 manual_flag => '' });
226 =item part_svc_router
228 Returns a list of FS::part_svc_router objects associated with this
229 object. This is unlikely to be useful for any purpose other than retrieving
230 the associated FS::part_svc objects. See below.
234 sub part_svc_router {
236 return qsearch('part_svc_router', { routernum => $self->routernum });
241 Returns a list of FS::part_svc objects associated with this object.
247 return map { qsearchs('part_svc', { svcpart => $_->svcpart }) }
248 $self->part_svc_router;
253 Returns the agent associated with this router, if any.
258 qsearchs('agent', { 'agentnum' => shift->agentnum });
263 Returns the cust_svc associated with this router, if any. This should be
264 the service that I<provides connectivity to the router>, not any service
265 connected I<through> the router.
270 my $svcnum = shift->svcnum or return undef;
271 FS::cust_svc->by_key($svcnum);
278 FS::svc_broadband, FS::router, FS::addr_block, FS::part_svc,
279 schema.html from the base documentation.