Bugzilla – Attachment 86551 Details for
Bug 13952
Import and export of authority types
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13952: (follow-up) Fixing authority type import
Bug-13952-follow-up-Fixing-authority-type-import.patch (text/plain), 12.31 KB, created by
Michal Denar
on 2019-03-12 20:35:15 UTC
(
hide
)
Description:
Bug 13952: (follow-up) Fixing authority type import
Filename:
MIME Type:
Creator:
Michal Denar
Created:
2019-03-12 20:35:15 UTC
Size:
12.31 KB
patch
obsolete
>From 1b54985f05132e0f2d9241347c218a33e14193d3 Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleishaamohia@hotmail.com> >Date: Mon, 19 Jun 2017 01:00:19 +0000 >Subject: [PATCH] Bug 13952: (follow-up) Fixing authority type import > >This patch fixes the comments from Comment 29 and the import >functionality. You should now be able to import an exported file without >editing the file at all and the authority type code will be overwritten >in the file (same behaviour as biblio frameworks). > >Sponsored-by: Catalyst IT > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >Signed-off-by: Michal Denar <black23@gmail.com> > >Signed-off-by: Michal Denar <black23@gmail.com> >--- > C4/ImportExportFramework.pm | 64 +++++++++++++++++++++++++++------------- > admin/import_export_authtype.pl | 12 ++------ > admin/import_export_framework.pl | 7 +---- > 3 files changed, 47 insertions(+), 36 deletions(-) > >diff --git a/C4/ImportExportFramework.pm b/C4/ImportExportFramework.pm >index ae7b8235ec..8b0212398d 100644 >--- a/C4/ImportExportFramework.pm >+++ b/C4/ImportExportFramework.pm >@@ -684,11 +684,21 @@ sub ImportFramework > # Process both tables > my $numDeleted = 0; > my $numDeletedAux = 0; >- if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['frameworkcode', 'tagfield'], $extension, $frameworktype)) >= 0) { >- $numDeleted += $numDeletedAux if ($numDeletedAux > 0); >- if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['frameworkcode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) { >+ if ($frameworktype eq "authority"){ >+ if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['authtypecode', 'tagfield'], $extension, $frameworktype)) >= 0) { > $numDeleted += $numDeletedAux if ($numDeletedAux > 0); >- $ok = ($numDeleted > 0)?$numDeleted:0; >+ if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['authtypecode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) { >+ $numDeleted += $numDeletedAux if ($numDeletedAux > 0); >+ $ok = ($numDeleted > 0)?$numDeleted:0; >+ } >+ } >+ } else { >+ if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['frameworkcode', 'tagfield'], $extension, $frameworktype)) >= 0) { >+ $numDeleted += $numDeletedAux if ($numDeletedAux > 0); >+ if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['frameworkcode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) { >+ $numDeleted += $numDeletedAux if ($numDeletedAux > 0); >+ $ok = ($numDeleted > 0)?$numDeleted:0; >+ } > } > } > } else { >@@ -841,11 +851,11 @@ sub _import_table > push @fieldsName, $hashRef->{Field}; > } > }; >- $ok = _import_table_csv($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, \@fieldsName); >+ $ok = _import_table_csv($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, \@fieldsName, $frameworktype); > } elsif ($format eq 'ods') { >- $ok = _import_table_ods($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete); >+ $ok = _import_table_ods($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, $frameworktype); > } else { >- $ok = _import_table_excel($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete); >+ $ok = _import_table_excel($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, $frameworktype); > } > if ($ok) { > if (($ok = scalar(keys %fields2Delete)) > 0) { >@@ -916,7 +926,7 @@ sub _processRow_DB > # Process the rows of a worksheet and insert/update them in a mysql table. > sub _processRows_Table > { >- my ($dbh, $frameworkcode, $nodeR, $table, $PKArray, $format, $fields2Delete) = @_; >+ my ($dbh, $frameworkcode, $nodeR, $table, $PKArray, $format, $fields2Delete, $frameworktype) = @_; > > my $query; > my @fields = (); >@@ -943,7 +953,7 @@ sub _processRows_Table > chop($updateStr) if ($updateStr); > } else { > # Get data from row >- my ($dataFields, $dataFieldsR) = _getDataFields($frameworkcode, $nodeR, \@fields, $format); >+ my ($dataFields, $dataFieldsR) = _getDataFields($frameworkcode, $nodeR, \@fields, $format, $frameworktype); > if (scalar(@fields) == scalar(@$dataFieldsR)) { > $ok = _processRow_DB($dbh, $db_scheme, $table, $fields, $dataStr, $updateStr, $dataFieldsR, $dataFields, $PKArray, \@fieldsPK, $fields2Delete); > } >@@ -961,8 +971,7 @@ sub _processRows_Table > # Import worksheet from the csv file to the mysql table > sub _import_table_csv > { >- my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $fields) = @_; >- >+ my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $fields, $frameworktype) = @_; > my $row = ''; > my $partialRow = ''; > my $numFields = @$fields; >@@ -1018,13 +1027,23 @@ sub _import_table_csv > my $j = 0; > my %dataFields = (); > for (@arrData) { >- if ($fields->[$j] eq 'frameworkcode' && $_ ne $frameworkcode) { >- $dataFields{$fields->[$j]} = $frameworkcode; >- $arrData[$j] = $frameworkcode; >+ if ($frameworktype eq "authority"){ >+ if ($fields->[$j] eq 'authtypecode' && $_ ne $frameworkcode) { >+ $dataFields{$fields->[$j]} = $frameworkcode; >+ $arrData[$j] = $frameworkcode; >+ } else { >+ $dataFields{$fields->[$j]} = $_; >+ } >+ $j++ > } else { >- $dataFields{$fields->[$j]} = $_; >+ if ($fields->[$j] eq 'frameworkcode' && $_ ne $frameworkcode) { >+ $dataFields{$fields->[$j]} = $frameworkcode; >+ $arrData[$j] = $frameworkcode; >+ } else { >+ $dataFields{$fields->[$j]} = $_; >+ } >+ $j++ > } >- $j++ > } > $ok = _processRow_DB($dbh, $db_scheme, $table, $fieldsStr, $dataStr, $updateStr, \@arrData, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete); > } >@@ -1041,7 +1060,7 @@ sub _import_table_csv > # Import worksheet from the ods content.xml file to the mysql table > sub _import_table_ods > { >- my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete) = @_; >+ my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $frameworktype) = @_; > > my $xc = XML::LibXML::XPathContext->new($dom); > $xc->registerNs('xmlns:office','urn:oasis:names:tc:opendocument:xmlns:office:1.0'); >@@ -1051,7 +1070,7 @@ sub _import_table_ods > @nodes = $xc->findnodes('//table:table[@table:name="' . $table . '"]'); > if (@nodes == 1 && $nodes[0]->hasChildNodes()) { > my $nodeR = $nodes[0]->firstChild; >- return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, 'ods', $fields2Delete); >+ return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, 'ods', $fields2Delete, $frameworktype); > } else { > $debug and warn "Error _import_table_ods there's not worksheet for $table\n"; > } >@@ -1062,7 +1081,7 @@ sub _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 ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $frameworktype) = @_; > > my $xc = XML::LibXML::XPathContext->new($dom); > $xc->registerNs('xmlns','urn:schemas-microsoft-com:office:spreadsheet'); >@@ -1075,7 +1094,7 @@ sub _import_table_excel > 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); >+ return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, undef, $fields2Delete, $frameworktype); > } > } > } else { >@@ -1112,7 +1131,7 @@ sub _getDataNodeODS > # Get the data from a row of a spreadsheet > sub _getDataFields > { >- my ($frameworkcode, $node, $fields, $format) = @_; >+ my ($frameworkcode, $node, $fields, $format, $frameworktype) = @_; > > my $dataFields = {}; > my @dataFieldsA = (); >@@ -1139,6 +1158,9 @@ sub _getDataFields > if ($ok) { > $data = '' if ($data eq '#'); > $data = $frameworkcode if ($fields->[$i] eq 'frameworkcode'); >+ if ($frameworktype eq "authority") { >+ $data = $frameworkcode if ($fields->[$i] eq 'authtypecode'); >+ } > $dataFields->{$fields->[$i]} = $data; > push @dataFieldsA, $data; > $i++; >diff --git a/admin/import_export_authtype.pl b/admin/import_export_authtype.pl >index cbf4a168a2..05cdb7cdbf 100755 >--- a/admin/import_export_authtype.pl >+++ b/admin/import_export_authtype.pl >@@ -17,9 +17,7 @@ > # You should have received a copy of the GNU General Public License > # along with Koha; if not, see <http://www.gnu.org/licenses>. > >- >-use strict; >-use warnings; >+use Modern::Perl; > use CGI qw ( -utf8 ); > use CGI::Cookie; > use C4::Context; >@@ -27,7 +25,6 @@ use C4::Auth qw/check_cookie_auth/; > use C4::ImportExportFramework; > > my %cookies = CGI::Cookie->fetch(); >-my $authenticated = 0; > my ($auth_status, $sessionID); > if (exists $cookies{'CGISESSID'}) { > ($auth_status, $sessionID) = check_cookie_auth( >@@ -35,13 +32,10 @@ if (exists $cookies{'CGISESSID'}) { > { parameters => 'parameters_remaining_permissions' }, > ); > } >-if ($auth_status eq 'ok') { >- $authenticated = 1; >-} > > my $input = new CGI; > >-unless ($authenticated) { >+unless ($auth_status eq 'ok') { > print $input->header(-type => 'text/plain', -status => '403 Forbidden'); > exit 0; > } >@@ -88,7 +82,7 @@ if ($action eq 'export' && $input->request_method() eq 'GET') { > my $extension = $1; > my $uploadFd = $input->upload($fieldname); > if ($uploadFd && !$input->cgi_error) { >- my $tmpfilename = $input->tmpFileName($input->param($fieldname)); >+ my $tmpfilename = $input->tmpFileName(scalar $input->param($fieldname)); > $filename = $tmpfilename . '.' . $extension; # rename the tmp file with the extension > $ok = ImportFramework($filename, $authtypecode, 1, 'authority') if (rename($tmpfilename, $filename)); > } >diff --git a/admin/import_export_framework.pl b/admin/import_export_framework.pl >index 56c6efa892..c0017fa97f 100755 >--- a/admin/import_export_framework.pl >+++ b/admin/import_export_framework.pl >@@ -17,7 +17,6 @@ > # You should have received a copy of the GNU General Public License > # along with Koha; if not, see <http://www.gnu.org/licenses>. > >- > use Modern::Perl; > use CGI qw ( -utf8 ); > use CGI::Cookie; >@@ -26,7 +25,6 @@ use C4::Auth qw/check_cookie_auth/; > use C4::ImportExportFramework; > > my %cookies = CGI::Cookie->fetch(); >-my $authenticated = 0; > my ($auth_status, $sessionID); > if (exists $cookies{'CGISESSID'}) { > ($auth_status, $sessionID) = check_cookie_auth( >@@ -34,13 +32,10 @@ if (exists $cookies{'CGISESSID'}) { > { parameters => 'manage_marc_frameworks' }, > ); > } >-if ($auth_status eq 'ok') { >- $authenticated = 1; >-} > > my $input = new CGI; > >-unless ($authenticated) { >+unless ($auth_status eq 'ok') { > print $input->header(-type => 'text/plain', -status => '403 Forbidden'); > exit 0; > } >-- >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 13952
:
44770
|
47326
|
47360
|
47364
|
50046
|
53065
|
53066
|
54840
|
54899
|
54900
|
57873
|
59831
|
64421
|
67914
|
67915
|
68299
|
68300
|
68301
|
68502
|
68512
|
68513
|
68514
|
68515
|
68556
|
69940
|
69941
|
69942
|
69943
|
69944
|
76665
|
76666
|
76667
|
76668
|
80794
|
80795
|
80796
|
80797
|
81248
|
82853
|
82854
|
82855
|
82856
|
82895
|
83024
|
83025
|
83026
|
83027
|
83028
|
85073
|
86549
|
86550
|
86551
|
86552
|
86553
|
86554
|
86555
|
103610
|
103611
|
103612
|
103613
|
103614
|
103615
|
103616
|
114170
|
114171
|
114172
|
114173
|
114174
|
114175
|
114176
|
114177
|
115379
|
115381
|
115382
|
115383
|
115384
|
115385
|
115386
|
115387
|
115388
|
125383
|
125384
|
125385
|
125386
|
125387
|
125388
|
125389
|
125390
|
128316
|
128317
|
128318
|
128319
|
128320
|
128321
|
128322
|
128323
|
128324
|
128325
|
128326
|
128327
|
128328
|
128329
|
128330
|
128331
|
130587
|
130917
|
130918
|
130919
|
130920
|
130921
|
130922
|
130923
|
130924
|
130925