From b26174ba0aa0f2ca7d475a8598e0fffc867593bd Mon Sep 17 00:00:00 2001 From: Bernardo Gonzalez Kriegel Date: Fri, 8 Jun 2018 08:23:34 -0300 Subject: [PATCH] Bug 13897: C4/Installer.pm - process XML files This patch modifies C4/Installer.pm to add support for processing of XML files into database. For MySQL only --- C4/Installer.pm | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/C4/Installer.pm b/C4/Installer.pm index 1a5c037a42..a9a3e8d554 100644 --- a/C4/Installer.pm +++ b/C4/Installer.pm @@ -21,6 +21,7 @@ use Modern::Perl; use Encode qw( encode is_utf8 ); use DBIx::RunSQL; +use XML::LibXML; use C4::Context; use C4::Installer::PerlModules; use DBI; @@ -145,7 +146,7 @@ sub marc_framework_sql_list { foreach my $requirelevel (@listdir) { opendir( MYDIR, "$dir/$requirelevel" ); - my @listname = grep { !/^\./ && -f "$dir/$requirelevel/$_" && $_ =~ m/\.sql$/ } readdir(MYDIR); + my @listname = grep { !/^\./ && -f "$dir/$requirelevel/$_" && $_ =~ m/\.(sql|xml)$/ } readdir(MYDIR); closedir MYDIR; my %cell; my @frameworklist; @@ -453,12 +454,23 @@ sub load_sql { local *STDERR; open STDERR, ">>", \$dup_stderr; - eval { - DBIx::RunSQL->run_sql_file( - dbh => $dbh, - sql => $filename, - ); - }; + if ( $filename =~ /xml$/ ) { + eval { + my $dom = XML::LibXML->load_xml( location => $filename ); # Load XML + my $table = $dom->documentElement->nodeName; # Find table name + my $query = "LOAD XML LOCAL INFILE '".$filename."' INTO TABLE ".$table; # MySQL only + my $loadxml = $dbh->prepare($query); + $loadxml->execute(); + }; + } + else { + eval { + DBIx::RunSQL->run_sql_file( + dbh => $dbh, + sql => $filename, + ); + }; + } }; # errors thrown while loading installer data should be logged if( $dup_stderr ) { -- 2.17.0