Bug 12626

Summary: SQLHelper replacement - C4::Acquisition
Product: Koha Reporter: Yohann Dufour <yohann.dufour>
Component: Architecture, internals, and plumbingAssignee: Yohann Dufour <yohann.dufour>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: bgkriegel, dpavlin, jonathan.druart, tomascohen
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on:    
Bug Blocks: 11385, 12891    
Attachments: Bug 12626: SQLHelper replacement - C4::Acquisition
[SIGNED-OFF] Bug 12626: SQLHelper replacement - C4::Acquisition
Bug 12626: SQLHelper replacement - C4::Acquisition
[SIGNED-OFF] Bug 12626: SQLHelper replacement - C4::Acquisition
[PASSED QA] Bug 12626: SQLHelper replacement - C4::Acquisition

Description Yohann Dufour 2014-07-22 10:14:33 UTC
The module C4::Acquisition depends on module C4::SQLHelper. However, the module SQLHelper is obsolete, so the calls for InsertInTable have to be replaced by the use of the module DBIx::Class.
Comment 1 Yohann Dufour 2014-07-22 11:51:36 UTC Comment hidden (obsolete)
Comment 2 Kyle M Hall (khall) 2014-07-25 13:04:47 UTC Comment hidden (obsolete)
Comment 3 Jonathan Druart 2014-07-25 13:23:06 UTC
I got:

DBIx::Class::Row::new(): No such column 'origquantityrec' on Koha::Schema::Result::Aqorder at /home/koha/src/C4/Acquisition.pm line 1278

On creating an order via the acquisition module.
Comment 4 Yohann Dufour 2014-07-28 09:20:58 UTC Comment hidden (obsolete)
Comment 5 Bernardo Gonzalez Kriegel 2014-08-07 21:45:25 UTC Comment hidden (obsolete)
Comment 6 Katrin Fischer 2014-08-17 09:44:18 UTC
Created attachment 30893 [details] [review]
[PASSED QA] Bug 12626: SQLHelper replacement - C4::Acquisition

With this patch, the subroutine NewOrder uses DBIx::Class instead of C4::SQLHelper.

Test plan:
1) Apply the patch

2) Execute the unit tests by launching :
prove t/db_dependent/Acquisition.t

3) The result has to be a success without error or warning :
t/db_dependent/Acquisition.t .. ok
All tests successful.
Files=1, Tests=79,  2 wallclock secs ( 0.04 usr  0.01 sys +  1.80 cusr  0.09 csys =  1.94 CPU)
Result: PASS

4) Log in the koha intranet and create a new order in the acquition module

5) The creation has to be a success

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>

Test pass, new order created without problem, no koha-qa errors

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Tested creating a new order from a subscription, no problems found.
Passes tests and QA script.
Comment 7 Tomás Cohen Arazi (tcohen) 2014-08-26 18:51:38 UTC
Patch pushed to master.

Thanks Yohann!
Comment 8 Dobrica Pavlinusic 2014-09-08 15:07:22 UTC
This bug introduced regression for acquisition in acqui/neworderempty.pl.

In logs, I see error messages like:

addorder.pl: DBD::mysql::st execute failed: Cannot add or update a child row: a foreign key constraint fails (`koha`.`aqorders_items`, CONSTRAINT `aqorders_items_ibfk_1` FOREIGN KEY (`ordernumber`) REFERENCES `aqorders` (`ordernumber`) ON DELETE CASCADE ON UPDATE CASCADE) at /srv/koha_ffzg//C4/Acquisition.pm line 1317., referer: https://koha.ffzg.hr:8443/cgi-bin/koha/acqui/neworderempty.pl?booksellerid=54&basketno=3764&biblionumber=237202

And indeed, adding additional debug warns all over the place, it seems that code inside C4/Acquisition.pm sub NewOrder does:

my $ordernumber = $rs->create($new_order)->id;

which doesn't return ordernumber but instead empty string "" and all hell breaks loose (resulting in missing entries in aqorders_items.

My DBIC foo isn't that good, but cookbook suggest that above code is correct:

http://search.cpan.org/~danieltwc/DBIx-Class-0.07002/lib/DBIx/Class/Manual/Cookbook.pod#Getting_the_value_of_the_primary_key_for_the_last_database_insert

I'm puzzled and confused how to fix this.
Comment 9 Jonathan Druart 2014-09-08 15:27:28 UTC
It's quite weird, the unit tests pass!
I got the same error when I create a new order with items.
Comment 10 Jonathan Druart 2014-09-08 18:25:13 UTC
(In reply to Dobrica Pavlinusic from comment #8)

This bug 12891 for a fix.