@@ -, +, @@ and common sense. branchtransfer_id in return columns. branchtransfer_id. --- C4/Circulation.pm | 5 ++-- Koha/Schema/Result/Branchtransfer.pm | 45 +++++++++++++++------------- installer/data/mysql/atomicupdate/14187.perl | 8 +++++ installer/data/mysql/kohastructure.sql | 2 ++ t/db_dependent/Circulation/transfers.t | 16 +++++----- 5 files changed, 47 insertions(+), 29 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/14187.perl --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -3309,7 +3309,8 @@ sub GetTransfers { my $query = ' SELECT datesent, frombranch, - tobranch + tobranch, + branchtransfer_id FROM branchtransfers WHERE itemnumber = ? AND datearrived IS NULL @@ -3333,7 +3334,7 @@ sub GetTransfersFromTo { return unless ( $frombranch && $tobranch ); my $dbh = C4::Context->dbh; my $query = " - SELECT itemnumber,datesent,frombranch + SELECT branchtransfer_id,itemnumber,datesent,frombranch FROM branchtransfers WHERE frombranch=? AND tobranch=? --- a/Koha/Schema/Result/Branchtransfer.pm +++ a/Koha/Schema/Result/Branchtransfer.pm @@ -1,21 +1,17 @@ -use utf8; package Koha::Schema::Result::Branchtransfer; # Created by DBIx::Class::Schema::Loader # DO NOT MODIFY THE FIRST PART OF THIS FILE -=head1 NAME - -Koha::Schema::Result::Branchtransfer - -=cut - use strict; use warnings; use base 'DBIx::Class::Core'; -=head1 TABLE: C + +=head1 NAME + +Koha::Schema::Result::Branchtransfer =cut @@ -23,6 +19,12 @@ __PACKAGE__->table("branchtransfers"); =head1 ACCESSORS +=head2 branchtransfer_id + + data_type: 'integer' + is_auto_increment: 1 + is_nullable: 0 + =head2 itemnumber data_type: 'integer' @@ -66,6 +68,8 @@ __PACKAGE__->table("branchtransfers"); =cut __PACKAGE__->add_columns( + "branchtransfer_id", + { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, "itemnumber", { data_type => "integer", @@ -104,6 +108,7 @@ __PACKAGE__->add_columns( "comments", { data_type => "mediumtext", is_nullable => 1 }, ); +__PACKAGE__->set_primary_key("branchtransfer_id"); =head1 RELATIONS @@ -122,39 +127,39 @@ __PACKAGE__->belongs_to( { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); -=head2 itemnumber +=head2 tobranch Type: belongs_to -Related object: L +Related object: L =cut __PACKAGE__->belongs_to( - "itemnumber", - "Koha::Schema::Result::Item", - { itemnumber => "itemnumber" }, + "tobranch", + "Koha::Schema::Result::Branch", + { branchcode => "tobranch" }, { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); -=head2 tobranch +=head2 itemnumber Type: belongs_to -Related object: L +Related object: L =cut __PACKAGE__->belongs_to( - "tobranch", - "Koha::Schema::Result::Branch", - { branchcode => "tobranch" }, + "itemnumber", + "Koha::Schema::Result::Item", + { itemnumber => "itemnumber" }, { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); -# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:NPbH+5o2BVPj8yeoUqEavw +# Created by DBIx::Class::Schema::Loader v0.07010 @ 2015-05-27 18:14:12 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:IKdPAJHJdYM3MHxnj6Mxzg # You can replace this text with custom content, and it will be preserved on regeneration --- a/installer/data/mysql/atomicupdate/14187.perl +++ a/installer/data/mysql/atomicupdate/14187.perl @@ -0,0 +1,8 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + $dbh->do("ALTER TABLE branchtransfers ADD COLUMN branchtransfer_id int(12) NOT NULL auto_increment FIRST, ADD CONSTRAINT PRIMARY KEY (branchtransfer_id);"); + + # Always end with this (adjust the bug info) + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 14187 - branchtransfer needs a primary key (id) for DBIx and common sense.)\n"; +} --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -1003,12 +1003,14 @@ CREATE TABLE `default_branch_item_rules` ( DROP TABLE IF EXISTS `branchtransfers`; CREATE TABLE `branchtransfers` ( -- information for items that are in transit between branches + `branchtransfer_id` int(12) NOT NULL auto_increment, -- primary key `itemnumber` int(11) NOT NULL default 0, -- the itemnumber that it is in transit (items.itemnumber) `datesent` datetime default NULL, -- the date the transfer was initialized `frombranch` varchar(10) NOT NULL default '', -- the branch the transfer is coming from `datearrived` datetime default NULL, -- the date the transfer arrived at its destination `tobranch` varchar(10) NOT NULL default '', -- the branch the transfer was going to `comments` mediumtext, -- any comments related to the transfer + PRIMARY KEY (`branchtransfer_id`), KEY `frombranch` (`frombranch`), KEY `tobranch` (`tobranch`), KEY `itemnumber` (`itemnumber`), --- a/t/db_dependent/Circulation/transfers.t +++ a/t/db_dependent/Circulation/transfers.t @@ -125,7 +125,7 @@ is(CreateBranchTransferLimit(undef,$branchcode_2),undef, my @transfers = GetTransfers($item_id1); cmp_deeply( \@transfers, - [ re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), $branchcode_1, $branchcode_2 ], + [ re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), $branchcode_1, $branchcode_2, re('[0-9]*') ], "Transfers of the item1" ); #NOTE: Only the first transfer is returned @transfers = GetTransfers; @@ -142,14 +142,16 @@ cmp_deeply( \@transferfrom1to2, [ { - itemnumber => $item_id1, - datesent => re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), - frombranch => $branchcode_1 + branchtransfer_id => re('[0-9]*'), + itemnumber => $item_id1, + datesent => re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), + frombranch => $branchcode_1 }, { - itemnumber => $item_id2, - datesent => re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), - frombranch => $branchcode_1 + branchtransfer_id => re('[0-9]*'), + itemnumber => $item_id2, + datesent => re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), + frombranch => $branchcode_1 } ], "Item1 and Item2 has been transferred from branch1 to branch2" --