|
Lines 17-26
package C4::Installer;
Link Here
|
| 17 |
# You should have received a copy of the GNU General Public License |
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>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
19 |
|
| 20 |
use strict; |
20 |
use Modern::Perl; |
| 21 |
#use warnings; FIXME - Bug 2505 |
|
|
| 22 |
|
21 |
|
| 23 |
use Encode qw( encode is_utf8 ); |
22 |
use Encode qw( encode is_utf8 ); |
|
|
23 |
use File::Slurp; |
| 24 |
use SQL::SplitStatement; |
| 24 |
use C4::Context; |
25 |
use C4::Context; |
| 25 |
use C4::Installer::PerlModules; |
26 |
use C4::Installer::PerlModules; |
| 26 |
use DBI; |
27 |
use DBI; |
|
Lines 428-473
with missing files, e.g.
Link Here
|
| 428 |
=cut |
429 |
=cut |
| 429 |
|
430 |
|
| 430 |
sub load_sql { |
431 |
sub load_sql { |
|
|
432 |
|
| 431 |
my $self = shift; |
433 |
my $self = shift; |
| 432 |
my $filename = shift; |
434 |
my $filename = shift; |
| 433 |
|
435 |
|
| 434 |
my $datadir = C4::Context->config('intranetdir') . "/installer/data/$self->{dbms}"; |
436 |
my $dbh = $self->{ dbh }; |
| 435 |
my $error; |
437 |
|
| 436 |
my $strcmd; |
438 |
my $sql = read_file( $filename, binmode => ':utf8'); |
| 437 |
my $cmd; |
439 |
my $sql_splitter = SQL::SplitStatement->new; |
| 438 |
if ( $self->{dbms} eq 'mysql' ) { |
440 |
my @statements = $sql_splitter->split($sql); |
| 439 |
$cmd = qx(which mysql 2>/dev/null || whereis mysql 2>/dev/null); |
441 |
my $error = ""; |
| 440 |
chomp $cmd; |
442 |
|
| 441 |
$cmd = $1 if ($cmd && $cmd =~ /^(.+?)[\r\n]+$/); |
443 |
foreach my $statement ( @statements ) { |
| 442 |
$cmd = 'mysql' if (!$cmd || !-x $cmd); |
444 |
$dbh->do($statement); |
| 443 |
$strcmd = "$cmd " |
445 |
if( $dbh->err) { |
| 444 |
. ( $self->{hostname} ? " -h $self->{hostname} " : "" ) |
446 |
$error .= "$filename (" . $dbh->errstr . "): $statement\n"; |
| 445 |
. ( $self->{port} ? " -P $self->{port} " : "" ) |
447 |
} |
| 446 |
. ( $self->{user} ? " -u $self->{user} " : "" ) |
|
|
| 447 |
. ( $self->{password} ? " -p'$self->{password}'" : "" ) |
| 448 |
. " $self->{dbname} "; |
| 449 |
$error = qx($strcmd --default-character-set=utf8 <$filename 2>&1 1>/dev/null); |
| 450 |
} elsif ( $self->{dbms} eq 'Pg' ) { |
| 451 |
$cmd = qx(which psql 2>/dev/null || whereis psql 2>/dev/null); |
| 452 |
chomp $cmd; |
| 453 |
$cmd = $1 if ($cmd && $cmd =~ /^(.+?)[\r\n]+$/); |
| 454 |
$cmd = 'psql' if (!$cmd || !-x $cmd); |
| 455 |
$strcmd = "$cmd " |
| 456 |
. ( $self->{hostname} ? " -h $self->{hostname} " : "" ) |
| 457 |
. ( $self->{port} ? " -p $self->{port} " : "" ) |
| 458 |
. ( $self->{user} ? " -U $self->{user} " : "" ) |
| 459 |
# . ( $self->{password} ? " -W $self->{password}" : "" ) # psql will NOT accept a password, but prompts... |
| 460 |
. " $self->{dbname} "; # Therefore, be sure to run 'trust' on localhost in pg_hba.conf -fbcit |
| 461 |
$error = qx($strcmd -f $filename 2>&1 1>/dev/null); |
| 462 |
# Be sure to set 'client_min_messages = error' in postgresql.conf |
| 463 |
# so that only true errors are returned to stderr or else the installer will |
| 464 |
# report the import as a failure although it really succeeded -fbcit |
| 465 |
} |
| 466 |
# errors thrown while loading installer data should be logged |
| 467 |
if($error) { |
| 468 |
warn "C4::Installer::load_sql returned the following errors while attempting to load $filename:\n"; |
| 469 |
warn "$error"; |
| 470 |
} |
448 |
} |
|
|
449 |
|
| 471 |
return $error; |
450 |
return $error; |
| 472 |
} |
451 |
} |
| 473 |
|
452 |
|
| 474 |
- |
|
|