[Koha-patches] [PATCH] Fixes bug 4201: Holds priority listings assigning large numbers

Ian Walls ian.walls at bywatersolutions.com
Tue Mar 30 16:53:56 CEST 2010


This patch comes with a cleanup script, which is attached to the bug report
for bug 4201 (http://bugs.koha.org/cgi-bin/bugzilla3/show_bug.cgi?id=4201).
 This cleanup script will reorder the holds priorities, by date placed
first, then by existing priority number (for multiple holds on the same
day).  SQL can be modified if this is counter to the libraries intent.

This patch does not solve the synchronous holds problem described at
http://www.nexpresslibrary.org/placing-and-processing-simultaneous-holds-issues/,
unfortunately.

Cheers,

Ian

On Mon, Mar 29, 2010 at 8:52 AM, Ian Walls
<ian.walls at bywatersolutions.com>wrote:

> ---
>  C4/Reserves.pm |   31 +++++++++++++++----------------
>  1 files changed, 15 insertions(+), 16 deletions(-)
>
> diff --git a/C4/Reserves.pm b/C4/Reserves.pm
> index fee4fce..5c70c08 100644
> --- a/C4/Reserves.pm
> +++ b/C4/Reserves.pm
> @@ -1787,32 +1787,31 @@ sub _ShiftPriorityByDateAndPriority {
>     my ( $biblio, $resdate, $new_priority ) = @_;
>
>     my $dbh = C4::Context->dbh;
> -    my $query = "SELECT priority FROM reserves WHERE biblionumber = ? AND
> ( reservedate > ? OR priority > ? ) ORDER BY priority ASC";
> +    my $query = "SELECT priority FROM reserves WHERE biblionumber = ? AND
> ( reservedate > ? OR priority > ? ) ORDER BY priority ASC LIMIT 1";
>     my $sth = $dbh->prepare( $query );
>     $sth->execute( $biblio, $resdate, $new_priority );
> -    my ( $min_priority ) = $sth->fetchrow;
> -    $sth->finish;  # $sth might have more data.
> +    my $min_priority = $sth->fetchrow;
> +    # if no such matches are found, $new_priority remains as original
> value
>     $new_priority = $min_priority if ( $min_priority );
> -    my $updated_priority = $new_priority + 1;
>
> -    $query = "
> - UPDATE reserves
> -    SET priority = ?
> -  WHERE biblionumber = ?
> -    AND borrowernumber = ?
> -    AND reservedate = ?
> -    AND found IS NULL";
> +    # Shift the priority up by one; works in conjunction with the next SQL
> statement
> +    $query = "UPDATE reserves
> +              SET priority = priority+1
> +              WHERE biblionumber = ?
> +              AND borrowernumber = ?
> +              AND reservedate = ?
> +              AND found IS NULL";
>     my $sth_update = $dbh->prepare( $query );
>
> -    $query = "SELECT * FROM reserves WHERE priority >= ?";
> +    # Select all reserves for the biblio with priority greater than
> $new_priority, and order greatest to least
> +    $query = "SELECT borrowernumber, reservedate FROM reserves WHERE
> priority >= ? AND biblionumber = ? ORDER BY priority DESC";
>     $sth = $dbh->prepare( $query );
> -    $sth->execute( $new_priority );
> +    $sth->execute( $new_priority, $biblio );
>     while ( my $row = $sth->fetchrow_hashref ) {
> -       $sth_update->execute( $updated_priority, $biblio,
> $row->{borrowernumber}, $row->{reservedate} );
> -       $updated_priority++;
> +       $sth_update->execute( $biblio, $row->{borrowernumber},
> $row->{reservedate} );
>     }
>
> -    return $new_priority;  # so the caller knows what priority they end up
> at
> +    return $new_priority;  # so the caller knows what priority they wind
> up receiving
>  }
>
>  =back
> --
> 1.5.6.5
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/koha-patches/attachments/20100330/49f044a2/attachment-0002.htm>


More information about the Koha-patches mailing list