4 use vars qw( @ISA @EXPORT_OK );
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;
49 populate_initial_data(%opt);
55 if ( $oldAutoCommit ) {
56 dbh->commit or die dbh->errstr;
61 sub populate_locales {
64 use Locale::SubCountry;
65 use FS::cust_main_county;
68 foreach my $country ( sort map uc($_), all_country_codes ) {
70 my $subcountry = eval { new Locale::SubCountry($country) };
71 my @states = $subcountry ? $subcountry->all_codes : undef;
73 if ( !scalar(@states) || ( scalar(@states)==1 && !defined($states[0]) ) ) {
75 my $cust_main_county = new FS::cust_main_county({
77 'country' => $country,
79 my $error = $cust_main_county->insert;
84 if ( $states[0] =~ /^(\d+|\w)$/ ) {
85 @states = map $subcountry->full_name($_), @states
88 foreach my $state ( @states ) {
90 my $cust_main_county = new FS::cust_main_county({
93 'country' => $country,
95 my $error = $cust_main_county->insert;
105 sub populate_initial_data {
108 my $data = initial_data(%opt);
110 foreach my $table ( keys %$data ) {
112 my $class = "FS::$table";
116 my @records = @{ $data->{$table} };
118 foreach my $record ( @records ) {
119 my $args = delete($record->{'_insert_args'}) || [];
120 my $object = $class->new( $record );
121 my $error = $object->insert( @$args );
122 die "error inserting record into $table: $error\n"
133 #tie my %hash, 'Tie::DxHash',
134 tie my %hash, 'Tie::IxHash',
138 { 'groupname' => 'Superuser' },
142 'part_bill_event' => [
144 'event' => 'Batch card',
146 'eventcode' => '$cust_bill->batch_card();',
148 'plan' => 'batch-card',
151 'event' => 'Send invoice',
153 'eventcode' => '$cust_bill->send();',
158 'event' => 'Send invoice',
160 'eventcode' => '$cust_bill->send();',
165 'event' => 'Send invoice',
167 'eventcode' => '$cust_bill->send();',
172 'event' => 'Suspend',
174 'eventcode' => '$cust_bill->suspend();',
180 #you must create a service definition. An example of a service definition
181 #would be a dial-up account or a domain. First, it is necessary to create a
182 #domain definition. Click on View/Edit service definitions and Add a new
183 #service definition with Table svc_domain (and no modifiers).
186 'svcdb' => 'svc_domain',
190 #Now that you have created your first service, you must create a package
191 #including this service which you can sell to customers. Zero, one, or many
192 #services are bundled into a package. Click on View/Edit package
193 #definitions and Add a new package definition which includes quantity 1 of
194 #the svc_domain service you created above.
196 { 'pkg' => 'System Domain',
197 'comment' => '(NOT FOR CUSTOMERS)',
201 'pkg_svc' => { 1 => 1 }, # XXX
202 'primary_svc' => 1, #XXX
211 #After you create your first package, then you must define who is able to
212 #sell that package by creating an agent type. An example of an agent type
213 #would be an internal sales representitive which sells regular and
214 #promotional packages, as opposed to an external sales representitive
215 #which would only sell regular packages of services. Click on View/Edit
216 #agent types and Add a new agent type.
218 { 'atype' => 'internal' },
221 #Allow this agent type to sell the package you created above.
223 { 'typenum' => 1, #XXX
228 #After creating a new agent type, you must create an agent. Click on
229 #View/Edit agents and Add a new agent.
231 { 'agent' => 'Internal',
232 'typenum' => 1, # XXX
236 #Set up at least one Advertising source. Advertising sources will help you
237 #keep track of how effective your advertising is, tracking where customers
238 #heard of your service offerings. You must create at least one advertising
239 #source. If you do not wish to use the referral functionality, simply
240 #create a single advertising source only. Click on View/Edit advertising
241 #sources and Add a new advertising source.
243 { 'referral' => 'Internal', },
246 #Click on New Customer and create a new customer for your system accounts
247 #with billing type Complimentary. Leave the First package dropdown set to
250 { 'agentnum' => 1, #XXX
253 'last' => 'Accounts',
254 'address1' => '1234 System Lane',
255 'city' => 'Systemtown',
260 'payinfo' => 'system', #or something
261 'paydate' => '1/2037',
265 #From the Customer View screen of the newly created customer, order the
266 #package you defined above.
268 { 'custnum' => 1, #XXX
273 #From the Package View screen of the newly created package, choose
274 #(Provision) to add the customer's service for this new package.
275 #Add your own domain.
277 { 'domain' => $opt{'domain'},
280 'action' => 'N', #pseudo-field
284 #Go back to View/Edit service definitions on the main menu, and Add a new
285 #service definition with Table svc_acct. Select your domain in the domsvc
286 #Modifier. Set Fixed to define a service locked-in to this domain, or
287 #Default to define a service which may select from among this domain and
288 #the customer's domains.
299 sub populate_access {
302 use FS::access_right;
304 foreach my $rightname ( FS::AccessRight->rights ) {
305 my $access_right = new FS::access_right {
306 'righttype' => 'FS::access_group',
307 'rightobjnum' => 1, #$supergroup->groupnum,
308 'rightname' => $rightname,
310 my $ar_error = $access_right->insert;
311 die $ar_error if $ar_error;
314 #foreach my $agent ( qsearch('agent', {} ) ) {
315 my $access_groupagent = new FS::access_groupagent {
316 'groupnum' => 1, #$supergroup->groupnum,
317 'agentnum' => 1, #$agent->agentnum,
319 my $aga_error = $access_groupagent->insert;
320 die $aga_error if $aga_error;
325 sub populate_msgcat {
327 use FS::Record qw(qsearch);
330 foreach my $del_msgcat ( qsearch('msgcat', {}) ) {
331 my $error = $del_msgcat->delete;
332 die $error if $error;
335 my %messages = msgcat_messages();
337 foreach my $msgcode ( keys %messages ) {
338 foreach my $locale ( keys %{$messages{$msgcode}} ) {
339 my $msgcat = new FS::msgcat( {
340 'msgcode' => $msgcode,
342 'msg' => $messages{$msgcode}{$locale},
344 my $error = $msgcat->insert;
345 die $error if $error;
351 sub msgcat_messages {
354 # 'en_US' => 'Message',
359 'passwords_dont_match' => {
360 'en_US' => "Passwords don't match",
364 'en_US' => 'Invalid credit card number',
367 'unknown_card_type' => {
368 'en_US' => 'Unknown card type',
375 'empty_password' => {
376 'en_US' => 'Empty password',
379 'no_access_number_selected' => {
380 'en_US' => 'No access number selected',
384 'en_US' => 'Illegal (text)',
385 #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in field',
388 'illegal_or_empty_text' => {
389 'en_US' => 'Illegal or empty (text)',
390 #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in required field',
393 'illegal_username' => {
394 'en_US' => 'Illegal username',
397 'illegal_password' => {
398 'en_US' => 'Illegal password (',
401 'illegal_password_characters' => {
402 'en_US' => ' characters)',
405 'username_in_use' => {
406 'en_US' => 'Username in use',
409 'illegal_email_invoice_address' => {
410 'en_US' => 'Illegal email invoice address',
414 'en_US' => 'Illegal (name)',
415 #'en_US' => 'Only letters, numbers, spaces and the following punctuation symbols are permitted: , . - \' in field',
419 'en_US' => 'Illegal (phone)',
424 'en_US' => 'Illegal (zip)',
429 'en_US' => 'Expired card',
433 'en_US' => 'Day Phone',
437 'en_US' => 'Night Phone',
440 'svc_external-id' => {
441 'en_US' => 'External ID',
444 'svc_external-title' => {