Bug 12721 - Prevent software error if incorrect fieldnames given in sypref StatisticsFields
To reproduce issue:
See comment #1
To test:
- Apply patch
- Leave syspref StatisticsFields empty
- Display statistics for an author
=> Result: Table displays Shelving location, Collection code, Item type
(as before)
- Change syspref to any combination of location|itype|ccode
=> Result: Table displays columns as appropriate
- Change syspref to some garbage
=> Result: Same as with empty syspref (was crashing without patch)
- Change syspref to valid combination with trailing |
=> Result: Table displays columns as appropriate (was crashing
without patch)
- Change syspref to a combination of valid and invalid fields
(location|blah|ccode)
=> Result: Table displays column of valid fields only (was crashing
without patch)
Signed-off-by: Aleisha <aleishaamohia@hotmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
(cherry picked from commit 5fc93bce9b)
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
This commit is contained in:
parent
f6694ce92f
commit
36392d8a0c
|
|
@ -43,13 +43,34 @@ BEGIN {
|
|||
|
||||
our $fields = get_fields();
|
||||
|
||||
|
||||
=head2 get_fields
|
||||
Get fields form syspref 'StatisticsFields'
|
||||
Returns list of valid fields, defaults to 'location|itype|ccode'
|
||||
if syspref is empty or does not contain valid fields
|
||||
=cut
|
||||
|
||||
|
||||
sub get_fields {
|
||||
my $r = C4::Context->preference('StatisticsFields') || 'location|itype|ccode';
|
||||
unless ( $r =~ m/^(\w|\d|\||-)+$/) {
|
||||
warn "Members/Statistics : Bad value for syspref StatisticsFields" if $debug;
|
||||
$r = 'location|itype|ccode';
|
||||
|
||||
my $syspref = C4::Context->preference('StatisticsFields');
|
||||
my $ret;
|
||||
|
||||
if ( $syspref ) {
|
||||
my @ret;
|
||||
my @spfields = split ('\|', $syspref);
|
||||
my $dbh=C4::Context->dbh;
|
||||
my $sth = $dbh->prepare('SHOW COLUMNS FROM items');
|
||||
$sth->execute;
|
||||
my $dbfields = $sth->fetchall_hashref('Field');
|
||||
$sth->finish();
|
||||
|
||||
foreach my $fn ( @spfields ) {
|
||||
push ( @ret, $fn ) if ( $dbfields->{ $fn } );
|
||||
}
|
||||
$ret = join( '|', @ret);
|
||||
}
|
||||
return $r;
|
||||
return $ret || 'location|itype|ccode';
|
||||
}
|
||||
|
||||
=head2 construct_query
|
||||
|
|
|
|||
Loading…
Reference in New Issue