From a7c1b602f88c177db34477ed4cdc1f72603f8995 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 11 Apr 2002 22:05:31 +0000 Subject: [PATCH] (almost) everything for bug#375 - create export_svc table - part_svc to part_export is now properly many-to-many, not one-to-many still need to finish service editing (choosing exports) in httemplate/edit/part_svc.cgi and httemplate/edti/process/part_svc.cgi and do somethinga about that manual $svcdb = 'svc_acct' in httemplate/edit/part_export.cgi (do part_export records need a svcdb? probably not... should be able to just pass an svcdb on creation of new exports, move the big %exports hash into part_export.pm and allow httemplate/edit/part_svc.cgi to query it for exports that can apply to a given svcdb.... --- FS/FS.pm | 3 + FS/FS/export_svc.pm | 123 ++++++++++++++++++++++++++++++++ FS/FS/part_export.pm | 89 +++++++++++++++-------- FS/FS/part_svc.pm | 9 ++- FS/MANIFEST | 2 + FS/t/export_svc.t | 5 ++ README.1.4.0pre12 | 11 +++ bin/fs-setup | 15 +++- bin/sqlradius_reset | 8 ++- httemplate/browse/part_export.cgi | 42 +++++++++++ httemplate/browse/part_svc.cgi | 25 +------ httemplate/docs/schema.html | 7 +- httemplate/docs/upgrade8.html | 10 ++- httemplate/edit/part_export.cgi | 39 +++------- httemplate/edit/process/part_export.cgi | 3 +- httemplate/index.html | 2 + httemplate/misc/delete-part_export.cgi | 2 +- 17 files changed, 301 insertions(+), 94 deletions(-) create mode 100644 FS/FS/export_svc.pm create mode 100644 FS/t/export_svc.t create mode 100755 httemplate/browse/part_export.cgi diff --git a/FS/FS.pm b/FS/FS.pm index 60831ecd5..36fabcb8e 100644 --- a/FS/FS.pm +++ b/FS/FS.pm @@ -57,6 +57,9 @@ L - Service definition class L - Column constraint class +L - Class linking service definitions (see L) +with exports (see L) + L - External provisioning export class L - Export option class diff --git a/FS/FS/export_svc.pm b/FS/FS/export_svc.pm new file mode 100644 index 000000000..da9ac698a --- /dev/null +++ b/FS/FS/export_svc.pm @@ -0,0 +1,123 @@ +package FS::export_svc; + +use strict; +use vars qw( @ISA ); +use FS::Record qw( qsearch qsearchs ); +use FS::part_export; +use FS::part_svc; + +@ISA = qw(FS::Record); + +=head1 NAME + +FS::export_svc - Object methods for export_svc records + +=head1 SYNOPSIS + + use FS::export_svc; + + $record = new FS::export_svc \%hash; + $record = new FS::export_svc { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::export_svc object links a service definition (see L) to +an export (see L). FS::export_svc inherits from FS::Record. +The following fields are currently supported: + +=over 4 + +=item exportsvcnum - primary key + +=item exportnum - export (see L) + +=item svcpart - service definition (see L) + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new record. To add the record to the database, see L<"insert">. + +Note that this stores the hash reference, not a distinct copy of the hash it +points to. You can ask the object for a copy with the I method. + +=cut + +# the new method can be inherited from FS::Record, if a table method is defined + +sub table { 'export_svc'; } + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=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, +returns the error, otherwise returns false. + +=cut + +# the replace method can be inherited from FS::Record + +=item check + +Checks all fields to make sure this is a valid record. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +# the check method should currently be supplied - FS::Record contains some +# data checking routines + +sub check { + my $self = shift; + + $self->ut_numbern('exportsvcnum') + || $self->ut_number('exportnum') + || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum') + || $self->ut_number('svcpart') + || $self->ut_foreign_key('svcpart', 'part_svc', 'svcpart') + ; +} + +=back + +=head1 BUGS + +=head1 SEE ALSO + +L, L, L, schema.html from the base +documentation. + +=cut + +1; + diff --git a/FS/FS/part_export.pm b/FS/FS/part_export.pm index a43c3844e..8af413b1d 100644 --- a/FS/FS/part_export.pm +++ b/FS/FS/part_export.pm @@ -5,6 +5,7 @@ use vars qw( @ISA ); use FS::Record qw( qsearch qsearchs dbh ); use FS::part_svc; use FS::part_export_option; +use FS::export_svc; @ISA = qw(FS::Record); @@ -19,7 +20,7 @@ FS::part_export - Object methods for part_export records $record = new FS::part_export \%hash; $record = new FS::part_export { 'column' => 'value' }; - ($new_record, $options) = $template_recored->clone( $svcpart ); + #($new_record, $options) = $template_recored->clone( $svcpart ); $error = $record->insert( { 'option' => 'value' } ); $error = $record->insert( \%options ); @@ -40,8 +41,6 @@ fields are currently supported: =item exportnum - primary key -=item svcpart - Service definition (see L) to which this export applies - =item machine - Machine name =item exporttype - Export type @@ -67,27 +66,29 @@ points to. You can ask the object for a copy with the I method. sub table { 'part_export'; } -=item clone SVCPART - -An alternate constructor. Creates a new export by duplicating an existing -export. The given svcpart is assigned to the new export. - -Returns a list consisting of the new export object and a hashref of options. - =cut -sub clone { - my $self = shift; - my $class = ref($self); - my %hash = $self->hash; - $hash{'exportnum'} = ''; - $hash{'svcpart'} = shift; - ( $class->new( \%hash ), - { map { $_->optionname => $_->optionvalue } - qsearch('part_export_option', { 'exportnum' => $self->exportnum } ) - } - ); -} +#=item clone SVCPART +# +#An alternate constructor. Creates a new export by duplicating an existing +#export. The given svcpart is assigned to the new export. +# +#Returns a list consisting of the new export object and a hashref of options. +# +#=cut +# +#sub clone { +# my $self = shift; +# my $class = ref($self); +# my %hash = $self->hash; +# $hash{'exportnum'} = ''; +# $hash{'svcpart'} = shift; +# ( $class->new( \%hash ), +# { map { $_->optionname => $_->optionvalue } +# qsearch('part_export_option', { 'exportnum' => $self->exportnum } ) +# } +# ); +#} =item insert HASHREF @@ -173,6 +174,14 @@ sub delete { } } + foreach my $export_svc ( $self->export_svc ) { + my $error = $export_svc->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; @@ -258,13 +267,11 @@ sub check { my $error = $self->ut_numbern('exportnum') || $self->ut_domain('machine') - || $self->ut_number('svcpart') || $self->ut_alpha('exporttype') ; return $error if $error; - return "Unknown svcpart: ". $self->svcpart - unless qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } ); + warn $self->machine. "!!!\n"; $self->machine =~ /^([\w\-\.]*)$/ or return "Illegal machine: ". $self->machine; @@ -273,20 +280,39 @@ sub check { $self->nodomain =~ /^(Y?)$/ or return "Illegal nodomain: ". $self->nodomain; $self->nodomain($1); + $self->deprecated(1); #BLAH + #check exporttype? ''; #no error } -=item part_svc +#=item part_svc +# +#Returns the service definition (see L) for this export. +# +#=cut +# +#sub part_svc { +# my $self = shift; +# qsearchs('part_svc', { svcpart => $self->svcpart } ); +#} + +sub part_svc { + use Carp; + croak "FS::part_export::part_svc deprecated"; + #confess "FS::part_export::part_svc deprecated"; +} + +=item export_svc -Returns the service definition (see L) for this export. +Returns a list of associated FS::export_svc records. =cut -sub part_svc { +sub export_svc { my $self = shift; - qsearchs('part_svc', { svcpart => $self->svcpart } ); + qsearch('export_svc', { 'exportnum' => $self->exportnum } ); } =item part_export_option @@ -413,9 +439,12 @@ Probably. Hmm... cust_export class (not necessarily a database table...) ... ? +deprecated column... + =head1 SEE ALSO -L, L, L, L, +L, L, L, +L, L, L, schema.html from the base documentation. =cut diff --git a/FS/FS/part_svc.pm b/FS/FS/part_svc.pm index 7ef996f5f..959a3f887 100644 --- a/FS/FS/part_svc.pm +++ b/FS/FS/part_svc.pm @@ -5,6 +5,7 @@ use vars qw( @ISA ); use FS::Record qw( qsearch qsearchs fields dbh ); use FS::part_svc_column; use FS::part_export; +use FS::export_svc; @ISA = qw(FS::Record); @@ -316,15 +317,15 @@ sub all_part_svc_column { sub part_export { my $self = shift; - my %search = ( 'svcpart' => $self->svcpart ); - qsearch('part_export', \%search); + map { qsearchs('part_export', { 'exportnum' => $_->exportnum } ) } + qsearch('export_svc', { 'svcpart' => $self->svcpart } ); } =back =head1 VERSION -$Id: part_svc.pm,v 1.12 2002-03-26 13:58:29 ivan Exp $ +$Id: part_svc.pm,v 1.13 2002-04-11 22:05:31 ivan Exp $ =head1 BUGS @@ -333,6 +334,8 @@ Delete is unimplemented. The list of svc_* tables is hardcoded. When svc_acct_pop is renamed, this should be fixed. +all_part_svc_column and part_export methods should be documented + =head1 SEE ALSO L, L, L, L, diff --git a/FS/MANIFEST b/FS/MANIFEST index dd9eb0906..440c75565 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -45,6 +45,7 @@ FS/cust_refund.pm FS/cust_credit_refund.pm FS/cust_svc.pm FS/part_bill_event.pm +FS/export_svc.pm FS/part_export.pm FS/part_export_option.pm FS/part_export/infostreet.pm @@ -97,6 +98,7 @@ t/cust_svc.t t/domain_record.t t/nas.t t/part_bill_event.t +t/export_svc.t t/part_export.t t/part_export_option.t t/part_export-infostreet.t diff --git a/FS/t/export_svc.t b/FS/t/export_svc.t new file mode 100644 index 000000000..773c5dea7 --- /dev/null +++ b/FS/t/export_svc.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::export_svc; +$loaded=1; +print "ok 1\n"; diff --git a/README.1.4.0pre12 b/README.1.4.0pre12 index ea1f95229..e8fdd3070 100644 --- a/README.1.4.0pre12 +++ b/README.1.4.0pre12 @@ -32,6 +32,17 @@ CREATE TABLE msgcat ( ); CREATE INDEX msgcat1 ON msgcat ( msgcode, locale ); +CREATE TABLE export_svc ( + exportsvcnum int primary key, + exportnum int not null, + svcpart int not null +); +CREATE UNIQUE INDEX export_svc1 ON export_svc ( exportnum, svcpart ); +CREATE INDEX export_svc2 ON export_svc ( exportnum ); +CREATE INDEX export_svc3 ON export_svc ( svcpart ); + +ALTER TABLE part_export RENAME svcpart TO deprecated; + Run bin/dbdef-create Run bin/create-history-tables diff --git a/bin/fs-setup b/bin/fs-setup index 2da0431bb..535408891 100755 --- a/bin/fs-setup +++ b/bin/fs-setup @@ -1,6 +1,6 @@ #!/usr/bin/perl -Tw # -# $Id: fs-setup,v 1.86 2002-04-10 08:39:47 ivan Exp $ +# $Id: fs-setup,v 1.87 2002-04-11 22:05:31 ivan Exp $ #to delay loading dbdef until we're ready BEGIN { $FS::Record::setup_hack = 1; } @@ -927,10 +927,21 @@ sub tables_hash_hack { 'index' => [ [ 'jobnum' ] ], }, + 'export_svc' => { + 'columns' => [ + 'exportsvcnum' => 'int', '', '', + 'exportnum' => 'int', '', '', + 'svcpart' => 'int', '', '', + ] + 'primary_key' => 'exportsvcnum', + 'unique' => [ [ 'exportnum', 'svcpart' ] ], + 'index' => [ [ 'exportnum' ], [ 'svcpart' ] ], + }, + 'part_export' => { 'columns' => [ 'exportnum', 'int', '', '', - 'svcpart', 'int', '', '', + #'svcpart', 'int', '', '', 'machine', 'varchar', '', $char_d, 'exporttype', 'varchar', '', $char_d, 'nodomain', 'char', 'NULL', 1, diff --git a/bin/sqlradius_reset b/bin/sqlradius_reset index da98fe6be..454043f54 100644 --- a/bin/sqlradius_reset +++ b/bin/sqlradius_reset @@ -25,9 +25,15 @@ foreach my $export ( @exports ) { } foreach my $export ( @exports ) { + + #my @svcparts = map { $_->svcpart } $export->export_svc; + my @svc_acct = map { qsearchs('svc_acct', { 'svcnum' => $_->svcnum } ) } - qsearch('cust_svc', { 'svcpart' => $export->part_svc->svcpart } ); + map { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) } + grep { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) } + $export->export_svc; + foreach my $svc_acct ( @svc_acct ) { #false laziness with FS::svc_acct::insert (like it matters) diff --git a/httemplate/browse/part_export.cgi b/httemplate/browse/part_export.cgi new file mode 100755 index 000000000..e9d9fa3d4 --- /dev/null +++ b/httemplate/browse/part_export.cgi @@ -0,0 +1,42 @@ + +<%= header("Export Listing", menubar( 'Main Menu' => $p )) %> +Provisioning services to external machines, databases and APIs.

