[Koha-patches] [PATCH] Bug 10463 - Quote of the day feature not selecting random quotes

Srdjan srdjan at catalyst.net.nz
Wed Jul 17 06:12:20 CEST 2013


From: Kyle M Hall <kyle at bywatersolutions.com>

When the Quote of the Day tool selects a new new quote, it updates the
timestamp and does not take the timezone into account.  Thus the time is
set to +4 hours (e.g. 2013-06-11 13:33:48 when the time is 2013-06-11
        09:33:48).  It then repeats the same quote every day.

To replicate:

set Administration >> System preferences >> OPAC preferences >> Features
>> QuoteOfTheDay to Enable

In Home >> Tools >> Quote Editor, add several quotes.

In the opac, refresh the home page. You should get a quote of the day at
the top.

mysql> select * from quotes;

note the timestamp of the quote selected by the tool. It will not match
the date on the machine.

If you change the date to the previous date and refresh the opac, the
tool wlill select another quote, which will not change unless forced.

Test Plan:
1) Remove all your quotes and import a fresh set
2) Enable the quote of the day and view the opac
3) Look at your quotes table and note the timestamp is incorrect
4) Repeat steps 1 and 2
5) Look at your quotes table and note the timestamp is now correct

Signed-off-by: Srdjan <srdjan at catalyst.net.nz>
---
 C4/Koha.pm | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/C4/Koha.pm b/C4/Koha.pm
index 9976995..e40efc9 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -25,8 +25,8 @@ use strict;
 
 use C4::Context;
 use C4::Branch qw(GetBranchesCount);
+use Koha::DateUtils qw(dt_from_string);
 use Memoize;
-use DateTime;
 use DateTime::Format::MySQL;
 use autouse 'Data::Dumper' => qw(Dumper);
 
@@ -1478,7 +1478,10 @@ sub GetDailyQuote {
         # update the timestamp for that quote
         $query = 'UPDATE quotes SET timestamp = ? WHERE id = ?';
         $sth = C4::Context->dbh->prepare($query);
-        $sth->execute(DateTime::Format::MySQL->format_datetime(DateTime->now), $quote->{'id'});
+        $sth->execute(
+            DateTime::Format::MySQL->format_datetime( dt_from_string() ),
+            $quote->{'id'} 
+        );
     }
     return $quote;
 }
-- 
1.8.1.2


More information about the Koha-patches mailing list