View | Details | Raw Unified | Return to bug 10337
Collapse All | Expand All

(-)a/misc/devel/populate_db.pl (-15 / +82 lines)
Lines 19-28 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Getopt::Long;
23
use Pod::Usage;
24
22
use C4::Installer;
25
use C4::Installer;
23
use C4::Context;
26
use C4::Context;
24
use t::lib::Mocks;
27
use t::lib::Mocks;
25
28
29
=head1 NAME
30
31
populate_db.pl - Load included sample data into the DB
32
33
=head1 SYNOPSIS
34
35
populate_db.pl [--marcflavour MARCFLAVOUR]
36
37
 Options:
38
   --help            Brief help message
39
   --marcflavour m   Specify the MARC flavour to use (MARC21|UNIMARC). Defaults
40
                                to MARC21.
41
   -v                Be verbose.
42
43
=head1 OPTIONS
44
45
=over 8
46
47
=item B<--help>
48
49
Prints a brief help message and exits.
50
51
=item B<--marcflavour>
52
53
Lets you choose the desired MARC flavour for the sample data. Valid options are MARC21 and UNIMARC.
54
It defaults to MARC21.
55
56
=item B<--verbose>
57
58
Make the output more verbose.
59
60
=back
61
62
=cut
63
64
my $help;
65
my $verbose;
66
my $marcflavour = 'MARC21';
67
68
GetOptions(
69
    'help|?'        => \$help,
70
    'verbose'       => \$verbose,
71
    'marcflavour=s' => \$marcflavour
72
) or pod2usage;
73
74
if ( $help ) {
75
    pod2usage;
76
}
77
78
if (     $marcflavour ne 'MARC21'
79
     and $marcflavour ne 'UNIMARC' ) {
80
    say "Invalid MARC flavour '$marcflavour' passed.";
81
    pod2usage;
82
}
83
26
$ENV{KOHA_DB_DO_NOT_RAISE_OR_PRINT_ERROR} = 1;
84
$ENV{KOHA_DB_DO_NOT_RAISE_OR_PRINT_ERROR} = 1;
27
my $dbh = C4::Context->dbh; # At the beginning to die if DB does not exist.
85
my $dbh = C4::Context->dbh; # At the beginning to die if DB does not exist.
28
86
Lines 57-63 initialize_data(); Link Here
57
update_database();
115
update_database();
58
116
59
sub initialize_data {
117
sub initialize_data {
60
    say "Inserting koha db structure...";
118
    say "Inserting koha db structure..."
119
        if $verbose;
61
    my $error = $installer->load_db_schema;
120
    my $error = $installer->load_db_schema;
62
    die $error if $error;
121
    die $error if $error;
63
122
Lines 73-103 sub initialize_data { Link Here
73
        execute_sqlfile($f);
132
        execute_sqlfile($f);
74
    }
133
    }
75
134
76
    for my $f (@marc21_sample_files_mandatory) {
135
    if ( $marcflavour eq 'UNIMARC' ) {
77
        execute_sqlfile($f);
136
        for my $f (@unimarc_sample_files_mandatory) {
137
            execute_sqlfile($f);
138
        }
139
    } else {
140
        for my $f (@marc21_sample_files_mandatory) {
141
            execute_sqlfile($f);
142
        }
78
    }
143
    }
79
144
80
    # set marcflavour (MARC21)
145
    # set marcflavour (MARC21)
81
    my $dbh = C4::Context->dbh;
146
    my $dbh = C4::Context->dbh;
82
    $dbh->do(
147
83
        q{
148
    say "Setting the MARC flavour on the sysprefs..."
149
        if $verbose;
150
    $dbh->do(qq{
84
        INSERT INTO `systempreferences` (variable,value,explanation,options,type)
151
        INSERT INTO `systempreferences` (variable,value,explanation,options,type)
85
        VALUES ('marcflavour','MARC21','Define global MARC flavor (MARC21 or UNIMARC) used for character encoding','MARC21|UNIMARC','Choice')
152
        VALUES ('marcflavour',?,'Define global MARC flavor (MARC21 or UNIMARC) used for character encoding','MARC21|UNIMARC','Choice')
86
    }
153
    },undef,$marcflavour);
87
    );
88
154
89
    # set version
155
    # set version
90
    $dbh->do(
156
    say "Setting Koha version to $version..."
91
        qq{
157
        if $verbose;
158
    $dbh->do(qq{
92
        INSERT INTO systempreferences(variable, value, options, explanation, type)
159
        INSERT INTO systempreferences(variable, value, options, explanation, type)
93
        VALUES ('Version', '$version', NULL, 'The Koha database version. WARNING: Do not change this value manually, it is maintained by the webinstaller', NULL)
160
        VALUES ('Version', '$version', NULL, 'The Koha database version. WARNING: Do not change this value manually, it is maintained by the webinstaller', NULL)
94
    }
161
    });
95
    );
96
}
162
}
97
163
98
sub execute_sqlfile {
164
sub execute_sqlfile {
99
    my ($filepath) = @_;
165
    my ($filepath) = @_;
100
    say "Inserting $filepath...";
166
    say "Inserting $filepath..."
167
        if $verbose;
101
    my $error = $installer->load_sql($filepath);
168
    my $error = $installer->load_sql($filepath);
102
    die $error if $error;
169
    die $error if $error;
103
}
170
}
Lines 111-117 sub get_version { Link Here
111
178
112
sub update_database {
179
sub update_database {
113
    my $update_db_path = $root . '/installer/data/mysql/updatedatabase.pl';
180
    my $update_db_path = $root . '/installer/data/mysql/updatedatabase.pl';
114
181
    say "Updating database..."
182
        if $verbose;
115
    my $file = `cat $update_db_path`;
183
    my $file = `cat $update_db_path`;
116
    $file =~ s/exit;//;
184
    $file =~ s/exit;//;
117
    eval $file;
185
    eval $file;
118
- 

Return to bug 10337