@@ -, +, @@ - 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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/C4/Koha.pm +++ a/C4/Koha.pm @@ -29,6 +29,7 @@ use Koha::DateUtils qw(dt_from_string); use Memoize; use DateTime::Format::MySQL; use autouse 'Data::Dumper' => qw(Dumper); +use DBI qw(:sql_types); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG); @@ -1443,11 +1444,14 @@ 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 OFFSET ?'; $sth = C4::Context->dbh->prepare($query); - $sth->execute($id); + # see http://www.perlmonks.org/?node_id=837422 for why + # we're being verbose and using bind_param + $sth->bind_param(1, $offset, SQL_INTEGER); + $sth->execute(); } else { $query = 'SELECT * FROM quotes;'; --