Bugzilla – Attachment 101953 Details for
Bug 24883
Add `misc/load_yaml.pl` utility script to allow manual loading of yaml data files
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24883: Move new sub from load_yaml.pl
Bug-24883-Move-new-sub-from-loadyamlpl.patch (text/plain), 3.39 KB, created by
Marcel de Rooy
on 2020-03-27 08:06:38 UTC
(
hide
)
Description:
Bug 24883: Move new sub from load_yaml.pl
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2020-03-27 08:06:38 UTC
Size:
3.39 KB
patch
obsolete
>From 127bb916bb366b09f6abe2208d119c89e144931d Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 19 Mar 2020 13:09:33 +0100 >Subject: [PATCH] Bug 24883: Move new sub from load_yaml.pl >Content-Type: text/plain; charset=utf-8 > >Use the sub from C4::Installer to avoid dup of code. > >Note: >We are going to modify the script and so will do more stuffs. >We may want to rename it, maybe installer_utilities.pl, >misc/installer/yaml_utility.pl, any suggestions? > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > misc/load_yaml.pl | 59 ++++++++++++++++--------------------------------------- > 1 file changed, 17 insertions(+), 42 deletions(-) > >diff --git a/misc/load_yaml.pl b/misc/load_yaml.pl >index e670f56660..b12d88d886 100755 >--- a/misc/load_yaml.pl >+++ b/misc/load_yaml.pl >@@ -19,70 +19,45 @@ > > use Modern::Perl; > >-use YAML::Syck qw( LoadFile ); >-use C4::Context; > use Getopt::Long qw(:config no_ignore_case); >-use Data::Printer; >+use C4::Context; >+use C4::Installer; > > sub print_usage { > ( my $basename = $0 ) =~ s|.*/||; > print <<USAGE; > > $basename >- Load file in YAML format into database >+ Load file in YAML format into database. > > Usage: > $0 [--file=FILE] > $0 -h >- >- -f, --file=FILE File to load. > -h, --help Show this help >+ -f, --file=FILE File to load. >+ --load Load the file into the database > > USAGE > } > > # Getting parameters >-my $file; >-my $help; >+my ( @files, $dump, $load, $help ); > > GetOptions( >- 'file|f=s' => \$file, >- 'help|h' => \$help >+ 'help|h' => \$help, >+ 'load' => \$load, >+ 'file|f=s@' => \@files, > ) or print_usage, exit 1; > >-if ($help or not $file) { >- print_usage; >- exit; >-} >- >-my $dbh = C4::Context->dbh; >-my $yaml; >-eval { >- $yaml = LoadFile( $file ); # Load YAML >-}; >-if ($@){ >- die "Something went wrong loading file $file ($@)"; >+if ($help or not @files or not $load) { >+ print_usage; >+ exit; > } > >-for my $table ( @{ $yaml->{'tables'} } ) { >- my $table_name = ( keys %$table )[0]; # table name >- my @rows = @{ $table->{$table_name}->{rows} }; # >- my @columns = ( sort keys %{$rows[0]} ); # column names >- my $fields = join ",", map{sprintf("`%s`", $_)} @columns; # idem, joined >- my $placeholders = join ",", map { "?" } @columns; # '?,..,?' string >- my $query = "INSERT INTO $table_name ( $fields ) VALUES ( $placeholders )"; >- my $sth = $dbh->prepare($query); >- my @multiline = @{ $table->{$table_name}->{'multiline'} }; # to check multiline values; >- foreach my $row ( @rows ) { >- my @values = map { >- my $col = $_; >- ( @multiline and grep { $_ eq $col } @multiline ) >- ? join "\r\n", @{$row->{$col}} # join multiline values >- : $row->{$col}; >- } @columns; >- $sth->execute( @values ); >+my $installer = C4::Installer->new; >+if ( $load ) { >+ for my $f ( @files ) { >+ my $error = $installer->load_sql($f); >+ say $error if $error; > } > } >-for my $statement ( @{ $yaml->{'sql_statements'} } ) { # extra SQL statements >- $dbh->do($statement); >-} >-- >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 24883
:
100831
|
101009
|
101010
|
101011
|
101012
|
101013
|
101292
|
101293
|
101294
|
101332
|
101333
|
101901
|
101902
|
101903
|
101904
|
101905
|
101950
|
101951
|
101952
| 101953 |
101954