Skip to content

Commit

Permalink
US808: cleanups to patron search code
Browse files Browse the repository at this point in the history
US808: SearchMember() now returns empty set if search string is empty.

US808: add index to statistics table.
  • Loading branch information
pjones9 committed Aug 19, 2010
1 parent a4b2c69 commit bfb8c9e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 37 deletions.
55 changes: 19 additions & 36 deletions C4/Members.pm
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ sub SearchMember {
my $count;
my @data;
my @bind = ();


# FIXME: find where in members.pl this function is being called a second time with no args
return (0, undef) if not defined $searchstring or $searchstring eq '';

# this is used by circulation everytime a new borrowers cardnumber is scanned
# so we can check an exact match first, if that works return, otherwise do the rest
my $cardnum = _prefix_cardnum($searchstring);
Expand Down Expand Up @@ -218,49 +221,29 @@ sub SearchMember {
$query.=" borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'})." AND " unless (C4::Context->userenv->{'branch'} eq "insecure");
}
}
$query.="((surname LIKE ?
$query .= '(';
for ( my $i = 0 ; $i < $count ; $i++ ) {
$query .= "(surname LIKE ?
OR firstname LIKE ?
OR othernames LIKE ?
OR initials LIKE ?)
" .
($category_type?" AND category_type = ".$dbh->quote($category_type):"");
# my $regex = '[[:punct:][:space:]]'.$data[0];
@bind = (
"$data[0]%",
"$data[0]%",
"$data[0]%",
"$data[0]%"
);
for ( my $i = 1 ; $i < $count ; $i++ ) {
$query = $query . " AND (" . " surname LIKE ?
OR firstname LIKE ?
OR othernames LIKE ?
OR initials LIKE ? )";
#$regex = '[[:punct:][:space:]]'.$data[$i];
push( @bind,
"$data[$i]%",
"$data[$i]%",
"$data[$i]%",
"$data[$i]%"
);

# FIXME - .= <<EOT;
OR initials LIKE ? ) AND ";
push( @bind, "$data[$i]%", "$data[$i]%", "$data[$i]%", "$data[$i]%" );
}
$query = $query . ") OR cardnumber LIKE ? ";
$query =~ s/ AND $/ /;
($category_type?" AND category_type = ".$dbh->quote($category_type):"");
$query .= ") OR cardnumber LIKE ? ";
push( @bind, $searchstring );
if (C4::Context->preference('ExtendedPatronAttributes')) {
$query .= "OR borrowernumber IN (
SELECT borrowernumber
FROM borrower_attributes
JOIN borrower_attribute_types USING (code)
WHERE staff_searchable = 1
AND attribute like ?
)";
SELECT borrowernumber
FROM borrower_attributes
JOIN borrower_attribute_types USING (code)
WHERE staff_searchable = 1
AND attribute like ?
)";
push (@bind, $searchstring);
}
$query .= "order by $orderby";

# FIXME - .= <<EOT;
}

$sth = $dbh->prepare($query);
Expand All @@ -275,7 +258,7 @@ AND attribute like ?
$query = "SELECT borrowers.*, categories.* FROM borrowers
LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
LEFT JOIN statistics ON borrowers.borrowernumber = statistics.borrowernumber
WHERE statistics.type = 'card_replaced' AND statistics.other = ? GROUP BY statistics.other";
WHERE statistics.type = 'card_replaced' AND statistics.other = ?";
$sth = $dbh->prepare( $query );
$sth->execute( $searchstring );
my $prevcards_data = $sth->fetchall_arrayref({});
Expand Down
6 changes: 6 additions & 0 deletions install_misc/ptfs_update.pl
Original file line number Diff line number Diff line change
Expand Up @@ -772,5 +772,11 @@
EOF2
;

print "Adding index to statistics table for lost card number extraction.\n";
$dbh->do("create index s_lostcard on statistics (borrowernumber, type)");
print ".";
print "done!\n";
print "==========\n";

$dbh -> do("UPDATE systempreferences SET value='1.1' WHERE variable='KohaPTFSVersion'");
}
3 changes: 2 additions & 1 deletion installer/data/mysql/kohastructure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,8 @@ CREATE TABLE `statistics` (
`itemtype` varchar(10) default NULL,
`borrowernumber` int(11) default NULL,
`associatedborrower` int(11) default NULL,
KEY `timeidx` (`datetime`)
KEY `timeidx` (`datetime`),
KEY `s_lostcard` (`borrowernumber`,`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
Expand Down

0 comments on commit bfb8c9e

Please sign in to comment.