4 use vars qw( @ISA @EXPORT_OK );
8 use FS::UID qw( dbh driver_name );
12 $FS::svc_domain::whois_hack = 1;
13 $FS::svc_domain::whois_hack = 1;
15 @ISA = qw( Exporter );
16 @EXPORT_OK = qw( create_initial_data );
20 FS::Setup - Database setup
28 Currently this module simply provides a place to store common subroutines for
39 sub create_initial_data {
42 my $oldAutoCommit = $FS::UID::AutoCommit;
43 local $FS::UID::AutoCommit = 0;
44 $FS::UID::AutoCommit = 0;
51 populate_initial_data(%opt);
57 if ( $oldAutoCommit ) {
58 dbh->commit or die dbh->errstr;
63 sub populate_locales {
66 use FS::cust_main_county;
69 foreach my $country ( sort map uc($_), all_country_codes ) {
70 _add_country($country);
75 sub populate_addl_locales {
79 'FM' => 'Federated States of Micronesia',
80 'MH' => 'Marshall Islands',
82 'AA' => "Armed Forces Americas (except Canada)",
83 'AE' => "Armed Forces Europe / Canada / Middle East / Africa",
84 'AP' => "Armed Forces Pacific",
88 foreach my $country ( keys %addl ) {
89 foreach my $state ( keys %{ $addl{$country} } ) {
90 # $longname = $addl{$country}{$state};
91 _add_locale( 'country'=>$country, 'state'=>$state);
99 use Locale::SubCountry;
101 my( $country ) = shift;
103 my $subcountry = eval { new Locale::SubCountry($country) };
104 my @states = $subcountry ? $subcountry->all_codes : undef;
106 if ( !scalar(@states) || ( scalar(@states)==1 && !defined($states[0]) ) ) {
108 _add_locale( 'country'=>$country );
112 if ( $states[0] =~ /^(\d+|\w)$/ ) {
113 @states = map $subcountry->full_name($_), @states
116 foreach my $state ( @states ) {
117 _add_locale( 'country'=>$country, 'state'=>$state);
125 my $cust_main_county = new FS::cust_main_county( { 'tax'=>0, @_ });
126 my $error = $cust_main_county->insert;
127 die $error if $error;
130 sub populate_duplock {
132 return unless driver_name =~ /^mysql/i;
134 my $sth = dbh->prepare(
135 "INSERT INTO duplicate_lock ( lockname ) VALUES ( 'svc_acct' )"
136 ) or die dbh->errstr;
138 $sth->execute or die $sth->errstr;
142 sub populate_initial_data {
145 my $data = initial_data(%opt);
147 foreach my $table ( keys %$data ) {
149 #warn "popuilating $table\n";
151 my $class = "FS::$table";
155 $class->_populate_initial_data(%opt)
156 if $class->can('_populate_initial_data');
158 my @records = @{ $data->{$table} };
160 foreach my $record ( @records ) {
162 my $args = delete($record->{'_insert_args'}) || [];
163 my $object = $class->new( $record );
164 my $error = $object->insert( @$args );
165 die "error inserting record into $table: $error\n"
168 #my $pkey = $object->primary_key;
169 #my $pkeyvalue = $object->$pkey();
170 #warn " inserted $pkeyvalue\n";
181 #tie my %hash, 'Tie::DxHash',
182 tie my %hash, 'Tie::IxHash',
186 { 'groupname' => 'Superuser' },
192 #XXX need default new-style billing events
194 # 'part_bill_event' => [
195 # { 'payby' => 'CARD',
196 # 'event' => 'Batch card',
198 # 'eventcode' => '$cust_bill->batch_card(%options);',
200 # 'plan' => 'batch-card',
202 # { 'payby' => 'BILL',
203 # 'event' => 'Send invoice',
205 # 'eventcode' => '$cust_bill->send();',
209 # { 'payby' => 'DCRD',
210 # 'event' => 'Send invoice',
212 # 'eventcode' => '$cust_bill->send();',
216 # { 'payby' => 'DCHK',
217 # 'event' => 'Send invoice',
219 # 'eventcode' => '$cust_bill->send();',
223 # { 'payby' => 'DCLN',
224 # 'event' => 'Suspend',
226 # 'eventcode' => '$cust_bill->suspend();',
228 # 'plan' => 'suspend',
230 # #{ 'payby' => 'DCLN',
231 # # 'event' => 'Retriable',
233 # # 'eventcode' => '$cust_bill_event->retriable();',
235 # # 'plan' => 'retriable',
239 #you must create a service definition. An example of a service definition
240 #would be a dial-up account or a domain. First, it is necessary to create a
241 #domain definition. Click on View/Edit service definitions and Add a new
242 #service definition with Table svc_domain (and no modifiers).
245 'svcdb' => 'svc_domain',
249 #Now that you have created your first service, you must create a package
250 #including this service which you can sell to customers. Zero, one, or many
251 #services are bundled into a package. Click on View/Edit package
252 #definitions and Add a new package definition which includes quantity 1 of
253 #the svc_domain service you created above.
255 { 'pkg' => 'System Domain',
256 'comment' => '(NOT FOR CUSTOMERS)',
260 'pkg_svc' => { 1 => 1 }, # XXX
261 'primary_svc' => 1, #XXX
270 #After you create your first package, then you must define who is able to
271 #sell that package by creating an agent type. An example of an agent type
272 #would be an internal sales representitive which sells regular and
273 #promotional packages, as opposed to an external sales representitive
274 #which would only sell regular packages of services. Click on View/Edit
275 #agent types and Add a new agent type.
277 { 'atype' => 'Internal' },
280 #Allow this agent type to sell the package you created above.
282 { 'typenum' => 1, #XXX
287 #After creating a new agent type, you must create an agent. Click on
288 #View/Edit agents and Add a new agent.
290 { 'agent' => 'Internal',
291 'typenum' => 1, # XXX
295 #Set up at least one Advertising source. Advertising sources will help you
296 #keep track of how effective your advertising is, tracking where customers
297 #heard of your service offerings. You must create at least one advertising
298 #source. If you do not wish to use the referral functionality, simply
299 #create a single advertising source only. Click on View/Edit advertising
300 #sources and Add a new advertising source.
302 { 'referral' => 'Internal', },
305 #Click on New Customer and create a new customer for your system accounts
306 #with billing type Complimentary. Leave the First package dropdown set to
309 { 'agentnum' => 1, #XXX
312 'last' => 'Accounts',
313 'address1' => '1234 System Lane',
314 'city' => 'Systemtown',
319 'payinfo' => 'system', #or something
320 'paydate' => '1/2037',
324 #From the Customer View screen of the newly created customer, order the
325 #package you defined above.
327 { 'custnum' => 1, #XXX
332 #From the Package View screen of the newly created package, choose
333 #(Provision) to add the customer's service for this new package.
334 #Add your own domain.
336 { 'domain' => $opt{'domain'},
339 'action' => 'N', #pseudo-field
343 #Go back to View/Edit service definitions on the main menu, and Add a new
344 #service definition with Table svc_acct. Select your domain in the domsvc
345 #Modifier. Set Fixed to define a service locked-in to this domain, or
346 #Default to define a service which may select from among this domain and
347 #the customer's domains.
362 sub populate_access {
365 use FS::access_right;
367 foreach my $rightname ( FS::AccessRight->default_superuser_rights ) {
368 my $access_right = new FS::access_right {
369 'righttype' => 'FS::access_group',
370 'rightobjnum' => 1, #$supergroup->groupnum,
371 'rightname' => $rightname,
373 my $ar_error = $access_right->insert;
374 die $ar_error if $ar_error;
377 #foreach my $agent ( qsearch('agent', {} ) ) {
378 my $access_groupagent = new FS::access_groupagent {
379 'groupnum' => 1, #$supergroup->groupnum,
380 'agentnum' => 1, #$agent->agentnum,
382 my $aga_error = $access_groupagent->insert;
383 die $aga_error if $aga_error;
388 sub populate_msgcat {
390 use FS::Record qw(qsearch);
393 foreach my $del_msgcat ( qsearch('msgcat', {}) ) {
394 my $error = $del_msgcat->delete;
395 die $error if $error;
398 my %messages = msgcat_messages();
400 foreach my $msgcode ( keys %messages ) {
401 foreach my $locale ( keys %{$messages{$msgcode}} ) {
402 my $msgcat = new FS::msgcat( {
403 'msgcode' => $msgcode,
405 'msg' => $messages{$msgcode}{$locale},
407 my $error = $msgcat->insert;
408 die $error if $error;
414 sub msgcat_messages {
417 # 'en_US' => 'Message',
422 'passwords_dont_match' => {
423 'en_US' => "Passwords don't match",
427 'en_US' => 'Invalid credit card number',
430 'unknown_card_type' => {
431 'en_US' => 'Unknown card type',
438 'empty_password' => {
439 'en_US' => 'Empty password',
442 'no_access_number_selected' => {
443 'en_US' => 'No access number selected',
447 'en_US' => 'Illegal (text)',
448 #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in field',
451 'illegal_or_empty_text' => {
452 'en_US' => 'Illegal or empty (text)',
453 #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in required field',
456 'illegal_username' => {
457 'en_US' => 'Illegal username',
460 'illegal_password' => {
461 'en_US' => 'Illegal password (',
464 'illegal_password_characters' => {
465 'en_US' => ' characters)',
468 'username_in_use' => {
469 'en_US' => 'Username in use',
472 'phonenum_in_use' => {
473 'en_US' => 'Phone number in use',
476 'illegal_email_invoice_address' => {
477 'en_US' => 'Illegal email invoice address',
481 'en_US' => 'Illegal (name)',
482 #'en_US' => 'Only letters, numbers, spaces and the following punctuation symbols are permitted: , . - \' in field',
486 'en_US' => 'Illegal (phone)',
491 'en_US' => 'Illegal (zip)',
496 'en_US' => 'Expired card',
500 'en_US' => 'Day Phone',
504 'en_US' => 'Night Phone',
507 'svc_external-id' => {
508 'en_US' => 'External ID',
511 'svc_external-title' => {
516 'en_US' => 'Driver\'s License',
520 'en_US' => 'Driver\'s License State',
523 'invalid_domain' => {
524 'en_US' => 'Invalid domain',