Bugzilla – Attachment 101010 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: Centralize code to load YAML installer files to a sub
Bug-24883-Centralize-code-to-load-YAML-installer-f.patch (text/plain), 3.72 KB, created by
Jonathan Druart
on 2020-03-19 12:24:38 UTC
(
hide
)
Description:
Bug 24883: Centralize code to load YAML installer files to a sub
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-03-19 12:24:38 UTC
Size:
3.72 KB
patch
obsolete
>From 0a95fce14da912532c758fad08995efb69577ecc Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 19 Mar 2020 12:05:25 +0100 >Subject: [PATCH] Bug 24883: Centralize code to load YAML installer files to a > sub > >--- > C4/Installer.pm | 43 ++++++++++++++++++++++++++----------------- > 1 file changed, 26 insertions(+), 17 deletions(-) > >diff --git a/C4/Installer.pm b/C4/Installer.pm >index a3f81e556c..a7ca5d807b 100644 >--- a/C4/Installer.pm >+++ b/C4/Installer.pm >@@ -459,6 +459,27 @@ error. > > =cut > >+sub process_yml_table { >+ my ($table) = @_; >+ 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 $query = "INSERT INTO $table_name ( $fields ) VALUES "; >+ my @multiline = @{ $table->{$table_name}->{'multiline'} }; # to check multiline values; >+ my $placeholders = '(' . join ( ",", map { "?" } @columns ) . ')'; # '(?,..,?)' string >+ my @values; >+ foreach my $row ( @rows ) { >+ push @values, map { >+ my $col = $_; >+ ( @multiline and grep { $_ eq $col } @multiline ) >+ ? join "\r\n", @{$row->{$col}} # join multiline values >+ : $row->{$col}; >+ } @columns; >+ } >+ return { query => $query, placeholders => $placeholders, values => \@values }; >+} >+ > sub load_sql { > my $self = shift; > my $filename = shift; >@@ -483,24 +504,12 @@ sub load_sql { > eval { > my $yaml = LoadFile( $filename ); # Load YAML > 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 $query = "INSERT INTO $table_name ( $fields ) VALUES "; >- my @multiline = @{ $table->{$table_name}->{'multiline'} }; # to check multiline values; >- my $placeholders = '(' . join ( ",", map { "?" } @columns ) . ')'; # '(?,..,?)' string >- my @values; >- foreach my $row ( @rows ) { >- push @values, map { >- my $col = $_; >- ( @multiline and grep { $_ eq $col } @multiline ) >- ? join "\r\n", @{$row->{$col}} # join multiline values >- : $row->{$col}; >- } @columns; >- } >+ my $query_info = process_yml_table($table); >+ my $query = $query_info->{query}; >+ my $placeholders = $query_info->{placeholders}; >+ my $values = $query_info->{values}; > # Doing only 1 INSERT query for the whole table >- $query .= join ', ', ( $placeholders ) x scalar @rows; >+ $query .= join ', ', ( $placeholders ) x scalar @values; > $dbh->do( $query, undef, @values ); > } > for my $statement ( @{ $yaml->{'sql_statements'} } ) { # extra SQL statements >-- >2.20.1
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