Bugzilla – Attachment 94688 Details for
Bug 23892
Code related to import/export biblio frameworks in XML format must be removed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23892: wip - does not work
Bug-23892-wip---does-not-work.patch (text/plain), 12.10 KB, created by
Jonathan Druart
on 2019-10-24 16:28:35 UTC
(
hide
)
Description:
Bug 23892: wip - does not work
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2019-10-24 16:28:35 UTC
Size:
12.10 KB
patch
obsolete
>From 36d4cfaf82b5dd6e1e97ef7d348b9d3f3c602974 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 24 Oct 2019 18:28:19 +0200 >Subject: [PATCH] Bug 23892: wip - does not work > >--- > C4/ImportExportFramework.pm | 173 +++++--------------------------------------- > 1 file changed, 17 insertions(+), 156 deletions(-) > >diff --git a/C4/ImportExportFramework.pm b/C4/ImportExportFramework.pm >index d4a11cabc5..bfd27e0148 100644 >--- a/C4/ImportExportFramework.pm >+++ b/C4/ImportExportFramework.pm >@@ -40,41 +40,6 @@ BEGIN { > ); > } > >- >-use constant XMLSTR => '<?xml version="1.0" encoding="UTF-8"?> >-<?mso-application progid="Excel.Sheet"?> >-<Workbook >- xmlns:x="urn:schemas-microsoft-com:office:excel" >- xmlns="urn:schemas-microsoft-com:office:spreadsheet" >- xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> >- >-<Styles> >- <Style ss:ID="Default" ss:Name="Normal"> >- <Alignment ss:Vertical="Bottom"/> >- <Borders/> >- <Font/> >- <Interior/> >- <NumberFormat/> >- <Protection/> >- </Style> >- <Style ss:ID="s27"> >- <Font x:Family="Swiss" ss:Color="#0000FF" ss:Bold="1"/> >- </Style> >- <Style ss:ID="s21"> >- <NumberFormat ss:Format="yyyy\-mm\-dd"/> >- </Style> >- <Style ss:ID="s22"> >- <NumberFormat ss:Format="yyyy\-mm\-dd\ hh:mm:ss"/> >- </Style> >- <Style ss:ID="s23"> >- <NumberFormat ss:Format="hh:mm:ss"/> >- </Style> >-</Styles> >- >-</Workbook> >-'; >- >- > use constant ODSSTR => '<?xml version="1.0" encoding="UTF-8"?> > <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" office:version="1.0"> > <office:scripts/> >@@ -171,7 +136,7 @@ use constant ODS_MANIFEST_STR => '<?xml version="1.0" encoding="UTF-8"?> > > =head1 NAME > >-C4::ImportExportFramework - Import/Export Framework to Excel-xml/ODS Module Functions >+C4::ImportExportFramework - Import/Export Framework to CSV or ODS Module Functions > > =head1 SYNOPSIS > >@@ -179,10 +144,10 @@ C4::ImportExportFramework - Import/Export Framework to Excel-xml/ODS Module Func > > =head1 DESCRIPTION > >-Module to Import/Export Framework to Excel-xml/ODS on intranet administration - MARC Frameworks section >+Module to Import/Export Framework to CSV or ODS on intranet administration - MARC Frameworks section > >-Module to Import/Export Framework to Excel-xml/ODS on intranet administration - MARC Frameworks section >-exporting the tables marc_tag_structure, marc_subfield_structure to excel-xml/ods or viceversa >+Module to Import/Export Framework to CSV or ODS on intranet administration - MARC Frameworks section >+exporting the tables marc_tag_structure, marc_subfield_structure to csv/ods or viceversa > > Functions for handling import/export. > >@@ -193,7 +158,7 @@ Functions for handling import/export. > > =head2 ExportFramework > >-Export all the information of a Framework to an excel "xml" file or OpenDocument SpreadSheet "ods" file. >+Export all the information of a Framework to a CSV file or OpenDocument SpreadSheet "ods" file. > > return : > succes >@@ -209,18 +174,15 @@ sub ExportFramework > my $dom; > my $root; > my $elementSS; >- if ($mode eq 'ods' || $mode eq 'excel') { >+ if ($mode eq 'ods') { > eval { > my $parser = XML::LibXML->new(); >- $dom = $parser->parse_string(($mode && $mode eq 'ods')?ODSSTR:XMLSTR); >+ $dom = $parser->parse_string(ODSSTR); > if ($dom) { >- $root = $dom->documentElement(); >- if ($mode && $mode eq 'ods') { >- my $elementBody = $dom->createElement('office:body'); >- $root->appendChild($elementBody); >- $elementSS = $dom->createElement('office:spreadsheet'); >- $elementBody->appendChild($elementSS); >- } >+ my $elementBody = $dom->createElement('office:body'); >+ $root->appendChild($elementBody); >+ $elementSS = $dom->createElement('office:spreadsheet'); >+ $elementBody->appendChild($elementSS); > } > }; > if ($@) { >@@ -229,9 +191,9 @@ sub ExportFramework > } > } > >- if (_export_table('marc_tag_structure', $dbh, ($mode eq 'csv')?$xmlStrRef:$dom, ($mode eq 'ods')?$elementSS:$root, $frameworkcode, $mode)) { >- if (_export_table('marc_subfield_structure', $dbh, ($mode eq 'csv')?$xmlStrRef:$dom, ($mode eq 'ods')?$elementSS:$root, $frameworkcode, $mode)) { >- $$xmlStrRef = $dom->toString(1) if ($mode eq 'ods' || $mode eq 'excel'); >+ if (_export_table('marc_tag_structure', $dbh, ($mode eq 'csv')?$xmlStrRef:$dom, $elementSS, $frameworkcode, $mode)) { >+ if (_export_table('marc_subfield_structure', $dbh, ($mode eq 'csv')?$xmlStrRef:$dom, $elementSS, $frameworkcode, $mode)) { >+ $$xmlStrRef = $dom->toString(1) if ($mode eq 'ods'); > return 1; > } > } >@@ -250,8 +212,6 @@ sub _export_table > _export_table_csv($table, $dbh, $dom, $root, $frameworkcode); > } elsif ($mode eq 'ods') { > _export_table_ods($table, $dbh, $dom, $root, $frameworkcode); >- } else { >- _export_table_excel($table, $dbh, $dom, $root, $frameworkcode); > } > } > >@@ -369,76 +329,6 @@ sub _export_table_ods > }#_export_table_ods > > >-# Export the mysql table to an excel-xml (openoffice/libreoffice compatible) file >-sub _export_table_excel >-{ >- my ($table, $dbh, $dom, $root, $frameworkcode) = @_; >- >- eval { >- my $elementWS = $dom->createElement('Worksheet'); >- $elementWS->setAttribute('ss:Name', $table); >- $root->appendChild($elementWS); >- my $elementTable = $dom->createElement('ss:Table'); >- $elementWS->appendChild($elementTable); >- my $elementRow = $dom->createElement('ss:Row'); >- $elementTable->appendChild($elementRow); >- >- # First row with the name of the columns >- my $elementCell; >- my $elementData; >- my $query = 'SHOW COLUMNS FROM ' . $table; >- my $sth = $dbh->prepare($query); >- $sth->execute(); >- my @fields = (); >- while (my $hashRef = $sth->fetchrow_hashref) { >- $elementCell = $dom->createElement('ss:Cell'); >- $elementCell->setAttribute('ss:StyleID', 's27'); >- $elementRow->appendChild($elementCell); >- $elementData = $dom->createElement('ss:Data'); >- $elementData->setAttribute('ss:Type', 'String'); >- $elementCell->appendChild($elementData); >- $elementData->appendTextNode($hashRef->{Field}); >- push @fields, {name => $hashRef->{Field}, type => ($hashRef->{Type} =~ /int/i)?'Number':'String'}; >- } >- # Populate rows with the data from mysql >- $query = 'SELECT * FROM ' . $table . ' WHERE frameworkcode=?'; >- $sth = $dbh->prepare($query); >- $sth->execute($frameworkcode); >- my $data; >- while (my $hashRef = $sth->fetchrow_hashref) { >- $elementRow = $dom->createElement('ss:Row'); >- $elementTable->appendChild($elementRow); >- for (@fields) { >- $elementCell = $dom->createElement('ss:Cell'); >- $elementRow->appendChild($elementCell); >- $elementData = $dom->createElement('ss:Data'); >- $elementData->setAttribute('ss:Type', $_->{type}); >- $elementCell->appendChild($elementData); >- $data = $hashRef->{$_->{name}}; >- if ($_->{type} eq 'Number' && !defined($data)) { >- $data = '0'; >- } elsif ($_->{type} eq 'String' && !defined($data)) { >- $data = q{}; >- } elsif ($_->{type} eq 'String' && (!$data && $data ne '0')) { >- $data = '#'; >- } >- $elementData->appendTextNode(($_->{type} eq 'String')?_parseContent2Xml($data):$data); >- } >- } >- }; >- if ($@) { >- $debug and warn "Error _export_table_excel $@\n"; >- return 0; >- } >- return 1; >-}#_export_table_excel >- >- >- >- >- >- >- > # Format chars problematics to a correct format for xml. > sub _parseContent2Xml > { >@@ -623,7 +513,7 @@ sub _getMeta > > =head2 ImportFramework > >-Import all the information of a Framework from a excel-xml/ods file. >+Import all the information of a Framework from a csv or ods file. > > return : > success >@@ -786,7 +676,7 @@ sub _check_validity_worksheet > }#_check_validity_worksheet > > >-# Import the data from an excel-xml/ods to mysql tables. >+# Import the data from a csv or ods to mysql tables. > sub _import_table > { > my ($dbh, $table, $frameworkcode, $dom, $PKArray, $format) = @_; >@@ -823,8 +713,6 @@ sub _import_table > $ok = _import_table_csv($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, \@fieldsName); > } elsif ($format eq 'ods') { > $ok = _import_table_ods($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete); >- } else { >- $ok = _import_table_excel($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete); > } > if ($ok) { > if (($ok = scalar(keys %fields2Delete)) > 0) { >@@ -908,7 +796,7 @@ sub _processRows_Table > my @fieldsPK = @$PKArray; > shift @fieldsPK; > while ($nodeR) { >- if ($nodeR->nodeType == 1 && (($format && $format eq 'ods' && $nodeR->nodeName =~ /(?:table:)?table-row/) || ($nodeR->nodeName =~ /(?:ss:)?Row/)) && $nodeR->hasChildNodes()) { >+ if ($nodeR->nodeType == 1 && (($nodeR->nodeName =~ /(?:table:)?table-row/) || ($nodeR->nodeName =~ /(?:ss:)?Row/)) && $nodeR->hasChildNodes()) { > if ($j == 0) { > # Get name columns > _getFields($nodeR, \@fields, $format); >@@ -1037,33 +925,6 @@ sub _import_table_ods > return 0; > }#_import_table_ods > >- >-# Import worksheet from the excel-xml file to the mysql table >-sub _import_table_excel >-{ >- my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete) = @_; >- >- my $xc = XML::LibXML::XPathContext->new($dom); >- $xc->registerNs('xmlns','urn:schemas-microsoft-com:office:spreadsheet'); >- $xc->registerNs('xmlns:ss','urn:schemas-microsoft-com:office:spreadsheet'); >- $xc->registerNs('xmlns:x','urn:schemas-microsoft-com:office:excel'); >- my @nodes; >- @nodes = $xc->findnodes('//ss:Worksheet[@ss:Name="' . $table . '"]'); >- if (@nodes > 0) { >- for (my $i=0; $i < @nodes; $i++) { >- my @nodesT = $nodes[$i]->getElementsByTagNameNS('urn:schemas-microsoft-com:office:spreadsheet', 'Table'); >- if (@nodesT == 1 && $nodesT[0]->hasChildNodes()) { >- my $nodeR = $nodesT[0]->firstChild; >- return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, undef, $fields2Delete); >- } >- } >- } else { >- $debug and warn "Error _import_table_excel there's not worksheet for $table\n"; >- } >- return 0; >-}#_import_table_excel >- >- > # Get the data from a cell on a ods file through the value attribute or the text node > sub _getDataNodeODS > { >-- >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 23892
: 94688