Bugzilla – Attachment 98516 Details for
Bug 21177
Add ability to run misc/devel/update_dbic_class_files.pl without passing parameters by defaulting to koha-conf.xml
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21177: Use koha-conf.xml in misc/devel/update_dbix_class_files.pl
Bug-21177-Use-koha-confxml-in-miscdevelupdatedbixc.patch (text/plain), 4.62 KB, created by
Marcel de Rooy
on 2020-02-06 07:52:43 UTC
(
hide
)
Description:
Bug 21177: Use koha-conf.xml in misc/devel/update_dbix_class_files.pl
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2020-02-06 07:52:43 UTC
Size:
4.62 KB
patch
obsolete
>From 0e014107c85661442364fdaf5b75a2f0b629bf34 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Wed, 8 Aug 2018 15:40:09 +0200 >Subject: [PATCH] Bug 21177: Use koha-conf.xml in > misc/devel/update_dbix_class_files.pl >Content-Type: text/plain; charset=utf-8 > >It is annoying to have to specify database connection parameters each >time DBIx::Class files need to be updated. > >This patch adds a new option --koha-conf that takes an optional <path> >which defaults to the value of KOHA_CONF environment variable, and use >the database connection parameters found in that file. >--db_* options override values from $KOHA_CONF > >Test plan: >1. Run the script with the same parameters as before the patch and see > that it still works. > Example: > misc/devel/update_dbix_class_files.pl --db_name koha_dev \ > --db_user koha --db_pass koha > >2. Verify that KOHA_CONF is set and execute: > misc/devel/update_dbix_class_files.pl --koha-conf > Verify that Koha/Schema files were updated accordingly > >3. Execute: > misc/devel/update_dbix_class_files.pl --koha-conf \ > /path/to/another/koha-conf.xml > Verify that Koha/Schema files were updated accordingly > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > misc/devel/update_dbix_class_files.pl | 64 +++++++++++++++++++++++++++++++---- > 1 file changed, 58 insertions(+), 6 deletions(-) > >diff --git a/misc/devel/update_dbix_class_files.pl b/misc/devel/update_dbix_class_files.pl >index a291cef48a..b89ec635a5 100755 >--- a/misc/devel/update_dbix_class_files.pl >+++ b/misc/devel/update_dbix_class_files.pl >@@ -25,13 +25,20 @@ use DBIx::Class::Schema::Loader qw/ make_schema_at /; > use Getopt::Long; > use Pod::Usage; > >+my %db_defaults = ( >+ driver => 'mysql', >+ host => 'localhost', >+ port => '3306', >+); >+ > my $path = "./"; >-my $db_driver = 'mysql'; >-my $db_host = 'localhost'; >-my $db_port = '3306'; >+my $db_driver; >+my $db_host; >+my $db_port; > my $db_name; > my $db_user; > my $db_passwd; >+my $koha_conf; > my $help; > > GetOptions( >@@ -42,12 +49,48 @@ GetOptions( > "db_name=s" => \$db_name, > "db_user=s" => \$db_user, > "db_passwd=s" => \$db_passwd, >+ "koha-conf:s" => \$koha_conf, > "h|help" => \$help > ); > > # If we were asked for usage instructions, do it > pod2usage(1) if defined $help; > >+if (defined $koha_conf) { >+ if ($koha_conf eq '' and not defined $ENV{KOHA_CONF}) { >+ print STDERR "Error: KOHA_CONF is not defined\n"; >+ exit(1); >+ } >+ >+ $koha_conf ||= $ENV{KOHA_CONF}; >+ unless (-r $koha_conf) { >+ print STDERR "Error: File $koha_conf does not exist or is not readable\n"; >+ exit(1); >+ } >+ >+ require C4::Context; >+ my $context = C4::Context->new($koha_conf); >+ unless ($context) { >+ print STDERR "Error: Koha context creation failed. Please check that $koha_conf is correct\n"; >+ exit(1); >+ } >+ >+ $context->set_context; >+ $db_defaults{driver} = $context->config('db_scheme'); >+ $db_defaults{host} = $context->config('hostname'); >+ $db_defaults{port} = $context->config('port'); >+ $db_defaults{name} = $context->config('database'); >+ $db_defaults{user} = $context->config('user'); >+ $db_defaults{passwd} = $context->config('pass'); >+} >+ >+$db_driver //= $db_defaults{driver}; >+$db_host //= $db_defaults{host}; >+$db_port //= $db_defaults{port}; >+$db_name //= $db_defaults{name}; >+$db_user //= $db_defaults{user}; >+$db_passwd //= $db_defaults{passwd}; >+ > if (! defined $db_name ) { > print "Error: \'db_name\' parameter is mandatory.\n"; > pod2usage(1); >@@ -68,8 +111,8 @@ misc/devel/update_dbix_class_files.pl > > =head1 SYNOPSIS > >- update_dbix_class_files.pl --db_name=db-name --db_user=db-user \ >- --db_passwd=db-pass ... >+ update_dbix_class_files.pl [--koha-conf <path>] --db_name=db-name \ >+ --db_user=db-user --db_passwd=db-pass ... > > The command in usually called from the root directory for the Koha source tree. > If you are running from another directory, use the --path switch to specify >@@ -79,6 +122,15 @@ a different path. > > =over 8 > >+=item B<--koha-conf> <path> >+ >+Path to koha-conf.xml from which DB connection params will be retrieved. >+ >+<path> is optional and defaults to the value of environment variable KOHA_CONF, >+if set. It is an error to omit the <path> if KOHA_CONF is not set. >+ >+Any B<--db_*> options will override values retrieved from <path>. >+ > =item B<--db_name> > > DB name. (mandatory) >@@ -111,4 +163,4 @@ path into which create the schema files. (defaults to './') > > prints this help text > >-=back >\ No newline at end of file >+=back >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21177
:
77574
|
95849
| 98516