@@ -, +, @@ --- C4/Update/Database.pm | 150 ++++++++------------ admin/updatedatabase.pl | 3 - .../prog/en/modules/admin/updatedatabase.tt | 3 - 3 files changed, 61 insertions(+), 95 deletions(-) --- a/C4/Update/Database.pm +++ a/C4/Update/Database.pm @@ -152,23 +152,7 @@ sub execute_version { return $report if ( defined $report->{$version} ); - my $errors; - for my $query ( @{$queries->{queries}} ) { - eval { - check_coherency( $query ); - }; - if ( $@ ) { - push @$errors, $@ - } - } - - if ( $errors ) { - $_ =~ s/at [^ ]* line \d*\.$// for @$errors; - $report->{$version} = $errors; - return $report; - } - - $errors = execute ( $queries ); + my $errors = execute ( $queries ); $report->{$version} = scalar( @$errors ) ? $errors : "OK"; set_infos ( $version, $queries, $errors, $md5 ); return $report; @@ -280,7 +264,7 @@ my $tables; =head2 check_coherency - my $errors = check_coherency($query); + my $errors = check_coherency($query); UNUSED This sub will try to check if a SQL query is useless or no. for queries that are CREATE TABLE, it will check if the table already exists for queries that are ALTER TABLE, it will search if the modification has already been made @@ -290,62 +274,62 @@ my $tables; =cut -sub check_coherency { - my ( $query ) = @_; - $tables = get_tables_name() if not $tables; - - given ( $query ) { - when ( /CREATE TABLE(?:.*?)? `?(\w+)`?/ ) { - my $table_name = $1; - if ( grep { /$table_name/ } @$tables ) { - die "COHERENCY: Table $table_name already exists"; - } - } - - when ( /ALTER TABLE *`?(\w+)`? *ADD *(?:COLUMN)? `?(\w+)`?/ ) { - my $table_name = $1; - my $column_name = $2; - next if $column_name =~ /(UNIQUE|CONSTRAINT|INDEX|KEY|FOREIGN)/; - if ( not grep { /$table_name/ } @$tables ) { - return "COHERENCY: Table $table_name does not exist"; - } else { - my $sth = $dbh->prepare( "DESC $table_name $column_name" ); - my $rv = $sth->execute; - if ( $rv > 0 ) { - die "COHERENCY: Field $table_name.$column_name already exists"; - } - } - } - - when ( /INSERT INTO `?(\w+)`?.*?VALUES *\((.*?)\)/ ) { - my $table_name = $1; - my @values = split /,/, $2; - s/^ *'// foreach @values; - s/' *$// foreach @values; - given ( $table_name ) { - when ( /systempreferences/ ) { - my $syspref = $values[0]; - my $sth = $dbh->prepare( "SELECT COUNT(*) FROM systempreferences WHERE variable = ?" ); - $sth->execute( $syspref ); - if ( ( my $count = $sth->fetchrow_array ) > 0 ) { - die "COHERENCY: Syspref $syspref already exists"; - } - } - - when ( /permissions/){ - my $module_bit = $values[0]; - my $code = $values[1]; - my $sth = $dbh->prepare( "SELECT COUNT(*) FROM permissions WHERE module_bit = ? AND code = ?" ); - $sth->execute($module_bit, $code); - if ( ( my $count = $sth->fetchrow_array ) > 0 ) { - die "COHERENCY: Permission $code already exists"; - } - } - } - } - } - return 1; -} +#sub check_coherency { +# my ( $query ) = @_; +# $tables = get_tables_name() if not $tables; +# +# given ( $query ) { +# when ( /CREATE TABLE(?:.*?)? `?(\w+)`?/ ) { +# my $table_name = $1; +# if ( grep { /$table_name/ } @$tables ) { +# die "COHERENCY: Table $table_name already exists"; +# } +# } +# +# when ( /ALTER TABLE *`?(\w+)`? *ADD *(?:COLUMN)? `?(\w+)`?/ ) { +# my $table_name = $1; +# my $column_name = $2; +# next if $column_name =~ /(UNIQUE|CONSTRAINT|INDEX|KEY|FOREIGN)/; +# if ( not grep { /$table_name/ } @$tables ) { +# return "COHERENCY: Table $table_name does not exist"; +# } else { +# my $sth = $dbh->prepare( "DESC $table_name $column_name" ); +# my $rv = $sth->execute; +# if ( $rv > 0 ) { +# die "COHERENCY: Field $table_name.$column_name already exists"; +# } +# } +# } +# +# when ( /INSERT INTO `?(\w+)`?.*?VALUES *\((.*?)\)/ ) { +# my $table_name = $1; +# my @values = split /,/, $2; +# s/^ *'// foreach @values; +# s/' *$// foreach @values; +# given ( $table_name ) { +# when ( /systempreferences/ ) { +# my $syspref = $values[0]; +# my $sth = $dbh->prepare( "SELECT COUNT(*) FROM systempreferences WHERE variable = ?" ); +# $sth->execute( $syspref ); +# if ( ( my $count = $sth->fetchrow_array ) > 0 ) { +# die "COHERENCY: Syspref $syspref already exists"; +# } +# } +# +# when ( /permissions/){ +# my $module_bit = $values[0]; +# my $code = $values[1]; +# my $sth = $dbh->prepare( "SELECT COUNT(*) FROM permissions WHERE module_bit = ? AND code = ?" ); +# $sth->execute($module_bit, $code); +# if ( ( my $count = $sth->fetchrow_array ) > 0 ) { +# die "COHERENCY: Permission $code already exists"; +# } +# } +# } +# } +# } +# return 1; +#} =head2 get_error @@ -462,22 +446,10 @@ sub mark_as_ok { my $sth = $dbh->prepare( "UPDATE updatedb_report SET status = 2 WHERE version=?" ); my $affected = $sth->execute( $version ); if ( $affected < 1 ) { - # For "Coherency" my $filepath = get_filepath $version; - my $queries = get_queries $filepath; - my $errors; - for my $query ( @{$queries->{queries}} ) { - eval { - check_coherency( $query ); - }; - if ( $@ ) { - push @$errors, $@ - } - } - - $_ =~ s/at [^ ]* line \d*\.$// for @$errors; - my $md5 = get_md5 $filepath; - set_infos $version, $queries, $errors, $md5; + my $queries = get_queries $filepath; + my $md5 = get_md5 $filepath; + set_infos $version, $queries, undef, $md5; $sth->execute( $version ); } --- a/admin/updatedatabase.pl +++ a/admin/updatedatabase.pl @@ -57,9 +57,6 @@ if ( $op eq 'update' ) { { version => $v, report => \@errors, - coherency => ( ref ( $r ) eq 'ARRAY' - ? @$r[0] =~ /COHERENCY/ ? 1 : 0 - : $r =~ /COHERENCY/ ? 1 : 0 ) } } @reports; $template->param( report_loop => \@report_loop ); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt @@ -67,9 +67,6 @@ [% r.error %]; [% END %] [% END %] - [% IF report_loo.coherency %] - [Mark as OK] - [% END %] [% END %] --