Bugzilla – Attachment 101902 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.79 KB, created by
Martin Renvoize (ashimema)
on 2020-03-26 18:15:50 UTC
(
hide
)
Description:
Bug 24883: Centralize code to load YAML installer files to a sub
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-03-26 18:15:50 UTC
Size:
3.79 KB
patch
obsolete
>From a8ba2a3c6acf9d2bf870dfcc74e021e6325702dc 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 > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > C4/Installer.pm | 43 ++++++++++++++++++++++++++----------------- > 1 file changed, 26 insertions(+), 17 deletions(-) > >diff --git a/C4/Installer.pm b/C4/Installer.pm >index 7dd4f42095..c0ff508519 100644 >--- a/C4/Installer.pm >+++ b/C4/Installer.pm >@@ -485,6 +485,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; >@@ -509,24 +530,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