[Bug 14539] New: castToObject(), aka. make a Koha::Object from various input types
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Bug ID: 14539 Summary: castToObject(), aka. make a Koha::Object from various input types Change sponsored?: --- Product: Koha Version: master Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Architecture, internals, and plumbing Assignee: gmcharlt@gmail.com Reporter: olli-antti.kivilahti@jns.fi QA Contact: testopia@bugs.koha-community.org Currently Koha is like an archeological dig site, we have different layers of dealing with various business objects. We started with DBI and numerous ways of passing an HASH around. There is no telling if it will be a List of column => values, or a reference to HASH, or a HASH or just any of the business object's (eg. Borrower's) unique identifiers (userid, cardnumber, borrowernumber). Then DBIx came to the rescue and now we are need to learn DBI and DBIx and SQL to do DB operatons in Koha. Migration to DBIx is on the way. Finally we have Koha::Object and subclasses, which include and use the DBIx, but those are not directly compatible, since Koha::Object is not a subclass of DBIx::Class making life occasionally miserable. Now we need to know 3 methods of DB accession. I am really frustrated with all of those different layers of history, and making things work nicely across all different programming patterns, I have had great success in using a casting system, where we take any value and try to make a Koha::Object-subclass out of it. So we try to cast a Scalar or a reference of Koha::Object-implementation or DBIx::ResultSet or HASH, to the desired Koha::Object-implementation. This is a nice validation/entry function in any subroutine dealing with business objects, making sure that we always have the "correct" implementation of the same business object. An example: #Does this look familiar? my $borrower = 1042; #A borrowernumber? my $user = '121A0321312'; #A cardnumber? or userid? my $borrower = {borrowernumber => 1043, cardnumber => '121A0321312', ...}; #HASH my $borrower = Koha::Borrowers->find({borrowernumber => 1024}); my $borrower = $schema->resultset('Borrower')->find({borrowernumber => 1024}); #So when I call my subroutine with the $borrower I got using some function, makeBorrowerHappy($borrower); #Bad things most often happen. #But if my makeBorrowerHappy()-function would cast its parameters to the #correct type, there would be only merriment and fun! sub makeBorrowerHappy { my ($borrower) = @_; $borrower = Koha::Borrowers::castToBorrower($borrower); ... #Do fun stuff! } #Whatever we throw at the subroutine, things just work (in theory)! Even better, if the $borrower already is a DBIx-derivative or Koha::Borrower, we don't even do anything, other than simple if statements. So minimally expensive, maximally productive. -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|gmcharlt@gmail.com |olli-antti.kivilahti@jns.fi -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|castToObject(), aka. make a |Introduction to |Koha::Object from various |castToObject(), aka. make a |input types |Koha::Object from various | |input types -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 --- Comment #1 from Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> --- Created attachment 41025 --> http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=41025&action=edit Bug 14539 - Introduction to castToObject(), aka. make a Koha::Object from various input types -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |13995 Referenced Bugs: http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=13995 [Bug 13995] Proper Exception handling -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |14540 Referenced Bugs: http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14540 [Bug 14540] Move member-flags.pl to PermissionsManager to better manage permissions for testing. -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #41025|0 |1 is obsolete| | --- Comment #2 from Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> --- Created attachment 41063 --> http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=41063&action=edit Bug 14539 - Introduction to castToObject(), aka. make a Koha::Object from various input types -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #41063|0 |1 is obsolete| | --- Comment #3 from Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> --- Created attachment 41122 --> http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=41122&action=edit Bug 14539 - Introduction to castToObject(), aka. make a Koha::Object from various input types -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #41122|0 |1 is obsolete| | --- Comment #4 from Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> --- Created attachment 41157 --> http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=41157&action=edit Bug 14539 - Introduction to castToObject(), aka. make a Koha::Object from various input types -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #41157|0 |1 is obsolete| | --- Comment #5 from Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> --- Created attachment 41250 --> http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=41250&action=edit Bug 14539 - Introduction to cast() (ToObject), aka. make a Koha::Object from various input types and validate. -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |13906 Referenced Bugs: http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=13906 [Bug 13906] TestObjectFactory(ies) for Koha objects. Enable easy Test object creation from HASHes or from preconfigured test groups. -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #41250|0 |1 is obsolete| | --- Comment #6 from Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> --- Created attachment 41530 --> http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=41530&action=edit Bug 14539 - Introduction to cast() (ToObject), aka. make a Koha::Object from various input types and validate. -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Julian Maurice <julian.maurice@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |13920 Referenced Bugs: http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=13920 [Bug 13920] API authentication system - proposal -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Zeno Tajoli <z.tajoli@cineca.it> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |z.tajoli@cineca.it Patch complexity|--- |Large patch --- Comment #7 from Zeno Tajoli <z.tajoli@cineca.it> --- Patch complexity is 'Large' because this change has many architectural connections -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Zeno Tajoli <z.tajoli@cineca.it> changed: What |Removed |Added ---------------------------------------------------------------------------- CC|z.tajoli@cineca.it | -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |14698 Referenced Bugs: http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14698 [Bug 14698] AtomicUpdater - Keeps track of which updates have been applied to a database -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org