Bug 36526: Remove circular dependency from Koha::Objects
authorJulian Maurice <julian.maurice@biblibre.com>
Thu, 4 Apr 2024 14:26:00 +0000 (16:26 +0200)
committerFridolin Somers <fridolin.somers@biblibre.com>
Fri, 24 May 2024 12:59:19 +0000 (14:59 +0200)
commitaace5d09905ec394846c51c846d3d68290ae76d0
tree85e9a6bf367937f0c57c926585324f8d7b28b53e
parentbdb4f0c1bbc4b76910f64a687a40dfef00584b99
Bug 36526: Remove circular dependency from Koha::Objects

Koha::Objects depends on Koha::DateUtils, which depends on C4::Context,
which depends on Koha::Config::SysPrefs, which depends on Koha::Objects

Apart from the circular dependency, the dependency on C4::Context alone
is problematic as it loads a bunch of modules that are not needed at all
in Koha::Objects (YAML::XS and ZOOM for instance).
As Koha::Objects is used as a base for a lot of modules, we should take
care to only load the minimum required.

This patch removes uses of Koha::DateUtils from Koha::Objects.
It was only used in Koha::Objects::filter_by_last_update

filter_by_last_update now requires that the 'from' and 'to' parameters
must be DateTime objects. Previously it would also allow date and
datetime strings. This possibility was only used in two places:
* misc/cronjobs/cleanup_database.pl
* tools/cleanborrowers.pl

Now they call dt_from_string first and pass a DateTime object to
filter_by_last_update

Test plan:
1. Run `perl -cw Koha/Objects.pm`. It should only say:
   "Koha/Objects.pm syntax OK" without warnings
2. Run `prove t/db_dependent/Koha/Objects.t`
3. Verify that misc/cronjobs/cleanup_database.pl works as before,
   especially with the options --pseudo-transactions,
   --pseudo-transactions-from and --pseudo-transactions-to
4. Go to Tools » Batch patron deletion and anonymization, check "Verify
   you want to anonymize patron checkout history" and enter a date in
   the text input below. Then click Next and verify that the correct
   count of borrowers is shown. Click on the "Finish" button and verify
   that the circulation history has been correctly anonymized

See also bug 36432

Signed-off-by: Tadeusz Sośnierz <tadeusz@sosnierz.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit 675c8263b707c8e1987ac6084272b355deb1b05c)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Koha/Objects.pm
misc/cronjobs/cleanup_database.pl
t/db_dependent/Koha/Objects.t
tools/cleanborrowers.pl