1 |
use warnings; |
2 |
use strict; |
3 |
|
4 |
package Transports::Bootstrap; |
5 |
use base qw(Jifty::Bootstrap); |
6 |
|
7 |
=head1 Bootstrap application data |
8 |
|
9 |
Create initial data |
10 |
|
11 |
=cut |
12 |
|
13 |
sub run { |
14 |
my $self = shift; |
15 |
|
16 |
my $system_user = Transports::CurrentUser->superuser( _bootstrap => 1 ); |
17 |
|
18 |
my $u1 = Transports::Model::User->new(current_user => $system_user); |
19 |
$u1->create( |
20 |
name => 'System administrator', |
21 |
email => 'admin@example.com', |
22 |
password => 'admin', |
23 |
admin => 1, |
24 |
); |
25 |
|
26 |
my $u2 = Transports::Model::User->new(current_user => $system_user); |
27 |
$u2->create( |
28 |
name => 'Normal User', |
29 |
email => 'user@example.com', |
30 |
password => 'user', |
31 |
); |
32 |
|
33 |
my $s; |
34 |
|
35 |
foreach my $i ( 0 ... 5 ) { |
36 |
$s->{$i} = Transports::Model::Source->new(current_user => $system_user); |
37 |
$s->{$i}->create( |
38 |
name => 'SRC/' . ($i + 1), |
39 |
); |
40 |
|
41 |
Transports::Model::UserOnSource->new(current_user => $system_user)->create( |
42 |
user_on => $u1, |
43 |
source => $s->{$i}, |
44 |
); |
45 |
|
46 |
Transports::Model::UserOnSource->new(current_user => $system_user)->create( |
47 |
user_on => $u2, |
48 |
source => $s->{$i}, |
49 |
) if ($i % 2 == 0); |
50 |
} |
51 |
|
52 |
my $d; |
53 |
|
54 |
foreach my $i ( 0 ... 2 ) { |
55 |
$d->{$i} = Transports::Model::Destination->new(current_user => $system_user); |
56 |
$d->{$i}->create( |
57 |
name => 'DEST/' . ($i + 1), |
58 |
); |
59 |
} |
60 |
|
61 |
my $tc1 = Transports::Model::TransportClass->new(current_user => $system_user); |
62 |
$tc1->create( |
63 |
name => 'Default', |
64 |
); |
65 |
|
66 |
my $tc2 = Transports::Model::TransportClass->new(current_user => $system_user); |
67 |
$tc2->create( |
68 |
name => 'Upgrade', |
69 |
); |
70 |
|
71 |
foreach my $i ( 1 ... 7 ) { |
72 |
my $t = Transports::Model::Transport->new(current_user => $system_user); |
73 |
$t->create( |
74 |
class => $i % 4 == 0 ? $tc2 : $tc1, |
75 |
source => $s->{ $i % 5 }, |
76 |
destination => $d->{ $i % 2 }, |
77 |
request_nr => $i, |
78 |
client_dependent => $i % 3 == 0 ? 0 : 1, |
79 |
created_by => $i % 2 == 0 ? $u1 : $u2, |
80 |
); |
81 |
} |
82 |
|
83 |
} |
84 |
|
85 |
|
86 |
1; |