Bugzilla – Attachment 30493 Details for
Bug 11331
CSV export for viewlog.pl is missing newlines
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[PASSED QA] Bug 11331 - CSV export for viewlog.pl is missing newlines
PASSED-QA-Bug-11331---CSV-export-for-viewlogpl-is-.patch (text/plain), 6.25 KB, created by
Katrin Fischer
on 2014-08-02 20:02:40 UTC
(
hide
)
Description:
[PASSED QA] Bug 11331 - CSV export for viewlog.pl is missing newlines
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2014-08-02 20:02:40 UTC
Size:
6.25 KB
patch
obsolete
>From c2bf2471553721001200ebdfb635ec6e1c7dfc7e Mon Sep 17 00:00:00 2001 >From: Fridolin Somers <fridolin.somers@biblibre.com> >Date: Fri, 25 Jul 2014 17:01:42 +0200 >Subject: [PATCH] [PASSED QA] Bug 11331 - CSV export for viewlog.pl is missing > newlines > >When you try to export the result of tools/viewlog.pl in csv, file >cannot be correctly loaded : > - newline is missing after each record, > - strings should be enclosed in "" > - columns are not the same as for screen output > >This patch corrects this by using like other export Text::CSV. >Adds a header line made with the keys of first data. For that, all data >values are initialiszed with empty string. > >Test plan : >- Use a database with some logs, see sysprefs > /cgi-bin/koha/admin/preferences.pl?tab=logs >- Go to export page /cgi-bin/koha/tools/viewlog.pl >- Select a module >- Click on "To a file" and choose a file name >- Click on "Submit" >- Open file > => Without this patch : newline is missing, multi-lines cells are not > enclosed in "", there are no column headings > => Without this patch : each line is a data line, complexe cells are > enclosed in "", there are column headings >- Test the export of all modules to see that all headings are necessary >- Check the output to screen in the browser > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> > >The CSV export is significantly improved. I question the usefulness of >including biblioitemnumber in the output. A better inclusion would be >itemnumber. > >Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> > >While this feature is still not perfect, this is a big improvement. >Passes tests and QA script, restores basic functionality. >--- > C4/Log.pm | 1 - > tools/viewlog.pl | 62 +++++++++++++++++++++++++++++++++++++------------------- > 2 files changed, 41 insertions(+), 22 deletions(-) > >diff --git a/C4/Log.pm b/C4/Log.pm >index 671fcdb..80c3493 100644 >--- a/C4/Log.pm >+++ b/C4/Log.pm >@@ -241,7 +241,6 @@ sub GetLogs { > > my @logs; > while( my $row = $sth->fetchrow_hashref ) { >- $row->{$row->{module}} = 1; > push @logs , $row; > } > return \@logs; >diff --git a/tools/viewlog.pl b/tools/viewlog.pl >index 3fe7b0a..217530e 100755 >--- a/tools/viewlog.pl >+++ b/tools/viewlog.pl >@@ -18,10 +18,11 @@ > # with Koha; if not, write to the Free Software Foundation, Inc., > # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > >-use strict; >-#use warnings; FIXME - Bug 2505 >+use Modern::Perl; >+ > use C4::Auth; > use CGI; >+use Text::CSV::Encoded; > use C4::Context; > use C4::Koha; > use C4::Dates; >@@ -131,22 +132,31 @@ if ($do_it) { > @data=@$results; > my $total = scalar @data; > foreach my $result (@data){ >+ # Init additional columns for CSV export >+ $result->{'biblionumber'} = q{}; >+ $result->{'biblioitemnumber'} = q{}; >+ $result->{'barcode'} = q{}; >+ $result->{'userfirstname'} = q{}; >+ $result->{'usersurname'} = q{}; >+ $result->{'borrowerfirstname'} = q{}; >+ $result->{'borrowersurname'} = q{}; >+ > if (substr($result->{'info'}, 0, 4) eq 'item' || $result->{module} eq "CIRCULATION"){ > # get item information so we can create a working link > my $itemnumber=$result->{'object'}; > $itemnumber=$result->{'info'} if ($result->{module} eq "CIRCULATION"); > my $item=GetItem($itemnumber); >- $result->{'biblionumber'}=$item->{'biblionumber'}; >- $result->{'biblioitemnumber'}=$item->{'biblionumber'}; >- $result->{'barcode'}=$item->{'barcode'}; >+ if ($item) { >+ $result->{'biblionumber'}=$item->{'biblionumber'}; >+ $result->{'biblioitemnumber'}=$item->{'biblionumber'}; >+ $result->{'barcode'}=$item->{'barcode'}; >+ } > } > #always add firstname and surname for librarian/user > if ($result->{'user'}){ > my $userdetails = C4::Members::GetMemberDetails($result->{'user'}); >- if ($userdetails->{'firstname'}){ >+ if ($userdetails){ > $result->{'userfirstname'} = $userdetails->{'firstname'}; >- } >- if ($userdetails->{'surname'}){ > $result->{'usersurname'} = $userdetails->{'surname'}; > } > } >@@ -154,10 +164,8 @@ if ($do_it) { > if ($result->{module} eq "CIRCULATION" || $result->{module} eq "MEMBERS" || $result->{module} eq "FINES"){ > if($result->{'object'}){ > my $borrowerdetails = C4::Members::GetMemberDetails($result->{'object'}); >- if ($borrowerdetails->{'firstname'}){ >- $result->{'borrowerfirstname'} = $borrowerdetails->{'firstname'}; >- } >- if ($borrowerdetails->{'surname'}){ >+ if ($borrowerdetails){ >+ $result->{'borrowerfirstname'} = $borrowerdetails->{'firstname'}; > $result->{'borrowersurname'} = $borrowerdetails->{'surname'}; > } > } >@@ -187,18 +195,30 @@ if ($do_it) { > output_html_with_http_headers $input, $cookie, $template->output; > } else { > # Printing to a csv file >+ my $content = q{}; >+ my $delimiter = C4::Context->preference('delimiter') || ','; >+ if (@data) { >+ my $csv = Text::CSV::Encoded->new( { encoding_out => 'utf8', sep_char => $delimiter } ); >+ $csv or die "Text::CSV::Encoded->new FAILED: " . Text::CSV::Encoded->error_diag(); >+ # First line with heading >+ # Exporting bd id seems useless >+ my @headings = grep { $_ ne 'action_id' } sort keys $data[0]; >+ if ( $csv->combine( @headings ) ) { >+ $content .= $csv->string() . "\n"; >+ } >+ # Lines of logs >+ foreach my $line (@data) { >+ my @cells = map { $line->{$_} } @headings; >+ if ( $csv->combine( @cells ) ) { >+ $content .= $csv->string() . "\n"; >+ } >+ } >+ } > print $input->header( > -type => 'text/csv', >- -attachment => "$basename.csv", >- -filename => "$basename.csv" >+ -attachment => $basename . '.csv', > ); >- my $sep = C4::Context->preference("delimiter"); >- foreach my $line (@data) { >- #next unless $modules[0] eq "catalogue"; >- foreach (qw(timestamp firstname surname action info title author)) { >- print $line->{$_} . $sep; >- } >- } >+ print $content; > } > exit; > } else { >-- >1.9.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 11331
:
23265
|
30264
|
30265
|
30466
|
30467
| 30493 |
30494