Lines 1-5
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
|
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Copyright (C) YEAR YOURNAME-OR-YOUREMPLOYER |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
3 |
use strict; |
20 |
use strict; |
4 |
use warnings; |
21 |
use warnings; |
5 |
use diagnostics; |
22 |
use diagnostics; |
Lines 40-49
if ( defined($language) ) {
Link Here
|
40 |
my $installer = C4::Installer->new(); |
57 |
my $installer = C4::Installer->new(); |
41 |
my %info; |
58 |
my %info; |
42 |
$info{'dbname'} = C4::Context->config("database"); |
59 |
$info{'dbname'} = C4::Context->config("database"); |
43 |
$info{'dbms'} = |
60 |
$info{'dbms'} = ( |
44 |
( C4::Context->config("db_scheme") |
61 |
C4::Context->config("db_scheme") |
45 |
? C4::Context->config("db_scheme") |
62 |
? C4::Context->config("db_scheme") |
46 |
: "mysql" ); |
63 |
: "mysql" |
|
|
64 |
); |
47 |
$info{'hostname'} = C4::Context->config("hostname"); |
65 |
$info{'hostname'} = C4::Context->config("hostname"); |
48 |
$info{'port'} = C4::Context->config("port"); |
66 |
$info{'port'} = C4::Context->config("port"); |
49 |
$info{'user'} = C4::Context->config("user"); |
67 |
$info{'user'} = C4::Context->config("user"); |
Lines 65-76
my $dbh = DBI->connect(
Link Here
|
65 |
); |
83 |
); |
66 |
|
84 |
|
67 |
if ( $step && $step == 1 ) { |
85 |
if ( $step && $step == 1 ) { |
|
|
86 |
|
68 |
#First Step (for both fresh installations and upgrades) |
87 |
#First Step (for both fresh installations and upgrades) |
69 |
#Checking ALL perl Modules and services needed are installed. |
88 |
#Checking ALL perl Modules and services needed are installed. |
70 |
#Whenever there is an error, adding a report to the page |
89 |
#Whenever there is an error, adding a report to the page |
71 |
my $op = $query->param('op') || 'noop'; |
90 |
my $op = $query->param('op') || 'noop'; |
72 |
$template->param( language => 1 ); |
91 |
$template->param( language => 1 ); |
73 |
$template->param( 'checkmodule' => 1 ); # we start with the assumption that there are no problems and set this to 0 if there are |
92 |
$template->param( 'checkmodule' => 1 ) |
|
|
93 |
; # we start with the assumption that there are no problems and set this to 0 if there are |
74 |
|
94 |
|
75 |
unless ( $] >= 5.010000 ) { # Bug 7375 |
95 |
unless ( $] >= 5.010000 ) { # Bug 7375 |
76 |
$template->param( problems => 1, perlversion => 1, checkmodule => 0 ); |
96 |
$template->param( problems => 1, perlversion => 1, checkmodule => 0 ); |
Lines 80-90
if ( $step && $step == 1 ) {
Link Here
|
80 |
$perl_modules->versions_info; |
100 |
$perl_modules->versions_info; |
81 |
|
101 |
|
82 |
my $modules = $perl_modules->get_attr('missing_pm'); |
102 |
my $modules = $perl_modules->get_attr('missing_pm'); |
83 |
if (scalar(@$modules)) { |
103 |
if ( scalar(@$modules) ) { |
84 |
my @components = (); |
104 |
my @components = (); |
85 |
my $checkmodule = 1; |
105 |
my $checkmodule = 1; |
86 |
foreach (@$modules) { |
106 |
foreach (@$modules) { |
87 |
my ($module, $stats) = each %$_; |
107 |
my ( $module, $stats ) = each %$_; |
88 |
$checkmodule = 0 if $stats->{'required'}; |
108 |
$checkmodule = 0 if $stats->{'required'}; |
89 |
push( |
109 |
push( |
90 |
@components, |
110 |
@components, |
Lines 96-109
if ( $step && $step == 1 ) {
Link Here
|
96 |
} |
116 |
} |
97 |
); |
117 |
); |
98 |
} |
118 |
} |
99 |
@components = sort {$a->{'name'} cmp $b->{'name'}} @components; |
119 |
@components = sort { $a->{'name'} cmp $b->{'name'} } @components; |
100 |
$template->param( missing_modules => \@components, checkmodule => $checkmodule, op => $op ); |
120 |
$template->param( |
|
|
121 |
missing_modules => \@components, |
122 |
checkmodule => $checkmodule, |
123 |
op => $op |
124 |
); |
101 |
} |
125 |
} |
102 |
} |
126 |
} |
103 |
elsif ( $step && $step == 2 ) { |
127 |
elsif ( $step && $step == 2 ) { |
104 |
# |
128 |
|
105 |
#STEP 2 Check Database connection and access |
129 |
#STEP 2 Check Database connection and access |
106 |
# |
130 |
|
107 |
$template->param(%info); |
131 |
$template->param(%info); |
108 |
my $checkdb = $query->param("checkdb"); |
132 |
my $checkdb = $query->param("checkdb"); |
109 |
$template->param( 'dbconnection' => $checkdb ); |
133 |
$template->param( 'dbconnection' => $checkdb ); |
Lines 128-134
elsif ( $step && $step == 2 ) {
Link Here
|
128 |
my $grantaccess; |
152 |
my $grantaccess; |
129 |
while ( my ($line) = $rq->fetchrow ) { |
153 |
while ( my ($line) = $rq->fetchrow ) { |
130 |
my $dbname = $info{dbname}; |
154 |
my $dbname = $info{dbname}; |
131 |
if ( $line =~ m/^GRANT (.*?) ON `$dbname`\.\*/ || index( $line, '*.*' ) > 0 ) { |
155 |
if ( $line =~ m/^GRANT (.*?) ON `$dbname`\.\*/ |
|
|
156 |
|| index( $line, '*.*' ) > 0 ) |
157 |
{ |
132 |
$grantaccess = 1 |
158 |
$grantaccess = 1 |
133 |
if ( |
159 |
if ( |
134 |
index( $line, 'ALL PRIVILEGES' ) > 0 |
160 |
index( $line, 'ALL PRIVILEGES' ) > 0 |
Lines 163-185
elsif ( $step && $step == 2 ) {
Link Here
|
163 |
} |
189 |
} |
164 |
} |
190 |
} |
165 |
$template->param( "checkgrantaccess" => $grantaccess ); |
191 |
$template->param( "checkgrantaccess" => $grantaccess ); |
166 |
} # End mysql connect check... |
192 |
} # End mysql connect check... |
167 |
|
193 |
|
168 |
elsif ( $info{dbms} eq "Pg" ) { |
194 |
elsif ( $info{dbms} eq "Pg" ) { |
169 |
# Check if database has been created... |
195 |
|
170 |
my $rv = $dbh->do( "SELECT * FROM pg_catalog.pg_database WHERE datname = \'$info{dbname}\';" ); |
196 |
# Check if database has been created... |
171 |
if ( $rv == 1 ) { |
197 |
my $rv = $dbh->do( |
172 |
$template->param( 'checkdatabasecreated' => 1 ); |
198 |
"SELECT * FROM pg_catalog.pg_database WHERE datname = \'$info{dbname}\';" |
173 |
} |
199 |
); |
174 |
|
200 |
if ( $rv == 1 ) { |
175 |
# Check if user has all necessary grants on this database... |
201 |
$template->param( 'checkdatabasecreated' => 1 ); |
176 |
my $rq = $dbh->do( "SELECT u.usesuper |
202 |
} |
177 |
FROM pg_catalog.pg_user as u |
203 |
|
178 |
WHERE u.usename = \'$info{user}\';" ); |
204 |
# Check if user has all necessary grants on this database... |
179 |
if ( $rq == 1 ) { |
205 |
my $rq = $dbh->do( |
180 |
$template->param( "checkgrantaccess" => 1 ); |
206 |
"SELECT u.usesuper |
181 |
} |
207 |
FROM pg_catalog.pg_user as u |
182 |
} # End Pg connect check... |
208 |
WHERE u.usename = \'$info{user}\';" |
|
|
209 |
); |
210 |
if ( $rq == 1 ) { |
211 |
$template->param( "checkgrantaccess" => 1 ); |
212 |
} |
213 |
} # End Pg connect check... |
183 |
} |
214 |
} |
184 |
else { |
215 |
else { |
185 |
$template->param( "error" => DBI::err, "message" => DBI::errstr ); |
216 |
$template->param( "error" => DBI::err, "message" => DBI::errstr ); |
Lines 187-197
elsif ( $step && $step == 2 ) {
Link Here
|
187 |
} |
218 |
} |
188 |
} |
219 |
} |
189 |
elsif ( $step && $step == 3 ) { |
220 |
elsif ( $step && $step == 3 ) { |
190 |
# |
221 |
|
191 |
# |
222 |
# STEP 3 : database setup |
192 |
# STEP 3 : database setup |
223 |
|
193 |
# |
|
|
194 |
# |
195 |
my $op = $query->param('op'); |
224 |
my $op = $query->param('op'); |
196 |
if ( $op && $op eq 'finished' ) { |
225 |
if ( $op && $op eq 'finished' ) { |
197 |
# |
226 |
# |
Lines 203-220
elsif ( $step && $step == 3 ) {
Link Here
|
203 |
elsif ( $op && $op eq 'finish' ) { |
232 |
elsif ( $op && $op eq 'finish' ) { |
204 |
$installer->set_version_syspref(); |
233 |
$installer->set_version_syspref(); |
205 |
|
234 |
|
206 |
# Installation is finished. |
235 |
# Installation is finished. |
207 |
# We just deny anybody access to install |
236 |
# We just deny anybody access to install |
208 |
# And we redirect people to mainpage. |
237 |
# And we redirect people to mainpage. |
209 |
# The installer will have to relogin since we do not pass cookie to redirection. |
238 |
# The installer will have to relogin since we do not pass cookie to redirection. |
210 |
$template->param( "$op" => 1 ); |
239 |
$template->param( "$op" => 1 ); |
211 |
} |
240 |
} |
|
|
241 |
|
212 |
elsif ( $op && $op eq 'addframeworks' ) { |
242 |
elsif ( $op && $op eq 'addframeworks' ) { |
213 |
# |
|
|
214 |
# 1ST install, 3rd sub-step : insert the SQL files the user has selected |
215 |
# |
216 |
|
243 |
|
217 |
my ($fwk_language, $list) = $installer->load_sql_in_order($all_languages, $query->param('framework')); |
244 |
# 1ST install, 3rd sub-step : insert the SQL files the user has selected |
|
|
245 |
|
246 |
my ( $fwk_language, $list ) = |
247 |
$installer->load_sql_in_order( $all_languages, |
248 |
$query->param('framework') ); |
218 |
$template->param( |
249 |
$template->param( |
219 |
"fwklanguage" => $fwk_language, |
250 |
"fwklanguage" => $fwk_language, |
220 |
"list" => $list |
251 |
"list" => $list |
Lines 224-265
elsif ( $step && $step == 3 ) {
Link Here
|
224 |
$template->param( "$op" => 1 ); |
255 |
$template->param( "$op" => 1 ); |
225 |
} |
256 |
} |
226 |
elsif ( $op && $op eq 'selectframeworks' ) { |
257 |
elsif ( $op && $op eq 'selectframeworks' ) { |
227 |
# |
258 |
# |
228 |
# |
259 |
# |
229 |
# 1ST install, 2nd sub-step : show the user the sql datas he can insert in the database. |
260 |
# 1ST install, 2nd sub-step : show the user the sql datas he can insert in the database. |
230 |
# |
261 |
# |
231 |
# |
262 |
# |
232 |
# (note that the term "selectframeworks is not correct. The user can select various files, not only frameworks) |
263 |
# (note that the term "selectframeworks is not correct. The user can select various files, not only frameworks) |
233 |
|
264 |
|
234 |
#Framework Selection |
265 |
#Framework Selection |
235 |
#sql data for import are supposed to be located in installer/data/<language>/<level> |
266 |
#sql data for import are supposed to be located in installer/data/<language>/<level> |
236 |
# Where <language> is en|fr or any international abbreviation (provided language hash is updated... This will be a problem with internationlisation.) |
267 |
# Where <language> is en|fr or any international abbreviation (provided language hash is updated... This will be a problem with internationlisation.) |
237 |
# Where <level> is a category of requirement : required, recommended optional |
268 |
# Where <level> is a category of requirement : required, recommended optional |
238 |
# level should contain : |
269 |
# level should contain : |
239 |
# SQL File for import With a readable name. |
270 |
# SQL File for import With a readable name. |
240 |
# txt File that explains what this SQL File is meant for. |
271 |
# txt File that explains what this SQL File is meant for. |
241 |
# Could be VERY useful to have A Big file for a kind of library. |
272 |
# Could be VERY useful to have A Big file for a kind of library. |
242 |
# But could also be useful to have some Authorised values data set prepared here. |
273 |
# But could also be useful to have some Authorised values data set prepared here. |
243 |
# Framework Selection is achieved through checking boxes. |
274 |
# Framework Selection is achieved through checking boxes. |
244 |
my $langchoice = $query->param('fwklanguage'); |
275 |
my $langchoice = $query->param('fwklanguage'); |
245 |
$langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice); |
276 |
$langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice); |
246 |
$langchoice =~ s/[^a-zA-Z_-]*//g; |
277 |
$langchoice =~ s/[^a-zA-Z_-]*//g; |
247 |
my $marcflavour = $query->param('marcflavour'); |
278 |
my $marcflavour = $query->param('marcflavour'); |
248 |
if ($marcflavour){ |
279 |
if ($marcflavour) { |
249 |
$installer->set_marcflavour_syspref($marcflavour); |
280 |
$installer->set_marcflavour_syspref($marcflavour); |
250 |
}; |
281 |
} |
251 |
$marcflavour = C4::Context->preference('marcflavour') unless ($marcflavour); |
282 |
$marcflavour = C4::Context->preference('marcflavour') |
|
|
283 |
unless ($marcflavour); |
284 |
|
252 |
#Insert into database the selected marcflavour |
285 |
#Insert into database the selected marcflavour |
253 |
undef $/; |
286 |
undef $/; |
254 |
my ($marc_defaulted_to_en, $fwklist) = $installer->marc_framework_sql_list($langchoice, $marcflavour); |
287 |
my ( $marc_defaulted_to_en, $fwklist ) = |
255 |
$template->param('en_marc_frameworks' => $marc_defaulted_to_en); |
288 |
$installer->marc_framework_sql_list( $langchoice, $marcflavour ); |
256 |
$template->param( "frameworksloop" => $fwklist ); |
289 |
$template->param( 'en_marc_frameworks' => $marc_defaulted_to_en ); |
257 |
$template->param( "marcflavour" => ucfirst($marcflavour)); |
290 |
$template->param( "frameworksloop" => $fwklist ); |
258 |
|
291 |
$template->param( "marcflavour" => ucfirst($marcflavour) ); |
259 |
my ($sample_defaulted_to_en, $levellist) = $installer->sample_data_sql_list($langchoice); |
292 |
|
260 |
$template->param( "en_sample_data" => $sample_defaulted_to_en); |
293 |
my ( $sample_defaulted_to_en, $levellist ) = |
261 |
$template->param( "levelloop" => $levellist ); |
294 |
$installer->sample_data_sql_list($langchoice); |
262 |
$template->param( "$op" => 1 ); |
295 |
$template->param( "en_sample_data" => $sample_defaulted_to_en ); |
|
|
296 |
$template->param( "levelloop" => $levellist ); |
297 |
$template->param( "$op" => 1 ); |
298 |
|
299 |
my $setup = $query->param('setup'); |
300 |
$template->param( "setup" => $setup ); |
301 |
|
263 |
} |
302 |
} |
264 |
elsif ( $op && $op eq 'choosemarc' ) { |
303 |
elsif ( $op && $op eq 'choosemarc' ) { |
265 |
# |
304 |
# |
Lines 268-313
elsif ( $step && $step == 3 ) {
Link Here
|
268 |
# |
307 |
# |
269 |
# |
308 |
# |
270 |
|
309 |
|
271 |
#Choose Marc Flavour |
310 |
#Choose Marc Flavour |
272 |
#sql data are supposed to be located in installer/data/<dbms>/<language>/marcflavour/marcflavourname |
311 |
#sql data are supposed to be located in installer/data/<dbms>/<language>/marcflavour/marcflavourname |
273 |
# Where <dbms> is database type according to DBD syntax |
312 |
# Where <dbms> is database type according to DBD syntax |
274 |
# Where <language> is en|fr or any international abbreviation (provided language hash is updated... This will be a problem with internationlisation.) |
313 |
# Where <language> is en|fr or any international abbreviation (provided language hash is updated... This will be a problem with internationlisation.) |
275 |
# Where <level> is a category of requirement : required, recommended optional |
314 |
# Where <level> is a category of requirement : required, recommended optional |
276 |
# level should contain : |
315 |
# level should contain : |
277 |
# SQL File for import With a readable name. |
316 |
# SQL File for import With a readable name. |
278 |
# txt File taht explains what this SQL File is meant for. |
317 |
# txt File taht explains what this SQL File is meant for. |
279 |
# Could be VERY useful to have A Big file for a kind of library. |
318 |
# Could be VERY useful to have A Big file for a kind of library. |
280 |
# But could also be useful to have some Authorised values data set prepared here. |
319 |
# But could also be useful to have some Authorised values data set prepared here. |
281 |
# Marcflavour Selection is achieved through radiobuttons. |
320 |
# Marcflavour Selection is achieved through radiobuttons. |
282 |
my $langchoice = $query->param('fwklanguage'); |
321 |
my $langchoice = $query->param('fwklanguage'); |
|
|
322 |
|
283 |
$langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice); |
323 |
$langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice); |
284 |
$langchoice =~ s/[^a-zA-Z_-]*//g; |
324 |
$langchoice =~ s/[^a-zA-Z_-]*//g; |
285 |
my $dir = |
325 |
my $dir = |
286 |
C4::Context->config('intranetdir') . "/installer/data/$info{dbms}/$langchoice/marcflavour"; |
326 |
C4::Context->config('intranetdir') |
287 |
unless (opendir( MYDIR, $dir )) { |
327 |
. "/installer/data/$info{dbms}/$langchoice/marcflavour"; |
288 |
if ($langchoice eq 'en') { |
328 |
unless ( opendir( MYDIR, $dir ) ) { |
|
|
329 |
if ( $langchoice eq 'en' ) { |
289 |
warn "cannot open MARC frameworks directory $dir"; |
330 |
warn "cannot open MARC frameworks directory $dir"; |
290 |
} else { |
331 |
} |
|
|
332 |
else { |
291 |
# if no translated MARC framework is available, |
333 |
# if no translated MARC framework is available, |
292 |
# default to English |
334 |
# default to English |
293 |
$dir = C4::Context->config('intranetdir') . "/installer/data/$info{dbms}/en/marcflavour"; |
335 |
$dir = C4::Context->config('intranetdir') |
294 |
opendir(MYDIR, $dir) or warn "cannot open English MARC frameworks directory $dir"; |
336 |
. "/installer/data/$info{dbms}/en/marcflavour"; |
|
|
337 |
opendir( MYDIR, $dir ) |
338 |
or warn "cannot open English MARC frameworks directory $dir"; |
295 |
} |
339 |
} |
296 |
} |
340 |
} |
297 |
my @listdir = grep { !/^\./ && -d "$dir/$_" } readdir(MYDIR); |
341 |
my @listdir = grep { !/^\./ && -d "$dir/$_" } readdir(MYDIR); |
298 |
closedir MYDIR; |
342 |
closedir MYDIR; |
299 |
my $marcflavour=C4::Context->preference("marcflavour"); |
343 |
my $marcflavour = C4::Context->preference("marcflavour"); |
300 |
my @flavourlist; |
344 |
my @flavourlist; |
301 |
foreach my $marc (@listdir) { |
345 |
foreach my $marc (@listdir) { |
302 |
my %cell=( |
346 |
my %cell = ( |
303 |
"label"=> ucfirst($marc), |
347 |
"label" => ucfirst($marc), |
304 |
"code"=>uc($marc), |
348 |
"code" => uc($marc), |
305 |
"checked"=> defined($marcflavour) ? uc($marc) eq $marcflavour : 0); |
349 |
"checked" => defined($marcflavour) |
|
|
350 |
? uc($marc) eq $marcflavour |
351 |
: 0 |
352 |
); |
353 |
|
306 |
# $cell{"description"}= do { local $/ = undef; open INPUT "<$dir/$marc.txt"||"";<INPUT> }; |
354 |
# $cell{"description"}= do { local $/ = undef; open INPUT "<$dir/$marc.txt"||"";<INPUT> }; |
307 |
push @flavourlist, \%cell; |
355 |
push @flavourlist, \%cell; |
308 |
} |
356 |
} |
309 |
$template->param( "flavourloop" => \@flavourlist ); |
357 |
$template->param( "flavourloop" => \@flavourlist ); |
310 |
$template->param( "$op" => 1 ); |
358 |
$template->param( "$op" => 1 ); |
311 |
} |
359 |
} |
312 |
elsif ( $op && $op eq 'importdatastructure' ) { |
360 |
elsif ( $op && $op eq 'importdatastructure' ) { |
313 |
# |
361 |
# |
Lines 327-333
elsif ( $step && $step == 3 ) {
Link Here
|
327 |
# |
375 |
# |
328 |
#Do updatedatabase And report |
376 |
#Do updatedatabase And report |
329 |
|
377 |
|
330 |
if ( ! defined $ENV{PERL5LIB} ) { |
378 |
if ( !defined $ENV{PERL5LIB} ) { |
331 |
my $find = "C4/Context.pm"; |
379 |
my $find = "C4/Context.pm"; |
332 |
my $path = $INC{$find}; |
380 |
my $path = $INC{$find}; |
333 |
$path =~ s/\Q$find\E//; |
381 |
$path =~ s/\Q$find\E//; |
Lines 335-394
elsif ( $step && $step == 3 ) {
Link Here
|
335 |
warn "# plack? inserted PERL5LIB $ENV{PERL5LIB}\n"; |
383 |
warn "# plack? inserted PERL5LIB $ENV{PERL5LIB}\n"; |
336 |
} |
384 |
} |
337 |
|
385 |
|
338 |
my $now = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime() ); |
386 |
my $now = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime() ); |
339 |
my $logdir = C4::Context->config('logdir'); |
387 |
my $logdir = C4::Context->config('logdir'); |
340 |
my $dbversion = C4::Context->preference('Version'); |
388 |
my $dbversion = C4::Context->preference('Version'); |
341 |
my $kohaversion = Koha::version; |
389 |
my $kohaversion = Koha::version; |
342 |
$kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; |
390 |
$kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; |
343 |
|
391 |
|
344 |
my $filename_suffix = join '_', $now, $dbversion, $kohaversion; |
392 |
my $filename_suffix = join '_', $now, $dbversion, $kohaversion; |
345 |
my ( $logfilepath, $logfilepath_errors ) = ( chk_log($logdir, "updatedatabase_$filename_suffix"), chk_log($logdir, "updatedatabase-error_$filename_suffix") ); |
393 |
my ( $logfilepath, $logfilepath_errors ) = ( |
|
|
394 |
chk_log( $logdir, "updatedatabase_$filename_suffix" ), |
395 |
chk_log( $logdir, "updatedatabase-error_$filename_suffix" ) |
396 |
); |
346 |
|
397 |
|
347 |
my $cmd = C4::Context->config("intranetdir") . "/installer/data/$info{dbms}/updatedatabase.pl >> $logfilepath 2>> $logfilepath_errors"; |
398 |
my $cmd = C4::Context->config("intranetdir") |
|
|
399 |
. "/installer/data/$info{dbms}/updatedatabase.pl >> $logfilepath 2>> $logfilepath_errors"; |
348 |
|
400 |
|
349 |
system($cmd ); |
401 |
system($cmd ); |
350 |
|
402 |
|
351 |
my $fh; |
403 |
my $fh; |
352 |
open( $fh, "<", $logfilepath ) or die "Cannot open log file $logfilepath: $!"; |
404 |
open( $fh, "<", $logfilepath ) |
|
|
405 |
or die "Cannot open log file $logfilepath: $!"; |
353 |
my @report = <$fh>; |
406 |
my @report = <$fh>; |
354 |
close $fh; |
407 |
close $fh; |
355 |
if (@report) { |
408 |
if (@report) { |
356 |
$template->param( update_report => [ map { { line => $_ } } split( /\n/, join( '', @report ) ) ] ); |
409 |
$template->param( update_report => |
|
|
410 |
[ map { { line => $_ } } split( /\n/, join( '', @report ) ) ] |
411 |
); |
357 |
$template->param( has_update_succeeds => 1 ); |
412 |
$template->param( has_update_succeeds => 1 ); |
358 |
} else { |
|
|
359 |
eval{ `rm $logfilepath` }; |
360 |
} |
413 |
} |
361 |
open( $fh, "<", $logfilepath_errors ) or die "Cannot open log file $logfilepath_errors: $!"; |
414 |
else { |
|
|
415 |
eval { `rm $logfilepath` }; |
416 |
} |
417 |
open( $fh, "<", $logfilepath_errors ) |
418 |
or die "Cannot open log file $logfilepath_errors: $!"; |
362 |
@report = <$fh>; |
419 |
@report = <$fh>; |
363 |
close $fh; |
420 |
close $fh; |
364 |
if (@report) { |
421 |
if (@report) { |
365 |
$template->param( update_errors => [ map { { line => $_ } } split( /\n/, join( '', @report ) ) ] ); |
422 |
$template->param( update_errors => |
|
|
423 |
[ map { { line => $_ } } split( /\n/, join( '', @report ) ) ] |
424 |
); |
366 |
$template->param( has_update_errors => 1 ); |
425 |
$template->param( has_update_errors => 1 ); |
367 |
warn "The following errors were returned while attempting to run the updatedatabase.pl script:\n"; |
426 |
warn |
|
|
427 |
"The following errors were returned while attempting to run the updatedatabase.pl script:\n"; |
368 |
foreach my $line (@report) { warn "$line\n"; } |
428 |
foreach my $line (@report) { warn "$line\n"; } |
369 |
} else { |
429 |
} |
370 |
eval{ `rm $logfilepath_errors` }; |
430 |
else { |
|
|
431 |
eval { `rm $logfilepath_errors` }; |
371 |
} |
432 |
} |
372 |
$template->param( $op => 1 ); |
433 |
$template->param( $op => 1 ); |
373 |
} |
434 |
} |
374 |
else { |
435 |
else { |
375 |
# |
436 |
# |
376 |
# check whether it's a 1st install or an update |
437 |
# check whether it's a 1st install or an update |
377 |
# |
438 |
# |
378 |
#Check if there are enough tables. |
439 |
#Check if there are enough tables. |
379 |
# Paul has cleaned up tables so reduced the count |
440 |
# Paul has cleaned up tables so reduced the count |
380 |
#I put it there because it implied a data import if condition was not satisfied. |
441 |
#I put it there because it implied a data import if condition was not satisfied. |
381 |
my $dbh = DBI->connect( |
442 |
my $dbh = DBI->connect( |
382 |
"DBI:$info{dbms}:dbname=$info{dbname};host=$info{hostname}" |
443 |
"DBI:$info{dbms}:dbname=$info{dbname};host=$info{hostname}" |
383 |
. ( $info{port} ? ";port=$info{port}" : "" ) |
444 |
. ( $info{port} ? ";port=$info{port}" : "" ) |
384 |
. ( $info{tlsoptions} ? $info{tlsoptions} : "" ), |
445 |
. ( $info{tlsoptions} ? $info{tlsoptions} : "" ), |
385 |
$info{'user'}, $info{'password'} |
446 |
$info{'user'}, $info{'password'} |
386 |
); |
447 |
); |
387 |
my $rq; |
448 |
my $rq; |
388 |
if ( $info{dbms} eq 'mysql' ) { $rq = $dbh->prepare( "SHOW TABLES" ); } |
449 |
if ( $info{dbms} eq 'mysql' ) { $rq = $dbh->prepare("SHOW TABLES"); } |
389 |
elsif ( $info{dbms} eq 'Pg' ) { $rq = $dbh->prepare( "SELECT * |
450 |
elsif ( $info{dbms} eq 'Pg' ) { |
390 |
FROM information_schema.tables |
451 |
$rq = $dbh->prepare( |
391 |
WHERE table_schema='public' and table_type='BASE TABLE';" ); } |
452 |
"SELECT * |
|
|
453 |
FROM information_schema.tables |
454 |
WHERE table_schema='public' and table_type='BASE TABLE';" |
455 |
); |
456 |
} |
392 |
$rq->execute; |
457 |
$rq->execute; |
393 |
my $data = $rq->fetchall_arrayref( {} ); |
458 |
my $data = $rq->fetchall_arrayref( {} ); |
394 |
my $count = scalar(@$data); |
459 |
my $count = scalar(@$data); |
Lines 399-421
elsif ( $step && $step == 3 ) {
Link Here
|
399 |
$template->param( "count" => $count, "proposeimport" => 1 ); |
464 |
$template->param( "count" => $count, "proposeimport" => 1 ); |
400 |
} |
465 |
} |
401 |
else { |
466 |
else { |
402 |
# |
467 |
# |
403 |
# we have tables, propose to select files to upload or updatedatabase |
468 |
# we have tables, propose to select files to upload or updatedatabase |
404 |
# |
469 |
# |
405 |
$template->param( "count" => $count, "default" => 1 ); |
470 |
$template->param( "count" => $count, "default" => 1 ); |
406 |
# |
471 |
# |
407 |
# 1st part of step 3 : check if there is a databaseversion systempreference |
472 |
# 1st part of step 3 : check if there is a databaseversion systempreference |
408 |
# if there is, then we just need to upgrade |
473 |
# if there is, then we just need to upgrade |
409 |
# if there is none, then we need to install the database |
474 |
# if there is none, then we need to install the database |
410 |
# |
475 |
# |
411 |
if (C4::Context->preference('Version')) { |
476 |
if ( C4::Context->preference('Version') ) { |
412 |
my $dbversion = C4::Context->preference('Version'); |
477 |
my $dbversion = C4::Context->preference('Version'); |
413 |
$dbversion =~ /(.*)\.(..)(..)(...)/; |
478 |
$dbversion =~ /(.*)\.(..)(..)(...)/; |
414 |
$dbversion = "$1.$2.$3.$4"; |
479 |
$dbversion = "$1.$2.$3.$4"; |
415 |
$template->param("upgrading" => 1, |
480 |
$template->param( |
416 |
"dbversion" => $dbversion, |
481 |
"upgrading" => 1, |
417 |
"kohaversion" => Koha::version(), |
482 |
"dbversion" => $dbversion, |
418 |
); |
483 |
"kohaversion" => Koha::version(), |
|
|
484 |
); |
419 |
} |
485 |
} |
420 |
} |
486 |
} |
421 |
} |
487 |
} |
Lines 433-439
else {
Link Here
|
433 |
if ( $rq->execute ) { |
499 |
if ( $rq->execute ) { |
434 |
my ($version) = $rq->fetchrow; |
500 |
my ($version) = $rq->fetchrow; |
435 |
if ($version) { |
501 |
if ($version) { |
436 |
print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3"); |
502 |
print $query->redirect( |
|
|
503 |
"/cgi-bin/koha/installer/install.pl?step=3"); |
437 |
exit; |
504 |
exit; |
438 |
} |
505 |
} |
439 |
} |
506 |
} |
Lines 441-453
else {
Link Here
|
441 |
} |
508 |
} |
442 |
output_html_with_http_headers $query, $cookie, $template->output; |
509 |
output_html_with_http_headers $query, $cookie, $template->output; |
443 |
|
510 |
|
444 |
sub chk_log { #returns a logfile in $dir or - if that failed - in temp dir |
511 |
sub chk_log { #returns a logfile in $dir or - if that failed - in temp dir |
445 |
my ($dir, $name) = @_; |
512 |
my ( $dir, $name ) = @_; |
446 |
my $fn=$dir.'/'.$name.'.log'; |
513 |
my $fn = $dir . '/' . $name . '.log'; |
447 |
if( ! open my $fh, '>', $fn ) { |
514 |
if ( !open my $fh, '>', $fn ) { |
448 |
$name.= '_XXXX'; |
515 |
$name .= '_XXXX'; |
449 |
require File::Temp; |
516 |
require File::Temp; |
450 |
($fh, $fn)= File::Temp::tempfile( $name, TMPDIR => 1, SUFFIX => '.log'); |
517 |
( $fh, $fn ) = |
|
|
518 |
File::Temp::tempfile( $name, TMPDIR => 1, SUFFIX => '.log' ); |
519 |
|
451 |
#if this should not work, let croak take over |
520 |
#if this should not work, let croak take over |
452 |
} |
521 |
} |
453 |
return $fn; |
522 |
return $fn; |