+ + + +<%= table() %> + + Export + Options + + +<% foreach my $part_export ( sort { + $a->getfield('exportnum') <=> $b->getfield('exportnum') + } qsearch('part_export',{}) ) { +%> + + <%= $part_export->exportnum %> + <%= $part_export->exporttype %> to <%= $part_export->machine %> (edit | delete) + + <%= itable() %> + <% my %opt = $part_export->options; + foreach my $opt ( keys %opt ) { %> + <%= $opt %><%= $opt{$opt} %> + <% } %> + + + + +<% } %> + + + Add a new export + + + + diff --git a/httemplate/browse/part_svc.cgi b/httemplate/browse/part_svc.cgi index 250b1ff4e..c8adebcd6 100755 --- a/httemplate/browse/part_svc.cgi +++ b/httemplate/browse/part_svc.cgi @@ -70,31 +70,8 @@ function part_export_areyousure(href) { foreach my $part_export ( @part_export ) { %> - <%= $part_export->exporttype %> to <%= $part_export->machine %> (edit | delete) - - <%= itable() %> - <% my %opt = $part_export->options; - foreach my $opt ( keys %opt ) { %> - <%= $opt %><%= $opt{$opt} %> - <% } %> - - + <%= $part_export->exporttype %> to <%= $part_export->machine %> <% } %> - Add a new export -<% if (@part_export) { %> - -
- - - -
-<% } %> <% my($n1)=''; diff --git a/httemplate/docs/schema.html b/httemplate/docs/schema.html index a7c21c7c9..6ed96d229 100644 --- a/httemplate/docs/schema.html +++ b/httemplate/docs/schema.html @@ -256,10 +256,15 @@
  • svcpart - Service definition
  • quantity - quantity of this service that this package includes +
  • export_svc +
  • part_export - Export to external provisioning
    • exportnum - primary key -
    • svcpart - Service definition
    • machine - Machine name
    • exporttype - Export type
    • nodomain - blank or Y: usernames are exported to this service with no domain diff --git a/httemplate/docs/upgrade8.html b/httemplate/docs/upgrade8.html index d1b13fe9c..841a053ed 100644 --- a/httemplate/docs/upgrade8.html +++ b/httemplate/docs/upgrade8.html @@ -152,9 +152,17 @@ CREATE TABLE part_bill_event ( ); CREATE INDEX part_bill_event1 ON part_bill_event ( payby ); +CREATE TABLE export_svc ( + exportsvcnum int primary key, + exportnum int not null, + svcpart int not null +); +CREATE UNIQUE INDEX export_svc1 ON export_svc ( exportnum, svcpart ); +CREATE INDEX export_svc2 ON export_svc ( exportnum ); +CREATE INDEX export_svc3 ON export_svc ( svcpart ); + CREATE TABLE part_export ( exportnum int primary key, - svcpart int not null, machine varchar(80) not null, exporttype varchar(80) not null, nodomain char(1) NULL diff --git a/httemplate/edit/part_export.cgi b/httemplate/edit/part_export.cgi index 0ca964e02..f3127403e 100644 --- a/httemplate/edit/part_export.cgi +++ b/httemplate/edit/part_export.cgi @@ -6,34 +6,18 @@ #} else { # $cgi->param('clone', ''); #} -#if ( $cgi->param('svcpart') && $cgi->param('svcpart') =~ /^(\d+)$/ ) { -# $cgi->param('svcpart', $1); -#} else { -# $cgi->param('svcpart', ''); -#} my($query) = $cgi->keywords; my $action = ''; my $part_export = ''; -my $options = {}; if ( $cgi->param('error') ) { $part_export = new FS::part_export ( { map { $_, scalar($cgi->param($_)) } fields('part_export') } ); -} - -#warn "***$query***"; -if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) { - $action = 'Add'; - my $old_part_export = qsearchs('part_export', { 'exportnum' => $1 } ); - unless ( $part_export ) { - ($part_export, $options) = $old_part_export->clone($cgi->param('svcpart')); - } -} elsif ( $cgi->param('new_with_svcpart') - && $cgi->param('new_with_svcpart') =~ /^(\d+)$/ ) { - $part_export ||= new FS::part_export ( { 'svcpart' => $1 } ); } elsif ( $query =~ /^(\d+)$/ ) { - $part_export ||= qsearchs('part_export', { 'exportnum' => $1 } ); + $part_export = qsearchs('part_export', { 'exportnum' => $1 } ); +} else { + $part_export = new FS::part_export; } $action ||= $part_export->exportnum ? 'Edit' : 'Add'; @@ -101,18 +85,20 @@ my %exports = ( ); -my $svcdb = $part_export->part_svc->svcdb; +#my $svcdb = $part_export->part_svc->svcdb; +#YUCK +my $svcdb = 'svc_acct'; + my %layers = map { $_ => "$_ - ". $exports{$svcdb}{$_}{desc} } keys %{$exports{$svcdb}}; $layers{''}=''; my $widget = new HTML::Widgets::SelectLayers( 'selected_layer' => $part_export->exporttype, - 'selected_layer' => $part_export->exporttype, 'options' => \%layers, 'form_name' => 'dummy', 'form_action' => 'process/part_export.cgi', - 'form_text' => [qw( exportnum svcpart machine )], + 'form_text' => [qw( exportnum machine )], # 'form_checkbox' => [qw()], 'html_between' => "\n", 'layer_callback' => sub { @@ -123,7 +109,7 @@ my $widget = new HTML::Widgets::SelectLayers( # foreach my $option ( qw(url login password groupID ) ) { my $optinfo = $exports{$svcdb}->{$layer}{options}{$option}; my $label = $optinfo->{label}; - my $value = $part_export->option($option); + my $value = $cgi->param($option) || $part_export->option($option); $html .= qq!$label!. qq!!. ''; @@ -160,13 +146,6 @@ my $widget = new HTML::Widgets::SelectLayers( <%= ntable("#cccccc",2) %> - Service - - <%= $part_export->svcpart %> - <%= $part_export->part_svc->svc %> - - - - Export host diff --git a/httemplate/edit/process/part_export.cgi b/httemplate/edit/process/part_export.cgi index d0c87a02a..34eb699bf 100644 --- a/httemplate/edit/process/part_export.cgi +++ b/httemplate/edit/process/part_export.cgi @@ -18,6 +18,7 @@ my $error; if ( $exportnum ) { warn $old; warn $exportnum; + warn $new->machine; $error = $new->replace($old,\%options); } else { $error = $new->insert(\%options); @@ -28,7 +29,7 @@ if ( $error ) { $cgi->param('error', $error ); print $cgi->redirect(popurl(2). "part_export.cgi?". $cgi->query_string ); } else { - print $cgi->redirect(popurl(3). "browse/part_svc.cgi"); + print $cgi->redirect(popurl(3). "browse/part_export.cgi"); } %> diff --git a/httemplate/index.html b/httemplate/index.html index 99d8df956..c638aec16 100644 --- a/httemplate/index.html +++ b/httemplate/index.html @@ -167,6 +167,8 @@
      • View/Edit service definitions - Services are items you offer to your customers. +
      • View/Edit exports + - Provisioning services to external machines, databases and APIs.
      • View/Edit package definitions - One or more services are grouped together into a package and given pricing information. Customers purchase packages, not diff --git a/httemplate/misc/delete-part_export.cgi b/httemplate/misc/delete-part_export.cgi index a5166d944..34ef06b96 100755 --- a/httemplate/misc/delete-part_export.cgi +++ b/httemplate/misc/delete-part_export.cgi @@ -10,6 +10,6 @@ my $part_export = qsearchs('part_export',{'exportnum'=>$exportnum}); my $error = $part_export->delete; eidiot($error) if $error; -print $cgi->redirect($p. "browse/part_svc.cgi"); +print $cgi->redirect($p. "browse/part_export.cgi"); %> -- 2.11.0