[freeside-commits] freeside/FS/FS Record.pm, 1.226.2.13, 1.226.2.14 Upgrade.pm, 1.52.2.5, 1.52.2.6 tower.pm, 1.1.2.2, 1.1.2.3 tower_sector.pm, 1.1.2.2, 1.1.2.3
Mark Wells
mark at wavetail.420.am
Thu Feb 9 17:58:21 PST 2012
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv21127/FS/FS
Modified Files:
Tag: FREESIDE_2_3_BRANCH
Record.pm Upgrade.pm tower.pm tower_sector.pm
Log Message:
allow towers without sectors, #16398 continued
Index: tower_sector.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/tower_sector.pm,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -w -d -r1.1.2.2 -r1.1.2.3
--- tower_sector.pm 10 Dec 2011 00:37:03 -0000 1.1.2.2
+++ tower_sector.pm 10 Feb 2012 01:58:19 -0000 1.1.2.3
@@ -137,7 +137,12 @@
sub description {
my $self = shift;
- $self->tower->towername. ' sector '. $self->sectorname;
+ if ( $self->sectorname eq '_default' ) {
+ $self->tower->towername
+ }
+ else {
+ $self->tower->towername. ' sector '. $self->sectorname
+ }
}
=back
Index: Upgrade.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Upgrade.pm,v
retrieving revision 1.52.2.5
retrieving revision 1.52.2.6
diff -u -w -d -r1.52.2.5 -r1.52.2.6
--- Upgrade.pm 14 Jan 2012 07:05:17 -0000 1.52.2.5
+++ Upgrade.pm 10 Feb 2012 01:58:18 -0000 1.52.2.6
@@ -263,6 +263,8 @@
'part_svc' => [],
'part_export' => [],
+ #insert default tower_sector if not present
+ 'tower',
;
\%hash;
Index: tower.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/tower.pm,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -w -d -r1.1.2.2 -r1.1.2.3
--- tower.pm 10 Dec 2011 00:37:03 -0000 1.1.2.2
+++ tower.pm 10 Feb 2012 01:58:18 -0000 1.1.2.3
@@ -2,8 +2,9 @@
use strict;
use base qw( FS::o2m_Common FS::Record );
-use FS::Record qw( qsearch ); #qsearchs );
+use FS::Record qw( qsearch qsearchs );
use FS::tower_sector;
+use List::Util qw( max );
=head1 NAME
@@ -69,16 +70,12 @@
=cut
-# the insert method can be inherited from FS::Record
-
=item delete
Delete this record from the database.
=cut
-# the delete method can be inherited from FS::Record
-
=item replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error,
@@ -112,10 +109,22 @@
$self->SUPER::check;
}
+=item default_sector
+
+Returns the default sector.
+
+=cut
+
+sub default_sector {
+ my $self = shift;
+ qsearchs('tower_sector', { towernum => $self->towernum,
+ sectorname => '_default' });
+}
+
=item tower_sector
Returns the sectors of this tower, as FS::tower_sector objects (see
-L<FS::tower_sector>).
+L<FS::tower_sector>), except for the default sector.
=cut
@@ -123,11 +132,56 @@
my $self = shift;
qsearch({
'table' => 'tower_sector',
- 'hashref' => { 'towernum' => $self->towernum },
+ 'hashref' => { 'towernum' => $self->towernum,
+ 'sectorname' => { op => '!=', value => '_default' },
+ },
'order_by' => 'ORDER BY sectorname',
});
}
+=item process_o2m
+
+Wrapper for the default method (see L<FS::o2m_Common>) to manage the
+default sector.
+
+=cut
+
+sub process_o2m {
+ my $self = shift;
+ my %opt = @_;
+ my $params = $opt{params};
+
+ # Adjust to make sure our default sector is in the list.
+ my $default_sector = $self->default_sector
+ or warn "creating default sector for tower ".$self->towernum."\n";
+ my $idx = max(0, map { $_ =~ /^sectornum(\d+)$/ ? $1 : 0 } keys(%$params));
+ $idx++; # append to the param list
+ my $prefix = "sectornum$idx";
+ # empty sectornum will create the default sector if it doesn't exist yet
+ $params->{$prefix} = $default_sector ? $default_sector->sectornum : '';
+ $params->{$prefix.'_sectorname'} = '_default';
+ $params->{$prefix.'_ip_addr'} = $params->{'default_ip_addr'} || '';
+
+ $self->SUPER::process_o2m(%opt);
+}
+
+sub _upgrade_data {
+ # Create default sectors for any tower that doesn't have one.
+ # Shouldn't do any harm if they're missing, but just for completeness.
+ my $class = shift;
+ foreach my $tower (qsearch('tower',{})) {
+ next if $tower->default_sector;
+ my $sector = FS::tower_sector->new({
+ towernum => $tower->towernum,
+ sectorname => '_default',
+ ip_addr => '',
+ });
+ my $error = $sector->insert;
+ die "error creating default sector: $error\n" if $error;
+ }
+ '';
+}
+
=back
=head1 BUGS
Index: Record.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Record.pm,v
retrieving revision 1.226.2.13
retrieving revision 1.226.2.14
diff -u -w -d -r1.226.2.13 -r1.226.2.14
--- Record.pm 18 Jan 2012 02:48:56 -0000 1.226.2.13
+++ Record.pm 10 Feb 2012 01:58:18 -0000 1.226.2.14
@@ -985,10 +985,12 @@
my $error = $self->check;
return $error if $error;
- #single-field unique keys are given a value if false
+ #single-field non-null unique keys are given a value if empty
#(like MySQL's AUTO_INCREMENT or Pg SERIAL)
foreach ( $self->dbdef_table->unique_singles) {
- $self->unique($_) unless $self->getfield($_);
+ next if $self->getfield($_);
+ next if $self->dbdef_table->column($_)->null eq 'NULL';
+ $self->unique($_);
}
#and also the primary key, if the database isn't going to
More information about the freeside-commits
mailing list