Bug 36432: Remove circular dependency from Koha::Object
authorJulian Maurice <julian.maurice@biblibre.com>
Tue, 26 Mar 2024 15:19:41 +0000 (16:19 +0100)
committerKatrin Fischer <katrin.fischer@bsz-bw.de>
Thu, 4 Apr 2024 13:24:32 +0000 (15:24 +0200)
commit8d5299639e3f983e95fcf2a9d81febc1406bafdd
treeaa307877550954a85813de2c5be64aea013a4f95
parent7aabe354ecf406761d3422130cdea2e9da2f4687
Bug 36432: Remove circular dependency from Koha::Object

Koha::Object depends on Koha::DateUtils, which depends on C4::Context,
which depends on Koha::Config::SysPref, which depends on... Koha::Object

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::Object (YAML::XS and ZOOM for instance).
As Koha::Object is used as a base for a lot of modules, we should take
care to only load the minimum required.

This patch moves some date parsing code to specific modules:
- Koha::DateTime::Format::RFC3339
- Koha::DateTime::Format::SQL

and it uses them in Koha::Object and Koha::DateUtils where it is
possible.

Test plan:
1. Do not apply the patch yet and run the following command:
   `perl -cw Koha/Object.pm`
   It should print several warnings about redefined subroutines, meaning
   there is a circular dependency.
2. Apply the patch
3. Run `perl -cw Koha/Object.pm`. It should only say:
   "Koha/Object.pm syntax OK"
4. Run the following command:
    prove \
        t/DateUtils.t \
        t/Koha/DateTime/Format/RFC3339.t \
        t/db_dependent/Koha/Object.t

Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Koha/DateTime/Format/RFC3339.pm [new file with mode: 0644]
Koha/DateTime/Format/SQL.pm [new file with mode: 0644]
Koha/DateUtils.pm
Koha/Object.pm
t/DateUtils.t
t/Koha/DateTime/Format/RFC3339.t [new file with mode: 0755]
t/db_dependent/Koha/Object.t