Factor out a 'with_duplicate_xapian_job_creation' helper

In a subsequent commit, we will want to wrap an additional section
of code with the addition and removal of a hook that creates a
duplicate xapian job, so it's useful for this to be factored out.

This commit introduces a 'with_duplicate_xapian_job_creation'
method that can be passed a block which will be run with the forced
duplicate xapian job creation.
Fix for an aborted transaction not being rolled-back

We were seeing errors in xapian_create_job that indicated that the
current transaction had been aborted but not rolled-back.  It seems
that this happened because sometimes xapian_create_job was called
from within another transaction (e.g. from the transaction block in
AdminIncomingMessageController#redeliver).  The default behaviour
of nested transactions in Rails is for them to behave as if all
but the outermost transaction blocks had no effect; this means
that the exception thrown in the inner transaction block in
xapian_create_job wasn't causing a rollback, and it was then being
caught before propagating up to the outermost transaction. Thus
the transaction was never being rolled-back so any subsequent
operation on this database connection would error.

This commit fixes this problem by using the :requires_new => true
option to transaction, which asks ActiveRecord to fake genuinely
nested transcations using SAVEPOINT.

Fixes #1124.
Merge remote-tracking branch 'origin/fix-aborted-transaction' into rails-3-develop