| 1 | package MojoMojo::Schema; | ||||||||||||||||||||||
| 2 | 40 | ▶ | use Moose; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 3 | |||||||||||||||||||||||
| 4 | 40 | our $VERSION = '1'; | |||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | 40 | has 'attachment_dir' => ( is => 'rw', isa => 'Str' ); | |||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 40 | ▶ | use parent 'DBIx::Class::Schema'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 40 | __PACKAGE__->load_namespaces( default_resultset_class => '+MojoMojo::Schema::Base::ResultSet' ); | |||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | MojoMojo::Schema - DBIC Schema | ||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | =head1 METHODS | ||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | =head2 create_initial_data | ||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | Creates initial set of data in the database which is necessary to run MojoMojo. | ||||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||||
| 23 | |||||||||||||||||||||||
| 24 | 6 | ▶ | sub create_initial_data { | ||||||||||||||||||||
|
Subroutine
create_initial_data: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||
| 25 | 6 | my ($schema, $config, $custom_values) = @_; | |||||||||||||||||||||
| 26 | |||||||||||||||||||||||
| 27 | 6 | my $file = __PACKAGE__ . ".pm"; | |||||||||||||||||||||
| 28 | 6 | $file =~ s{::}{/}g; | |||||||||||||||||||||
| 29 | 6 | my $path = $INC{$file}; | |||||||||||||||||||||
| 30 | 6 | $path =~ s{Schema\.pm$}{I18N}; | |||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | 6 | require Locale::Maketext::Simple; | |||||||||||||||||||||
| 33 | 6 | Locale::Maketext::Simple->import( | |||||||||||||||||||||
| 34 | Decode => 1, | ||||||||||||||||||||||
| 35 | Class => 'MojoMojo', | ||||||||||||||||||||||
| 36 | Path => $path, | ||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||
| 38 | 6 | ▶ | my $lang = $config->{'default_lang'} || 'en'; | ||||||||||||||||||||
|
Condition50%1/2
$config->{'default_lang'} || 'en'
MC/DC0%0/1
$config->{'default_lang'} || 'en'
$config->{'default_lang'}
Truth table50%1/2
A
A= $config->{'default_lang'}
| |||||||||||||||||||||||
| 39 | 6 | $lang =~ s/\..*$//; | |||||||||||||||||||||
| 40 | 6 | loc_lang($lang); | |||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | 6 | ▶ | my $default_user = $ENV{USER} || 'admin'; | ||||||||||||||||||||
|
Condition50%1/2
$ENV{'USER'} || 'admin'
MC/DC0%0/1
$ENV{'USER'} || 'admin'
$ENV{'USER'}
Truth table50%1/2
A
A= $ENV{'USER'}
| |||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | 6 | ▶ | $custom_values ||= { | ||||||||||||||||||||
|
Condition50%1/2
$custom_values ||= {"wiki_name", "MojoMojo", "admin_username", "admin", "admin_password", "admin", "admin_fullname", $default_user, "admin_email", "$default_user\@localhost", "anonymous_email", "anonymous.coward\@localhost"}
MC/DC0%0/1
$custom_values ||= {"wiki_name", "MojoMojo", "admin_username", "admin", "admin_password", "admin", "admin_fullname", $default_user, "admin_email", "$default_user\@localhost", "anonymous_email", "anonymous.coward\@localhost"}
$custom_values
Truth table50%1/2
A
A= $custom_values
| |||||||||||||||||||||||
| 45 | wiki_name => 'MojoMojo', | ||||||||||||||||||||||
| 46 | admin_username => 'admin', | ||||||||||||||||||||||
| 47 | admin_password => 'admin', | ||||||||||||||||||||||
| 48 | admin_fullname => $default_user, | ||||||||||||||||||||||
| 49 | admin_email => "$default_user\@localhost", | ||||||||||||||||||||||
| 50 | anonymous_email => 'anonymous.coward@localhost', | ||||||||||||||||||||||
| 51 | }; | ||||||||||||||||||||||
| 52 | |||||||||||||||||||||||
| 53 | 6 | print "Creating initial data\n"; | |||||||||||||||||||||
| 54 | |||||||||||||||||||||||
| 55 | my @people = $schema->populate( | ||||||||||||||||||||||
| 56 | 'Person', | ||||||||||||||||||||||
| 57 | [ | ||||||||||||||||||||||
| 58 | [ | ||||||||||||||||||||||
| 59 | qw/ active views photo login name email pass timezone born gender occupation industry interests movies music / | ||||||||||||||||||||||
| 60 | ], | ||||||||||||||||||||||
| 61 | [ | ||||||||||||||||||||||
| 62 | 1, 0, 0, loc('anonymouscoward'), loc('Anonymous Coward'), $custom_values->{anonymous_email}, | ||||||||||||||||||||||
| 63 | '', '', undef, '', '', '', '', '', '' | ||||||||||||||||||||||
| 64 | ], | ||||||||||||||||||||||
| 65 | [ | ||||||||||||||||||||||
| 66 | 1, 0, 0, $custom_values->{admin_username}, $custom_values->{admin_fullname}, $custom_values->{admin_email}, | ||||||||||||||||||||||
| 67 | 6 | $custom_values->{admin_password}, '', undef, '', '', '', '', '', '' | |||||||||||||||||||||
| 68 | ], | ||||||||||||||||||||||
| 69 | ] | ||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | 6 | my @roles = $schema->populate( | |||||||||||||||||||||
| 73 | 'Role', | ||||||||||||||||||||||
| 74 | [ | ||||||||||||||||||||||
| 75 | [ qw/ name active / ], | ||||||||||||||||||||||
| 76 | [ loc('Admins'), 1 ], | ||||||||||||||||||||||
| 77 | [ loc('Users'), 1 ], | ||||||||||||||||||||||
| 78 | [ loc('Anonymous'), 1 ] | ||||||||||||||||||||||
| 79 | ] | ||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||
| 81 | |||||||||||||||||||||||
| 82 | 6 | my @role_members = $schema->populate( | |||||||||||||||||||||
| 83 | 'RoleMember', | ||||||||||||||||||||||
| 84 | [ | ||||||||||||||||||||||
| 85 | [ qw/role person admin/ ], | ||||||||||||||||||||||
| 86 | [ $roles[0]->id, $people[1]->id, 1 ], | ||||||||||||||||||||||
| 87 | [ $roles[2]->id, $people[0]->id, 0 ] | ||||||||||||||||||||||
| 88 | ] | ||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | 6 | my @path_permissions = $schema->populate( | |||||||||||||||||||||
| 92 | 'PathPermissions', | ||||||||||||||||||||||
| 93 | [ | ||||||||||||||||||||||
| 94 | [ qw/path role apply_to_subpages create_allowed delete_allowed edit_allowed view_allowed attachment_allowed / ], | ||||||||||||||||||||||
| 95 | [ '/', $roles[0]->id, qw/ no yes yes yes yes yes / ], | ||||||||||||||||||||||
| 96 | [ '/', $roles[0]->id, qw/yes yes yes yes yes yes / ], | ||||||||||||||||||||||
| 97 | [ '/', $roles[1]->id, qw/ no yes no yes yes yes / ], | ||||||||||||||||||||||
| 98 | [ '/', $roles[1]->id, qw/yes yes no yes yes yes / ], | ||||||||||||||||||||||
| 99 | [ '/', $roles[2]->id, qw/ no yes no yes yes no / ], | ||||||||||||||||||||||
| 100 | [ '/', $roles[2]->id, qw/yes yes no yes yes no / ] | ||||||||||||||||||||||
| 101 | ] | ||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||
| 103 | |||||||||||||||||||||||
| 104 | |||||||||||||||||||||||
| 105 | my @prefs = $schema->populate( | ||||||||||||||||||||||
| 106 | 'Preference', | ||||||||||||||||||||||
| 107 | [ | ||||||||||||||||||||||
| 108 | [qw/ prefkey prefvalue /], | ||||||||||||||||||||||
| 109 | [ 'name', $custom_values->{wiki_name} ], | ||||||||||||||||||||||
| 110 | [ 'admins', $custom_values->{admin_username} ], | ||||||||||||||||||||||
| 111 | [ 'theme', $config->{'theme'} || 'default' ], | ||||||||||||||||||||||
| 112 | 6 | ▶ | [ 'open_registration', $config->{'open_registration'} || 1 ], | ||||||||||||||||||||
|
Condition50%2/4
$config->{'theme'} || 'default'
$config->{'open_registration'} || 1
MC/DC0%0/1
$config->{'theme'} || 'default'
$config->{'theme'}
MC/DC0%0/1
$config->{'open_registration'} || 1
$config->{'open_registration'}
Truth table50%1/2
A
A= $config->{'theme'}
Truth table50%1/2
A
A= $config->{'open_registration'}
| |||||||||||||||||||||||
| 113 | [ 'anonymous_user', 'anonymouscoward' ], | ||||||||||||||||||||||
| 114 | ] | ||||||||||||||||||||||
| 115 | ); | ||||||||||||||||||||||
| 116 | |||||||||||||||||||||||
| 117 | 6 | my @pages = $schema->populate( | |||||||||||||||||||||
| 118 | 'Page', | ||||||||||||||||||||||
| 119 | [ | ||||||||||||||||||||||
| 120 | [qw/ version parent name name_orig depth lft rgt content_version /], | ||||||||||||||||||||||
| 121 | [ undef, undef, '/', '/', 0, 1, 5, undef ], | ||||||||||||||||||||||
| 122 | [ undef, 1, 'help', loc('Help'), 1, 2, 3, undef ], | ||||||||||||||||||||||
| 123 | [ undef, 1, 'admin', 'Admin', 1, 4, 5, undef ], | ||||||||||||||||||||||
| 124 | ] | ||||||||||||||||||||||
| 125 | ); | ||||||||||||||||||||||
| 126 | |||||||||||||||||||||||
| 127 | 6 | my @pageversions = $schema->populate( | |||||||||||||||||||||
| 128 | 'PageVersion', | ||||||||||||||||||||||
| 129 | [ | ||||||||||||||||||||||
| 130 | [ | ||||||||||||||||||||||
| 131 | qw/page version parent parent_version name name_orig depth | ||||||||||||||||||||||
| 132 | content_version_first content_version_last creator status created | ||||||||||||||||||||||
| 133 | release_date remove_date comments/ | ||||||||||||||||||||||
| 134 | ], | ||||||||||||||||||||||
| 135 | [ | ||||||||||||||||||||||
| 136 | 1, 1, undef, undef, '/', '/', 0, undef, undef, $people[1]->id, '', 0, '', '', '' | ||||||||||||||||||||||
| 137 | ], | ||||||||||||||||||||||
| 138 | [ | ||||||||||||||||||||||
| 139 | 2, 1, 1, undef, 'help', 'Help', 0, undef, undef, $people[1]->id, '', 0, '', '', | ||||||||||||||||||||||
| 140 | '' | ||||||||||||||||||||||
| 141 | ], | ||||||||||||||||||||||
| 142 | [ | ||||||||||||||||||||||
| 143 | 3, 1, 1, undef, 'admin', 'Admin', 0, undef, undef, $people[1]->id, '', 0, '', | ||||||||||||||||||||||
| 144 | '', '' | ||||||||||||||||||||||
| 145 | ], | ||||||||||||||||||||||
| 146 | ] | ||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||
| 148 | |||||||||||||||||||||||
| 149 | 6 | my @content = $schema->populate( | |||||||||||||||||||||
| 150 | 'Content', | ||||||||||||||||||||||
| 151 | [ | ||||||||||||||||||||||
| 152 | [ | ||||||||||||||||||||||
| 153 | qw/ page version creator created body status release_date remove_date type abstract comments | ||||||||||||||||||||||
| 154 | precompiled / | ||||||||||||||||||||||
| 155 | ], | ||||||||||||||||||||||
| 156 | [ | ||||||||||||||||||||||
| 157 | 1, 1, $people[1]->id, 0, loc('welcome message', "test"), | ||||||||||||||||||||||
| 158 | 'released', 1, 1, '', '', '', '' | ||||||||||||||||||||||
| 159 | ], | ||||||||||||||||||||||
| 160 | [ | ||||||||||||||||||||||
| 161 | 2, 1, $people[1]->id, 0, loc('help message'), | ||||||||||||||||||||||
| 162 | 'released', 1, 1, '', '', '', '' | ||||||||||||||||||||||
| 163 | ], | ||||||||||||||||||||||
| 164 | [ | ||||||||||||||||||||||
| 165 | 3, 1, $people[1]->id, 0, loc('admin home page'), | ||||||||||||||||||||||
| 166 | 'released', 1, 1, '', '', '' | ||||||||||||||||||||||
| 167 | ], | ||||||||||||||||||||||
| 168 | ] | ||||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||||
| 170 | |||||||||||||||||||||||
| 171 | 6 | $schema->resultset('Page')->update( { version => 1 } ); | |||||||||||||||||||||
| 172 | 6 | $schema->resultset('Page')->update( { content_version => 1 } ); | |||||||||||||||||||||
| 173 | 6 | $schema->resultset('PageVersion')->update( { content_version_first => 1 } ); | |||||||||||||||||||||
| 174 | 6 | $schema->resultset('PageVersion')->update( { content_version_last => 1 } ); | |||||||||||||||||||||
| 175 | |||||||||||||||||||||||
| 176 | 6 | print "Success!\n"; | |||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||
| 178 | |||||||||||||||||||||||
| 179 | =head1 AUTHOR | ||||||||||||||||||||||
| 180 | |||||||||||||||||||||||
| 181 | Marcus Ramberg <mramberg@cpan.org> | ||||||||||||||||||||||
| 182 | |||||||||||||||||||||||
| 183 | =head1 LICENSE | ||||||||||||||||||||||
| 184 | |||||||||||||||||||||||
| 185 | This library is free software. You can redistribute it and/or modify | ||||||||||||||||||||||
| 186 | it under the same terms as Perl itself. | ||||||||||||||||||||||
| 187 | |||||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||||
| 189 | |||||||||||||||||||||||
| 190 | 40 | 1; | |||||||||||||||||||||