Lines 41-48
C4::Update::Database.pm
Link Here
|
41 |
|
41 |
|
42 |
=cut |
42 |
=cut |
43 |
|
43 |
|
44 |
our $dbh = C4::Context->dbh; |
|
|
45 |
|
46 |
=head2 get_versions_path |
44 |
=head2 get_versions_path |
47 |
|
45 |
|
48 |
return the path to the version files |
46 |
return the path to the version files |
Lines 194-199
sub list_versions_available {
Link Here
|
194 |
|
192 |
|
195 |
sub list_versions_already_applied { |
193 |
sub list_versions_already_applied { |
196 |
# 1st check if tables exist, otherwise create them |
194 |
# 1st check if tables exist, otherwise create them |
|
|
195 |
my $dbh = C4::Context->dbh; |
197 |
$dbh->do(qq{ |
196 |
$dbh->do(qq{ |
198 |
CREATE TABLE IF NOT EXISTS `updatedb_error` ( `version` varchar(32) DEFAULT NULL, `error` text ) ENGINE=InnoDB CHARSET=utf8; |
197 |
CREATE TABLE IF NOT EXISTS `updatedb_error` ( `version` varchar(32) DEFAULT NULL, `error` text ) ENGINE=InnoDB CHARSET=utf8; |
199 |
}); |
198 |
}); |
Lines 240-245
sub list_versions_already_applied {
Link Here
|
240 |
sub execute { |
239 |
sub execute { |
241 |
my ( $queries ) = @_; |
240 |
my ( $queries ) = @_; |
242 |
my @errors; |
241 |
my @errors; |
|
|
242 |
my $dbh = C4::Context->dbh; |
243 |
for my $query ( @{$queries->{queries}} ) { |
243 |
for my $query ( @{$queries->{queries}} ) { |
244 |
eval { |
244 |
eval { |
245 |
$dbh->do( $query ); |
245 |
$dbh->do( $query ); |
Lines 257-262
sub execute {
Link Here
|
257 |
=cut |
257 |
=cut |
258 |
|
258 |
|
259 |
sub get_tables_name { |
259 |
sub get_tables_name { |
|
|
260 |
my $dbh = C4::Context->dbh; |
260 |
my $sth = $dbh->prepare("SHOW TABLES"); |
261 |
my $sth = $dbh->prepare("SHOW TABLES"); |
261 |
$sth->execute(); |
262 |
$sth->execute(); |
262 |
my @tables; |
263 |
my @tables; |
Lines 344-349
my $tables;
Link Here
|
344 |
=cut |
345 |
=cut |
345 |
|
346 |
|
346 |
sub get_error { |
347 |
sub get_error { |
|
|
348 |
my $dbh = C4::Context->dbh; |
347 |
my @errors = $dbh->selectrow_array(qq{SHOW ERRORS}); # Get errors |
349 |
my @errors = $dbh->selectrow_array(qq{SHOW ERRORS}); # Get errors |
348 |
my @warnings = $dbh->selectrow_array(qq{SHOW WARNINGS}); # Get warnings |
350 |
my @warnings = $dbh->selectrow_array(qq{SHOW WARNINGS}); # Get warnings |
349 |
if ( @errors ) { # Catch specifics errors |
351 |
if ( @errors ) { # Catch specifics errors |
Lines 429-434
sub get_queries {
Link Here
|
429 |
sub md5_already_exists { |
431 |
sub md5_already_exists { |
430 |
my ( $md5 ) = @_; |
432 |
my ( $md5 ) = @_; |
431 |
my $query = qq/SELECT version, md5 FROM updatedb_report WHERE md5 = ?/; |
433 |
my $query = qq/SELECT version, md5 FROM updatedb_report WHERE md5 = ?/; |
|
|
434 |
my $dbh = C4::Context->dbh; |
432 |
my $sth = $dbh->prepare( $query ); |
435 |
my $sth = $dbh->prepare( $query ); |
433 |
$sth->execute( $md5 ); |
436 |
$sth->execute( $md5 ); |
434 |
my @r; |
437 |
my @r; |
Lines 449-454
sub md5_already_exists {
Link Here
|
449 |
sub set_infos { |
452 |
sub set_infos { |
450 |
my ( $version, $queries, $errors, $md5 ) = @_; |
453 |
my ( $version, $queries, $errors, $md5 ) = @_; |
451 |
SetVersion($version) if not -s $errors; |
454 |
SetVersion($version) if not -s $errors; |
|
|
455 |
my $dbh = C4::Context->dbh; |
452 |
for my $query ( @{ $queries->{queries} } ) { |
456 |
for my $query ( @{ $queries->{queries} } ) { |
453 |
my $sth = $dbh->prepare("INSERT INTO updatedb_query(version, query) VALUES (?, ?)"); |
457 |
my $sth = $dbh->prepare("INSERT INTO updatedb_query(version, query) VALUES (?, ?)"); |
454 |
$sth->execute( $version, $query ); |
458 |
$sth->execute( $version, $query ); |
Lines 477-482
sub set_infos {
Link Here
|
477 |
|
481 |
|
478 |
sub mark_as_ok { |
482 |
sub mark_as_ok { |
479 |
my ( $version ) = @_; |
483 |
my ( $version ) = @_; |
|
|
484 |
my $dbh = C4::Context->dbh; |
480 |
my $sth = $dbh->prepare( "UPDATE updatedb_report SET status = 2 WHERE version=?" ); |
485 |
my $sth = $dbh->prepare( "UPDATE updatedb_report SET status = 2 WHERE version=?" ); |
481 |
my $affected = $sth->execute( $version ); |
486 |
my $affected = $sth->execute( $version ); |
482 |
if ( $affected < 1 ) { |
487 |
if ( $affected < 1 ) { |
Lines 528-533
sub SetVersion {
Link Here
|
528 |
my $new_version = TransformToNum(shift); |
533 |
my $new_version = TransformToNum(shift); |
529 |
return unless $new_version =~ /\d\.\d+/; |
534 |
return unless $new_version =~ /\d\.\d+/; |
530 |
my $current_version = TransformToNum( C4::Context->preference('Version') ); |
535 |
my $current_version = TransformToNum( C4::Context->preference('Version') ); |
|
|
536 |
my $dbh = C4::Context->dbh; |
531 |
unless ( C4::Context->preference('Version') ) { |
537 |
unless ( C4::Context->preference('Version') ) { |
532 |
my $finish = $dbh->prepare(qq{ |
538 |
my $finish = $dbh->prepare(qq{ |
533 |
INSERT IGNORE INTO systempreferences (variable,value,explanation) |
539 |
INSERT IGNORE INTO systempreferences (variable,value,explanation) |
Lines 548-553
sub SetVersion {
Link Here
|
548 |
|
554 |
|
549 |
sub TableExists { |
555 |
sub TableExists { |
550 |
my $table = shift; |
556 |
my $table = shift; |
|
|
557 |
my $dbh = C4::Context->dbh; |
551 |
eval { |
558 |
eval { |
552 |
local $dbh->{PrintError} = 0; |
559 |
local $dbh->{PrintError} = 0; |
553 |
local $dbh->{RaiseError} = 0; |
560 |
local $dbh->{RaiseError} = 0; |
554 |
- |
|
|