Lines 1787-1818
sub _ShiftPriorityByDateAndPriority {
Link Here
|
1787 |
my ( $biblio, $resdate, $new_priority ) = @_; |
1787 |
my ( $biblio, $resdate, $new_priority ) = @_; |
1788 |
|
1788 |
|
1789 |
my $dbh = C4::Context->dbh; |
1789 |
my $dbh = C4::Context->dbh; |
1790 |
my $query = "SELECT priority FROM reserves WHERE biblionumber = ? AND ( reservedate > ? OR priority > ? ) ORDER BY priority ASC"; |
1790 |
my $query = "SELECT priority FROM reserves WHERE biblionumber = ? AND ( reservedate > ? OR priority > ? ) ORDER BY priority ASC LIMIT 1"; |
1791 |
my $sth = $dbh->prepare( $query ); |
1791 |
my $sth = $dbh->prepare( $query ); |
1792 |
$sth->execute( $biblio, $resdate, $new_priority ); |
1792 |
$sth->execute( $biblio, $resdate, $new_priority ); |
1793 |
my ( $min_priority ) = $sth->fetchrow; |
1793 |
my $min_priority = $sth->fetchrow; |
1794 |
$sth->finish; # $sth might have more data. |
1794 |
# if no such matches are found, $new_priority remains as original value |
1795 |
$new_priority = $min_priority if ( $min_priority ); |
1795 |
$new_priority = $min_priority if ( $min_priority ); |
1796 |
my $updated_priority = $new_priority + 1; |
|
|
1797 |
|
1796 |
|
1798 |
$query = " |
1797 |
# Shift the priority up by one; works in conjunction with the next SQL statement |
1799 |
UPDATE reserves |
1798 |
$query = "UPDATE reserves |
1800 |
SET priority = ? |
1799 |
SET priority = priority+1 |
1801 |
WHERE biblionumber = ? |
1800 |
WHERE biblionumber = ? |
1802 |
AND borrowernumber = ? |
1801 |
AND borrowernumber = ? |
1803 |
AND reservedate = ? |
1802 |
AND reservedate = ? |
1804 |
AND found IS NULL"; |
1803 |
AND found IS NULL"; |
1805 |
my $sth_update = $dbh->prepare( $query ); |
1804 |
my $sth_update = $dbh->prepare( $query ); |
1806 |
|
1805 |
|
1807 |
$query = "SELECT * FROM reserves WHERE priority >= ?"; |
1806 |
# Select all reserves for the biblio with priority greater than $new_priority, and order greatest to least |
|
|
1807 |
$query = "SELECT borrowernumber, reservedate FROM reserves WHERE priority >= ? AND biblionumber = ? ORDER BY priority DESC"; |
1808 |
$sth = $dbh->prepare( $query ); |
1808 |
$sth = $dbh->prepare( $query ); |
1809 |
$sth->execute( $new_priority ); |
1809 |
$sth->execute( $new_priority, $biblio ); |
1810 |
while ( my $row = $sth->fetchrow_hashref ) { |
1810 |
while ( my $row = $sth->fetchrow_hashref ) { |
1811 |
$sth_update->execute( $updated_priority, $biblio, $row->{borrowernumber}, $row->{reservedate} ); |
1811 |
$sth_update->execute( $biblio, $row->{borrowernumber}, $row->{reservedate} ); |
1812 |
$updated_priority++; |
|
|
1813 |
} |
1812 |
} |
1814 |
|
1813 |
|
1815 |
return $new_priority; # so the caller knows what priority they end up at |
1814 |
return $new_priority; # so the caller knows what priority they wind up receiving |
1816 |
} |
1815 |
} |
1817 |
|
1816 |
|
1818 |
=back |
1817 |
=back |
1819 |
- |
|
|