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