Bug 32334: (QA follow-up) Improve finding schema file
Adds a schema parameter to the cmdline script now too. Test plan: Run sync_db_comments.pl with -schema file where file does not exist. (On dev install) rename kohastructure.sql, try with[out] referring to it using -schema. You could also use the standard path intranet/cgi-bin/installer/data/mysql. Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
a59c530786
commit
6a706f0e6a
2 changed files with 20 additions and 4 deletions
|
@ -20,6 +20,7 @@ package Koha::Database::Commenter;
|
|||
use Modern::Perl;
|
||||
use File::Slurp qw(read_file);
|
||||
|
||||
use C4::Context;
|
||||
use Koha::Exceptions;
|
||||
|
||||
use constant KOHA_STRUCTURE => 'installer/data/mysql/kohastructure.sql';
|
||||
|
@ -76,7 +77,7 @@ sub new {
|
|||
unless ref($self->{dbh}) eq DBI_HANDLE_CLASS;
|
||||
|
||||
$self->{database} //= ( $self->{dbh}->selectrow_array('SELECT DATABASE()') )[0];
|
||||
$self->{schema_file} //= KOHA_STRUCTURE;
|
||||
$self->_find_schema unless $self->{schema_file};
|
||||
$self->{schema_info} = {};
|
||||
|
||||
return $self;
|
||||
|
@ -151,8 +152,20 @@ sub renumber {
|
|||
|
||||
=head1 INTERNAL ROUTINES
|
||||
|
||||
=head2 _find_schema
|
||||
|
||||
=cut
|
||||
|
||||
sub _find_schema {
|
||||
my $self = shift;
|
||||
my $rootdir = C4::Context->config('intranetdir');
|
||||
if( -e "$rootdir/". KOHA_STRUCTURE ) {
|
||||
$self->{schema_file} = "$rootdir/". KOHA_STRUCTURE;
|
||||
} elsif( -e "$rootdir/intranet/cgi-bin/". KOHA_STRUCTURE ) {
|
||||
$self->{schema_file} = "$rootdir/intranet/cgi-bin/". KOHA_STRUCTURE;
|
||||
}
|
||||
}
|
||||
|
||||
=head2 _fetch_schema_comments
|
||||
|
||||
=cut
|
||||
|
@ -161,7 +174,7 @@ sub _fetch_schema_comments {
|
|||
# Wish we had a DBIC function for this, showing comments too ;) Now using kohastructure as source of truth.
|
||||
my ( $self ) = @_;
|
||||
my $file = $self->{schema_file};
|
||||
Koha::Exceptions::FileNotFound->throw( filename => $file ) unless -e $file;
|
||||
Koha::Exceptions::FileNotFound->throw( filename => $file ) unless $file && -e $file;
|
||||
|
||||
return $self->{schema_info} if keys %{$self->{schema_info}};
|
||||
|
||||
|
|
|
@ -36,12 +36,15 @@ GetOptions(
|
|||
'help|h' => \$cmd_args->{help},
|
||||
'renumber' => \$cmd_args->{renumber},
|
||||
'reset' => \$cmd_args->{reset},
|
||||
'schema:s' => \$cmd_args->{schema},
|
||||
'table:s' => \$cmd_args->{table},
|
||||
'verbose|v' => \$cmd_args->{verbose},
|
||||
);
|
||||
$cmd_args->{dry_run} = !$cmd_args->{commit};
|
||||
|
||||
my $commenter = Koha::Database::Commenter->new({ database => delete $cmd_args->{database}, dbh => C4::Context->dbh });
|
||||
my $commenter = Koha::Database::Commenter->new({
|
||||
database => delete $cmd_args->{database}, dbh => C4::Context->dbh, schema_file => delete $cmd_args->{schema},
|
||||
});
|
||||
my $messages = $cmd_args->{verbose} || $cmd_args->{dry_run} ? [] : undef;
|
||||
if( $cmd_args->{help} ) {
|
||||
pod2usage( -verbose => 2 );
|
||||
|
@ -71,7 +74,7 @@ misc/maintenance/sync_db_comments.pl
|
|||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
perl sync_db_comments.pl [-h] [-v] [-database DB_NAME] [-table TABLE_NAME] [-commit] [-clear|-reset|-renumber]
|
||||
perl sync_db_comments.pl [-h] [-v] [-schema FILE ] [-database DB_NAME] [-table TABLE_NAME] [-commit] [-clear|-reset|-renumber]
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
|
|
Loading…
Reference in a new issue