From 5ba080c439a2afcf06efb79cd18375cc66be4d00 Mon Sep 17 00:00:00 2001 From: Katrin Fischer Date: Thu, 12 Dec 2013 00:54:08 +0100 Subject: [PATCH] Bug 11279: Improve how a new quote of the day is selected When a lot of quotes were deleted, it's possible that no new quote will be selected. This will happen when a lot of the older quotes with low ids have been deleted. This patch improves the selection of a new quote. To test: - Load sample quotes - Delete the first half of the quotes. Note: With 34 quotes, delete the quotes with ids from 1-17 - Activate the QuoteOfTheDay system preference - Check if a quote is displayed in OPAC - Reload the page a few times, no quote should be displayed Note: make sure you don't have a quote with the current date in your quotes table before running those tests - Run 'perl t/db_dependent/Koha.t' Note: requires sample quotes! - Apply patch - Reload the OPAC start page - Verify a quote was now picked - Run 'perl t/db/dependent/Koha.t' again - all tests should still pass --- C4/Koha.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index 937ac5f..7faf7ca 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -1443,11 +1443,11 @@ sub GetDailyQuote { my $range = ($sth->fetchrow_array)[0]; if ($range > 1) { # chose a random id within that range if there is more than one quote - my $id = int(rand($range)); + my $offset = int(rand($range)); # grab it - $query = 'SELECT * FROM quotes WHERE id = ?;'; + $query = 'SELECT * FROM quotes ORDER BY id LIMIT ?, 1;'; $sth = C4::Context->dbh->prepare($query); - $sth->execute($id); + $sth->execute($offset); } else { $query = 'SELECT * FROM quotes;'; -- 1.8.3.2