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 { 'username' => 'fs_bootstrap',
187 '_password' => 'changeme', #will trigger warning if you try to enable
189 'first' => 'Bootstrap',
196 { 'groupname' => 'Superuser' },
202 #XXX need default new-style billing events
204 # 'part_bill_event' => [
205 # { 'payby' => 'CARD',
206 # 'event' => 'Batch card',
208 # 'eventcode' => '$cust_bill->batch_card(%options);',
210 # 'plan' => 'batch-card',
212 # { 'payby' => 'BILL',
213 # 'event' => 'Send invoice',
215 # 'eventcode' => '$cust_bill->send();',
219 # { 'payby' => 'DCRD',
220 # 'event' => 'Send invoice',
222 # 'eventcode' => '$cust_bill->send();',
226 # { 'payby' => 'DCHK',
227 # 'event' => 'Send invoice',
229 # 'eventcode' => '$cust_bill->send();',
233 # { 'payby' => 'DCLN',
234 # 'event' => 'Suspend',
236 # 'eventcode' => '$cust_bill->suspend();',
238 # 'plan' => 'suspend',
240 # #{ 'payby' => 'DCLN',
241 # # 'event' => 'Retriable',
243 # # 'eventcode' => '$cust_bill_event->retriable();',
245 # # 'plan' => 'retriable',
249 #you must create a service definition. An example of a service definition
250 #would be a dial-up account or a domain. First, it is necessary to create a
251 #domain definition. Click on View/Edit service definitions and Add a new
252 #service definition with Table svc_domain (and no modifiers).
255 'svcdb' => 'svc_domain',
259 #Now that you have created your first service, you must create a package
260 #including this service which you can sell to customers. Zero, one, or many
261 #services are bundled into a package. Click on View/Edit package
262 #definitions and Add a new package definition which includes quantity 1 of
263 #the svc_domain service you created above.
265 { 'pkg' => 'System Domain',
266 'comment' => '(NOT FOR CUSTOMERS)',
270 'pkg_svc' => { 1 => 1 }, # XXX
271 'primary_svc' => 1, #XXX
280 #After you create your first package, then you must define who is able to
281 #sell that package by creating an agent type. An example of an agent type
282 #would be an internal sales representitive which sells regular and
283 #promotional packages, as opposed to an external sales representitive
284 #which would only sell regular packages of services. Click on View/Edit
285 #agent types and Add a new agent type.
287 { 'atype' => 'Internal' },
290 #Allow this agent type to sell the package you created above.
292 { 'typenum' => 1, #XXX
297 #After creating a new agent type, you must create an agent. Click on
298 #View/Edit agents and Add a new agent.
300 { 'agent' => 'Internal',
301 'typenum' => 1, # XXX
305 #Set up at least one Advertising source. Advertising sources will help you
306 #keep track of how effective your advertising is, tracking where customers
307 #heard of your service offerings. You must create at least one advertising
308 #source. If you do not wish to use the referral functionality, simply
309 #create a single advertising source only. Click on View/Edit advertising
310 #sources and Add a new advertising source.
312 { 'referral' => 'Internal', },
315 #Click on New Customer and create a new customer for your system accounts
316 #with billing type Complimentary. Leave the First package dropdown set to
319 { 'agentnum' => 1, #XXX
322 'last' => 'Accounts',
323 'address1' => '1234 System Lane',
324 'city' => 'Systemtown',
329 'payinfo' => 'system', #or something
330 'paydate' => '1/2037',
334 #From the Customer View screen of the newly created customer, order the
335 #package you defined above.
337 { 'custnum' => 1, #XXX
342 #From the Package View screen of the newly created package, choose
343 #(Provision) to add the customer's service for this new package.
344 #Add your own domain.
346 { 'domain' => $opt{'domain'},
349 'action' => 'N', #pseudo-field
353 #Go back to View/Edit service definitions on the main menu, and Add a new
354 #service definition with Table svc_acct. Select your domain in the domsvc
355 #Modifier. Set Fixed to define a service locked-in to this domain, or
356 #Default to define a service which may select from among this domain and
357 #the customer's domains.
373 sub populate_access {
376 use FS::access_right;
378 foreach my $rightname ( FS::AccessRight->default_superuser_rights ) {
379 my $access_right = new FS::access_right {
380 'righttype' => 'FS::access_group',
381 'rightobjnum' => 1, #$supergroup->groupnum,
382 'rightname' => $rightname,
384 my $ar_error = $access_right->insert;
385 die $ar_error if $ar_error;
388 #foreach my $agent ( qsearch('agent', {} ) ) {
389 my $access_groupagent = new FS::access_groupagent {
390 'groupnum' => 1, #$supergroup->groupnum,
391 'agentnum' => 1, #$agent->agentnum,
393 my $aga_error = $access_groupagent->insert;
394 die $aga_error if $aga_error;
399 sub populate_msgcat {
401 use FS::Record qw(qsearch);
404 foreach my $del_msgcat ( qsearch('msgcat', {}) ) {
405 my $error = $del_msgcat->delete;
406 die $error if $error;
409 my %messages = msgcat_messages();
411 foreach my $msgcode ( keys %messages ) {
412 foreach my $locale ( keys %{$messages{$msgcode}} ) {
413 my $msgcat = new FS::msgcat( {
414 'msgcode' => $msgcode,
416 'msg' => $messages{$msgcode}{$locale},
418 my $error = $msgcat->insert;
419 die $error if $error;
425 sub msgcat_messages {
428 # 'en_US' => 'Message',
433 'passwords_dont_match' => {
434 'en_US' => "Passwords don't match",
438 'en_US' => 'Invalid credit card number',
441 'unknown_card_type' => {
442 'en_US' => 'Unknown card type',
449 'empty_password' => {
450 'en_US' => 'Empty password',
453 'no_access_number_selected' => {
454 'en_US' => 'No access number selected',
458 'en_US' => 'Illegal (text)',
459 #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in field',
462 'illegal_or_empty_text' => {
463 'en_US' => 'Illegal or empty (text)',
464 #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in required field',
467 'illegal_username' => {
468 'en_US' => 'Illegal username',
471 'illegal_password' => {
472 'en_US' => 'Illegal password (',
475 'illegal_password_characters' => {
476 'en_US' => ' characters)',
479 'username_in_use' => {
480 'en_US' => 'Username in use',
483 'phonenum_in_use' => {
484 'en_US' => 'Phone number in use',
487 'illegal_email_invoice_address' => {
488 'en_US' => 'Illegal email invoice address',
492 'en_US' => 'Illegal (name)',
493 #'en_US' => 'Only letters, numbers, spaces and the following punctuation symbols are permitted: , . - \' in field',
497 'en_US' => 'Illegal (phone)',
502 'en_US' => 'Illegal (zip)',
507 'en_US' => 'Expired card',
511 'en_US' => 'Day Phone',
515 'en_US' => 'Night Phone',
518 'svc_external-id' => {
519 'en_US' => 'External ID',
522 'svc_external-title' => {
527 'en_US' => 'Driver\'s License',
531 'en_US' => 'Driver\'s License State',
534 'invalid_domain' => {
535 'en_US' => 'Invalid domain',