Bug 39488

Summary: Update Koha::Object(s) to allow for polymorphic classing
Product: Koha Reporter: Martin Renvoize (ashimema) <martin.renvoize>
Component: Architecture, internals, and plumbingAssignee: Martin Renvoize (ashimema) <martin.renvoize>
Status: Signed Off --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: lucas, paul.derscheid
Version: unspecified   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on:    
Bug Blocks: 39190    
Attachments: Bug 39488: Add $result to Koha::Objects `object_class` calls
Bug 39488: Add template for required polymorphic class methods
Bug 39488: Use introspection in TestBuilder tests
Bug 39488: Unit tests

Description Martin Renvoize (ashimema) 2025-03-31 09:22:49 UTC
This splits out the proof of concept code in bug 39190 that allows for polymorphic Koha Object classing.

We update our Koha::Object(s) classes to pass back $result and propose a signature for class selection with resultsets.

This allows for subclassing of an object based on a field in a shared table so one can keep methods grouped for their tasks more easily.

Example use cases are (S)FTP where we want to store the basic transport details in one table and then dynamically load the right set of transport protocol specific methods based on the transport type.  We might also want to update the Account Line classes to work in a similar way, where we store both debits and credits in one table and would want some shared and some specific methods based on the account line type.
Comment 1 Martin Renvoize (ashimema) 2025-03-31 12:15:09 UTC
Created attachment 179985 [details] [review]
Bug 39488: Add $result to Koha::Objects `object_class` calls

This allows us to do dynamic polymorphic classing on calls to 'find',
'find_or_create', 'single', 'next', 'last' and 'as_list' etc.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 2 Martin Renvoize (ashimema) 2025-03-31 12:15:12 UTC
Created attachment 179986 [details] [review]
Bug 39488: Add template for required polymorphic class methods
Comment 3 Martin Renvoize (ashimema) 2025-03-31 12:15:14 UTC
Created attachment 179987 [details] [review]
Bug 39488: Use introspection in TestBuilder tests

We update the testbuilder tests here to look for signs of a polymorphic
class map and use it to test the different class options for this base
class

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 4 Martin Renvoize (ashimema) 2025-03-31 12:36:04 UTC
Hmm, I'm struggling to come up with explicit tests for these changes.  The main change here is that we consistently pass the original DBIx::Class row objects into the object_class meta method so that we can query the content to ascertain which polymorphpihc subclass to use for the subsequent _new_from_dbic calls.
Comment 5 Martin Renvoize (ashimema) 2025-04-01 13:35:57 UTC
Created attachment 180189 [details] [review]
Bug 39488: Unit tests
Comment 6 Martin Renvoize (ashimema) 2025-04-01 13:36:50 UTC
Transferring Kyles SO from the bug this was split out from.