Bug 10621: use correct from-address for subscription alert emails

From-address and to-address were the same (patron's email) for
subscription alerts. This patch changes 'from' the branch or
kohaadminemailaddress

To test
- add a subscription in staff/serials in case you don't have any
- enable patron notifications or the subscription
- in the OPAC, subscribe to the serial
- in staff/serial, receive an issue of the serial

Before applying the patch, the email that is supposed to be sent
has the patron's email as 'from' and 'to' (and is likely to fail).

If you follow the steps after applying the patch, the email alert
should have the 'from' address of the patron's branch or
kohaadminemiladdress -- which should also work fine with the MTA/SMTP
you have set up for messaging.

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 61fa246ac06d637d50c8eed68244f0577ed34e4d)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10463: ensure that Quote of the Day feature selects random quotes

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 (unless your server's timezone is set to UTC).

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@catalyst.net.nz>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit def952bda9cd72a4f6916e93ad1c454a04a3cb43)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10644: add unit tests for ClassSource.pm

The tests are wrapped in a database transaction.

To test:
prove t/db_dependent/ClassSource.t
t/db_dependent/ClassSource.t .. 1/24 prepare_cached(SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?) statement handle DBI::st=HASH(0x92dbedc) still Active at C4/ClassSource.pm line 249
prepare_cached(SELECT * FROM `class_sources` WHERE cn_source = ?) statement handle DBI::st=HASH(0x926876c) still Active at C4/ClassSource.pm line 137
attempting to use non-existent class sorting routine routine1
prepare_cached(SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?) statement handle DBI::st=HASH(0x92dbedc) still Active at C4/ClassSource.pm line 249
prepare_cached(SELECT * FROM `class_sources` WHERE cn_source = ?) statement handle DBI::st=HASH(0x926876c) still Active at C4/ClassSource.pm line 137
t/db_dependent/ClassSource.t .. ok
All tests successful.
Files=1, Tests=24,  0 wallclock secs ( 0.02 usr  0.00 sys +  0.12 cusr  0.01 csys =  0.15 CPU)
Result: PASS

Signed-off-by: Srdjan <srdjan@catalyst.net.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 5de06b87e29f12250a35df3239372a7ed0754811)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10644: fix typos in test descriptions

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit d9d8a8424dcd62988293920f7c67f7d0a01efc70)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10666: avoid random failures of Daily quotes tests

In t/db_dependent/Koha.t, the test "Got a quote based on today's
date" is failing :

$prove t/db_dependent/Koha.t :
t/db_dependent/Koha.t .. 1/6
    #   Failed test 'Got a quote based on today's date.'
    #   at t/db_dependent/Koha.t line 126.
    # Compared $data->{"source"}
    #    got : 'Herbert Hoover'
    # expect : 'Abraham Lincoln'
    # Be sure to run this test on a clean install of sample data.
    # Looks like you failed 1 test of 4.

Looks like the wrong quote is returned by GetDailyQuote().
I'm using a databased created with the English sample SQL datas.

I think I found the cause :
The test "Got a random quote." calls GetDailyQuote('random'=>1) which
changes the quote timestamp to now. When then testing GetDailyQuote(),
this quote (which may not be the one created by test) is the most
recent quote.

This patch moves the "Got a random quote." test after "Got a quote
based on today's date" to solve the problem.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit b874f7d63894693c9c3f2a3d93ee119bc3b01486)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10643: fix inappropriate uses of $sth->finish() in C4::ClassSource.pm

This patch gets rid of finish() and replace prepare_cached by prepare.

From the man page

finish()
Indicate that no more data will be fetched from this statement handle
before it is either executed again or destroyed.
You almost certainly do not need to call this method.

Adding calls to "finish" after loop that fetches all rows is a common
mistake, don't do it, it can mask genuine problems like uncaught fetch errors.

Signed-off-by: Srdjan <srdjan@catalyst.net.nz>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 5cba6457aa00f3f3b2038f70057df300d9c6b9c3)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10644: (follow-up) remove inadvertant dependence on Perl 5.14

Perl 5.14 changed array and hash container functions (e.g., keys())
to accept hashrefs or arrayrefs.  However, this doesn't work in
Perl 5.10, so doing

  scalar(keys( function_returning_hashref() ) );

is a syntax error in that version.  This patch changes the affected
tests to explicitly difference the hashrefs returned by the various
functions.

To test:

Verify that t/db_dependent/ClassSource.t passes.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 8f933bc040e8e4198f5278253191a7a4233467ce)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10712: Save missing config variables to install log

The variables for AUTH_INDEX_MODE and ZEBRA_TOKENIZER were not
being saved to the koha_install_log file.  As a result when using the
--prev-install-log option in Makefile.PL the user was still prompted
to select them.

This patch adds the appropriate variables to the list saved in
the install log.

To test:

On a (non-package) system installed/upgraded without the patch running
'perl Makefile.PL --prev-install-log /path/to/koha-install-log' will
still prompt you to choose authorities indexing mode and select
between chr and icu, after upgrading with this patch applied the same
command should get the responses from the install log and not require
user intervention.

The values can be seen written into misc/koha-install-log

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 40e6f6a8f22b8af7adef79a0ece80a61a69ccc50)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10663: tests for CanBookBeRenewed

Initial work on unit tests for CanBookBeRenewed. More scenarios are needed.
Also made Circulation.t use autocommit=0.

Sponsored-by: Universidad Nacional de Córdoba
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit dc469424c8bcf952cb64f5c9dc2cdc53772d8ca5)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10663: Follow-up - Unit tests for CanBookBeRenewed

Follow-up fixing some and adding more unit tests.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit b15b3be5ae878d19d4b6ed659b68ce0b9843a35e)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10663: (follow-up) set circ policy for circulation tests

This patch ensures that the loan rules are set to a known
value suitable for testing.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 51b8deb4d5eceee84ad95b28cac902330b4b12fe)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10663: restore ability of active hold requests to block renewal

Sponsored-by: Universidad Nacional de Cordoba
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
This reverts changes made to CanBookBeRenewed by
patches from bug 9367.
GetReserveStatus is not suitable to recognize if an item
can fild a hold on return and CheckReserves is restored.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>

This patch includes a squash of a follow-up authored by
Katrin Fischer <Katrin.Fischer.83@web.de>:

  CheckReserves returns '' when no reserve is found,
  so $resfound will always be defined and we need to
  check if it's true.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 3e387f72a337b36d96e1b0df56965391ffc95213)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10666: (follow-up) really fix the daily quotes test

Koha::DateUtils::dt_from_string() and DateTime->now() are
not equivalent -- they don't handle timezones in the same
way.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit c6f903198cf427b9e4c9f8ad89fef97518998a09)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10663: QA Followup: Typo in comment in renewscript

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 240520c2f925a4e9235628f06a0bdd15c99dfa80)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Bug 10362: ensure that all messages and alerts are shown upon checkin

If an item is returned and has mutiple error or warnings (e.g.,
it both needs to be transferred and the patron was debarred
in the course of the return), because of a bug in the template,
not all of the messages would be displayed.

This patch changes the template to show both messages and alerts.

Test plan :
- Perform an checkout that will a checkin :
  * need a transfert (return in a different branch)
  * set user debarred (depends on issuing rules)
- Perform check-in
=> You get tranfert message and debarment alert

Signed-off-by: Srdjan <srdjan@catalyst.net.nz>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 5192fd81adaccf9b0f4a01dcc0ffc689edc9468f)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>