a291cef48a1e52d7281dbdc012d89a920abb9ce5
[koha-equinox.git] / misc / devel / update_dbix_class_files.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright (C) 2012 ByWater Solutions
6 # Copyright (C) 2013 Equinox Software, Inc.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 use Modern::Perl;
22
23 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
24
25 use Getopt::Long;
26 use Pod::Usage;
27
28 my $path = "./";
29 my $db_driver = 'mysql';
30 my $db_host = 'localhost';
31 my $db_port = '3306';
32 my $db_name;
33 my $db_user;
34 my $db_passwd;
35 my $help;
36
37 GetOptions(
38     "path=s"      => \$path,
39     "db_driver=s" => \$db_driver,
40     "db_host=s"   => \$db_host,
41     "db_port=s"   => \$db_port,
42     "db_name=s"   => \$db_name,
43     "db_user=s"   => \$db_user,
44     "db_passwd=s" => \$db_passwd,
45     "h|help"      => \$help
46 );
47
48 # If we were asked for usage instructions, do it
49 pod2usage(1) if defined $help;
50
51 if (! defined $db_name ) {
52     print "Error: \'db_name\' parameter is mandatory.\n";
53     pod2usage(1);
54 } else {
55
56     make_schema_at(
57         "Koha::Schema",
58         { debug => 1, dump_directory => $path, preserve_case => 1 },
59         ["DBI:$db_driver:dbname=$db_name;host=$db_host;port=$db_port",$db_user, $db_passwd ]
60     );
61 }
62
63 1;
64
65 =head1 NAME
66
67 misc/devel/update_dbix_class_files.pl
68
69 =head1 SYNOPSIS
70
71  update_dbix_class_files.pl --db_name=db-name --db_user=db-user \
72                             --db_passwd=db-pass ...
73
74 The command in usually called from the root directory for the Koha source tree.
75 If you are running from another directory, use the --path switch to specify
76 a different path.
77
78 =head1 OPTIONS
79
80 =over 8
81
82 =item B<--db_name>
83
84 DB name. (mandatory)
85
86 =item B<--db_user>
87
88 DB user name.
89
90 =item B<--db_passwd>
91
92 DB password.
93
94 =item B<--db_driver>
95
96 DB driver to be used. (defaults to 'mysql')
97
98 =item B<--db_host>
99
100 hostname for the DB server. (defaults to 'localhost')
101
102 =item B<--db_port>
103
104 port number for the DB server. (defaults to '3306')
105
106 =item B<--path>
107
108 path into which create the schema files. (defaults to './')
109
110 =item B<-h|--help>
111
112 prints this help text
113
114 =back