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 my $class = "FS::$table";
153 $class->_populate_initial_data(%opt)
154 if $class->can('_populate_inital_data');
156 my @records = @{ $data->{$table} };
158 foreach my $record ( @records ) {
159 my $args = delete($record->{'_insert_args'}) || [];
160 my $object = $class->new( $record );
161 my $error = $object->insert( @$args );
162 die "error inserting record into $table: $error\n"
173 #tie my %hash, 'Tie::DxHash',
174 tie my %hash, 'Tie::IxHash',
178 { 'groupname' => 'Superuser' },
184 #XXX need default new-style billing events
186 # 'part_bill_event' => [
187 # { 'payby' => 'CARD',
188 # 'event' => 'Batch card',
190 # 'eventcode' => '$cust_bill->batch_card(%options);',
192 # 'plan' => 'batch-card',
194 # { 'payby' => 'BILL',
195 # 'event' => 'Send invoice',
197 # 'eventcode' => '$cust_bill->send();',
201 # { 'payby' => 'DCRD',
202 # 'event' => 'Send invoice',
204 # 'eventcode' => '$cust_bill->send();',
208 # { 'payby' => 'DCHK',
209 # 'event' => 'Send invoice',
211 # 'eventcode' => '$cust_bill->send();',
215 # { 'payby' => 'DCLN',
216 # 'event' => 'Suspend',
218 # 'eventcode' => '$cust_bill->suspend();',
220 # 'plan' => 'suspend',
222 # #{ 'payby' => 'DCLN',
223 # # 'event' => 'Retriable',
225 # # 'eventcode' => '$cust_bill_event->retriable();',
227 # # 'plan' => 'retriable',
231 #you must create a service definition. An example of a service definition
232 #would be a dial-up account or a domain. First, it is necessary to create a
233 #domain definition. Click on View/Edit service definitions and Add a new
234 #service definition with Table svc_domain (and no modifiers).
237 'svcdb' => 'svc_domain',
241 #Now that you have created your first service, you must create a package
242 #including this service which you can sell to customers. Zero, one, or many
243 #services are bundled into a package. Click on View/Edit package
244 #definitions and Add a new package definition which includes quantity 1 of
245 #the svc_domain service you created above.
247 { 'pkg' => 'System Domain',
248 'comment' => '(NOT FOR CUSTOMERS)',
252 'pkg_svc' => { 1 => 1 }, # XXX
253 'primary_svc' => 1, #XXX
262 #After you create your first package, then you must define who is able to
263 #sell that package by creating an agent type. An example of an agent type
264 #would be an internal sales representitive which sells regular and
265 #promotional packages, as opposed to an external sales representitive
266 #which would only sell regular packages of services. Click on View/Edit
267 #agent types and Add a new agent type.
269 { 'atype' => 'internal' },
272 #Allow this agent type to sell the package you created above.
274 { 'typenum' => 1, #XXX
279 #After creating a new agent type, you must create an agent. Click on
280 #View/Edit agents and Add a new agent.
282 { 'agent' => 'Internal',
283 'typenum' => 1, # XXX
287 #Set up at least one Advertising source. Advertising sources will help you
288 #keep track of how effective your advertising is, tracking where customers
289 #heard of your service offerings. You must create at least one advertising
290 #source. If you do not wish to use the referral functionality, simply
291 #create a single advertising source only. Click on View/Edit advertising
292 #sources and Add a new advertising source.
294 { 'referral' => 'Internal', },
297 #Click on New Customer and create a new customer for your system accounts
298 #with billing type Complimentary. Leave the First package dropdown set to
301 { 'agentnum' => 1, #XXX
304 'last' => 'Accounts',
305 'address1' => '1234 System Lane',
306 'city' => 'Systemtown',
311 'payinfo' => 'system', #or something
312 'paydate' => '1/2037',
316 #From the Customer View screen of the newly created customer, order the
317 #package you defined above.
319 { 'custnum' => 1, #XXX
324 #From the Package View screen of the newly created package, choose
325 #(Provision) to add the customer's service for this new package.
326 #Add your own domain.
328 { 'domain' => $opt{'domain'},
331 'action' => 'N', #pseudo-field
335 #Go back to View/Edit service definitions on the main menu, and Add a new
336 #service definition with Table svc_acct. Select your domain in the domsvc
337 #Modifier. Set Fixed to define a service locked-in to this domain, or
338 #Default to define a service which may select from among this domain and
339 #the customer's domains.
350 sub populate_access {
353 use FS::access_right;
355 foreach my $rightname ( FS::AccessRight->rights ) {
356 my $access_right = new FS::access_right {
357 'righttype' => 'FS::access_group',
358 'rightobjnum' => 1, #$supergroup->groupnum,
359 'rightname' => $rightname,
361 my $ar_error = $access_right->insert;
362 die $ar_error if $ar_error;
365 #foreach my $agent ( qsearch('agent', {} ) ) {
366 my $access_groupagent = new FS::access_groupagent {
367 'groupnum' => 1, #$supergroup->groupnum,
368 'agentnum' => 1, #$agent->agentnum,
370 my $aga_error = $access_groupagent->insert;
371 die $aga_error if $aga_error;
376 sub populate_msgcat {
378 use FS::Record qw(qsearch);
381 foreach my $del_msgcat ( qsearch('msgcat', {}) ) {
382 my $error = $del_msgcat->delete;
383 die $error if $error;
386 my %messages = msgcat_messages();
388 foreach my $msgcode ( keys %messages ) {
389 foreach my $locale ( keys %{$messages{$msgcode}} ) {
390 my $msgcat = new FS::msgcat( {
391 'msgcode' => $msgcode,
393 'msg' => $messages{$msgcode}{$locale},
395 my $error = $msgcat->insert;
396 die $error if $error;
402 sub msgcat_messages {
405 # 'en_US' => 'Message',
410 'passwords_dont_match' => {
411 'en_US' => "Passwords don't match",
415 'en_US' => 'Invalid credit card number',
418 'unknown_card_type' => {
419 'en_US' => 'Unknown card type',
426 'empty_password' => {
427 'en_US' => 'Empty password',
430 'no_access_number_selected' => {
431 'en_US' => 'No access number selected',
435 'en_US' => 'Illegal (text)',
436 #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in field',
439 'illegal_or_empty_text' => {
440 'en_US' => 'Illegal or empty (text)',
441 #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in required field',
444 'illegal_username' => {
445 'en_US' => 'Illegal username',
448 'illegal_password' => {
449 'en_US' => 'Illegal password (',
452 'illegal_password_characters' => {
453 'en_US' => ' characters)',
456 'username_in_use' => {
457 'en_US' => 'Username in use',
460 'illegal_email_invoice_address' => {
461 'en_US' => 'Illegal email invoice address',
465 'en_US' => 'Illegal (name)',
466 #'en_US' => 'Only letters, numbers, spaces and the following punctuation symbols are permitted: , . - \' in field',
470 'en_US' => 'Illegal (phone)',
475 'en_US' => 'Illegal (zip)',
480 'en_US' => 'Expired card',
484 'en_US' => 'Day Phone',
488 'en_US' => 'Night Phone',
491 'svc_external-id' => {
492 'en_US' => 'External ID',
495 'svc_external-title' => {
500 'en_US' => 'Driver\'s License',
504 'en_US' => 'Driver\'s License State',