2 use base qw( FS::m2m_Common FS::Record );
5 use FS::Record qw( qsearchs qsearch dbh );
10 FS::router - Object methods for router records
16 $record = new FS::router \%hash;
17 $record = new FS::router { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $new_record->replace($old_record);
23 $error = $record->delete;
25 $error = $record->check;
29 An FS::router record describes a broadband router, such as a DSLAM or a wireless
30 access point. FS::router inherits from FS::Record. The following
31 fields are currently supported:
35 =item routernum - primary key
37 =item routername - descriptive name for the router
39 =item svcnum - svcnum of the owning FS::svc_broadband, if appropriate
41 =item manual_addr - set to 'Y' to allow services linked to this router
42 to have any IP address, rather than one in an address block belonging
53 Create a new record. To add the record to the database, see "insert".
57 sub table { 'router'; }
61 Adds this record to the database. If there is an error, returns the error,
62 otherwise returns false.
64 If the pseudo-field 'blocknum' is set to an L<FS::addr_block> number, then
65 that address block will be assigned to this router. Currently only one
66 block can be assigned this way.
71 my $oldAutoCommit = $FS::UID::AutoCommit;
72 local $FS::UID::AutoCommit = 0;
76 my $error = $self->SUPER::insert(@_);
77 return $error if $error;
78 if ( $self->blocknum ) {
79 my $block = FS::addr_block->by_key($self->blocknum);
81 if ($block->routernum) {
82 $error = "block ".$block->cidr." is already assigned to a router";
84 $block->set('routernum', $self->routernum);
85 $block->set('manual_flag', 'Y');
86 $error = $block->replace;
89 $error = "blocknum ".$self->blocknum." not found";
92 $dbh->rollback if $oldAutoCommit;
96 $dbh->commit if $oldAutoCommit;
100 =item replace OLD_RECORD
102 Replaces OLD_RECORD with this one in the database. If there is an error,
103 returns the error, otherwise returns false.
108 my $oldAutoCommit = $FS::UID::AutoCommit;
109 local $FS::UID::AutoCommit = 0;
113 my $old = shift || $self->replace_old;
114 my $error = $self->SUPER::replace($old, @_);
115 return $error if $error;
117 if ( defined($self->blocknum) ) {
118 #warn "FS::router::replace: blocknum = ".$self->blocknum."\n";
119 # then release any blocks we're already holding
120 foreach my $block ($self->addr_block) {
121 $block->set('routernum', 0);
122 $block->set('manual_flag', '');
123 $error ||= $block->replace;
125 if ( !$error and $self->blocknum > 0 ) {
126 # and, if the new blocknum is a real blocknum, assign it
127 my $block = FS::addr_block->by_key($self->blocknum);
129 $block->set('routernum', $self->routernum);
130 $block->set('manual_flag', '');
131 $error ||= $block->replace;
133 $error = "blocknum ".$self->blocknum." not found";
137 $dbh->rollback if $oldAutoCommit;
141 $dbh->commit if $oldAutoCommit;
147 Checks all fields to make sure this is a valid record. If there is an error,
148 returns the error, otherwise returns false. Called by the insert and replace
157 $self->ut_numbern('routernum')
158 || $self->ut_text('routername')
159 || $self->ut_enum('manual_addr', [ '', 'Y' ])
160 || $self->ut_agentnum_acl('agentnum', 'Broadband global configuration')
161 || $self->ut_foreign_keyn('svcnum', 'cust_svc', 'svcnum')
163 return $error if $error;
170 Deallocate all address blocks from this router and delete it.
177 my $oldAutoCommit = $FS::UID::AutoCommit;
178 local $FS::UID::AutoCommit = 0;
182 foreach my $block ($self->addr_block) {
183 $block->set('manual_flag', '');
184 $block->set('routernum', 0);
185 $error ||= $block->replace;
188 $error ||= $self->SUPER::delete;
190 $dbh->rollback if $oldAutoCommit;
194 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
200 Returns a list of FS::addr_block objects (address blocks) associated
203 =item auto_addr_block
205 Returns a list of address blocks on which auto-assignment of IP addresses
210 sub auto_addr_block {
212 return () if $self->manual_addr;
213 return qsearch('addr_block', { routernum => $self->routernum,
214 manual_flag => '' });
217 =item part_svc_router
219 Returns a list of FS::part_svc_router objects associated with this
220 object. This is unlikely to be useful for any purpose other than retrieving
221 the associated FS::part_svc objects. See below.
225 Returns a list of FS::part_svc objects associated with this object.
231 return map { qsearchs('part_svc', { svcpart => $_->svcpart }) }
232 $self->part_svc_router;
237 Returns the agent associated with this router, if any.
241 Returns the cust_svc associated with this router, if any. This should be
242 the service that I<provides connectivity to the router>, not any service
243 connected I<through> the router.
249 FS::svc_broadband, FS::router, FS::addr_block, FS::part_svc,
250 schema.html from the base documentation.