From 617b2a36080e1fc3e15a61b52e9e85406e5b0605 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Thu, 23 Sep 2021 08:33:26 +0100
Subject: [PATCH] Bug 28854: DBIC Schema Updates

---
 Koha/Schema/Result/Item.pm           |  49 +++++++++-
 Koha/Schema/Result/ItemBundle.pm     | 113 ++++++++++++++++++++++
 Koha/Schema/Result/ItemsLostIssue.pm | 138 +++++++++++++++++++++++++++
 Koha/Schema/Result/OldIssue.pm       |  19 +++-
 4 files changed, 315 insertions(+), 4 deletions(-)
 create mode 100644 Koha/Schema/Result/ItemBundle.pm
 create mode 100644 Koha/Schema/Result/ItemsLostIssue.pm

diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm
index a53e10e98a..316203cea0 100644
--- a/Koha/Schema/Result/Item.pm
+++ b/Koha/Schema/Result/Item.pm
@@ -729,6 +729,36 @@ __PACKAGE__->might_have(
   { cascade_copy => 0, cascade_delete => 0 },
 );
 
+=head2 item_bundles_hosts
+
+Type: has_many
+
+Related object: L<Koha::Schema::Result::ItemBundle>
+
+=cut
+
+__PACKAGE__->has_many(
+  "item_bundles_hosts",
+  "Koha::Schema::Result::ItemBundle",
+  { "foreign.host" => "self.itemnumber" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 item_bundles_item
+
+Type: might_have
+
+Related object: L<Koha::Schema::Result::ItemBundle>
+
+=cut
+
+__PACKAGE__->might_have(
+  "item_bundles_item",
+  "Koha::Schema::Result::ItemBundle",
+  { "foreign.item" => "self.itemnumber" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
 =head2 items_last_borrower
 
 Type: might_have
@@ -744,6 +774,21 @@ __PACKAGE__->might_have(
   { cascade_copy => 0, cascade_delete => 0 },
 );
 
+=head2 items_lost_issue
+
+Type: might_have
+
+Related object: L<Koha::Schema::Result::ItemsLostIssue>
+
+=cut
+
+__PACKAGE__->might_have(
+  "items_lost_issue",
+  "Koha::Schema::Result::ItemsLostIssue",
+  { "foreign.itemnumber" => "self.itemnumber" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
 =head2 linktrackers
 
 Type: has_many
@@ -865,8 +910,8 @@ __PACKAGE__->has_many(
 );
 
 
-# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-27 08:42:21
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SjZn3haOtUZWu1jrMigjNQ
+# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-23 07:00:41
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/LUKEnOVCeXHPYDqV7HGRg
 
 __PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" );
 
diff --git a/Koha/Schema/Result/ItemBundle.pm b/Koha/Schema/Result/ItemBundle.pm
new file mode 100644
index 0000000000..590061c922
--- /dev/null
+++ b/Koha/Schema/Result/ItemBundle.pm
@@ -0,0 +1,113 @@
+use utf8;
+package Koha::Schema::Result::ItemBundle;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Koha::Schema::Result::ItemBundle
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<item_bundles>
+
+=cut
+
+__PACKAGE__->table("item_bundles");
+
+=head1 ACCESSORS
+
+=head2 item
+
+  data_type: 'integer'
+  is_foreign_key: 1
+  is_nullable: 0
+
+=head2 host
+
+  data_type: 'integer'
+  is_foreign_key: 1
+  is_nullable: 0
+
+=cut
+
+__PACKAGE__->add_columns(
+  "item",
+  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
+  "host",
+  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</host>
+
+=item * L</item>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("host", "item");
+
+=head1 UNIQUE CONSTRAINTS
+
+=head2 C<item_bundles_uniq_1>
+
+=over 4
+
+=item * L</item>
+
+=back
+
+=cut
+
+__PACKAGE__->add_unique_constraint("item_bundles_uniq_1", ["item"]);
+
+=head1 RELATIONS
+
+=head2 host
+
+Type: belongs_to
+
+Related object: L<Koha::Schema::Result::Item>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "host",
+  "Koha::Schema::Result::Item",
+  { itemnumber => "host" },
+  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
+);
+
+=head2 item
+
+Type: belongs_to
+
+Related object: L<Koha::Schema::Result::Item>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "item",
+  "Koha::Schema::Result::Item",
+  { itemnumber => "item" },
+  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-08-10 13:47:56
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:QXlgF8iwZUFSsg+Eo5kNUw
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;
diff --git a/Koha/Schema/Result/ItemsLostIssue.pm b/Koha/Schema/Result/ItemsLostIssue.pm
new file mode 100644
index 0000000000..6d213d9ee4
--- /dev/null
+++ b/Koha/Schema/Result/ItemsLostIssue.pm
@@ -0,0 +1,138 @@
+use utf8;
+package Koha::Schema::Result::ItemsLostIssue;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Koha::Schema::Result::ItemsLostIssue
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<items_lost_issue>
+
+=cut
+
+__PACKAGE__->table("items_lost_issue");
+
+=head1 ACCESSORS
+
+=head2 id
+
+  data_type: 'integer'
+  is_auto_increment: 1
+  is_nullable: 0
+
+=head2 itemnumber
+
+  data_type: 'integer'
+  is_foreign_key: 1
+  is_nullable: 0
+
+=head2 issue_id
+
+  data_type: 'integer'
+  is_foreign_key: 1
+  is_nullable: 1
+
+=head2 created_on
+
+  data_type: 'timestamp'
+  datetime_undef_if_invalid: 1
+  default_value: current_timestamp
+  is_nullable: 0
+
+=cut
+
+__PACKAGE__->add_columns(
+  "id",
+  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
+  "itemnumber",
+  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
+  "issue_id",
+  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
+  "created_on",
+  {
+    data_type => "timestamp",
+    datetime_undef_if_invalid => 1,
+    default_value => \"current_timestamp",
+    is_nullable => 0,
+  },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</id>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("id");
+
+=head1 UNIQUE CONSTRAINTS
+
+=head2 C<itemnumber>
+
+=over 4
+
+=item * L</itemnumber>
+
+=back
+
+=cut
+
+__PACKAGE__->add_unique_constraint("itemnumber", ["itemnumber"]);
+
+=head1 RELATIONS
+
+=head2 issue
+
+Type: belongs_to
+
+Related object: L<Koha::Schema::Result::OldIssue>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "issue",
+  "Koha::Schema::Result::OldIssue",
+  { issue_id => "issue_id" },
+  {
+    is_deferrable => 1,
+    join_type     => "LEFT",
+    on_delete     => "SET NULL",
+    on_update     => "CASCADE",
+  },
+);
+
+=head2 itemnumber
+
+Type: belongs_to
+
+Related object: L<Koha::Schema::Result::Item>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "itemnumber",
+  "Koha::Schema::Result::Item",
+  { itemnumber => "itemnumber" },
+  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-23 07:00:41
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:8QBruozDPiIGKamb3U2Wxw
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;
diff --git a/Koha/Schema/Result/OldIssue.pm b/Koha/Schema/Result/OldIssue.pm
index 7d37600caf..a3c5d090c7 100644
--- a/Koha/Schema/Result/OldIssue.pm
+++ b/Koha/Schema/Result/OldIssue.pm
@@ -305,9 +305,24 @@ __PACKAGE__->belongs_to(
   },
 );
 
+=head2 items_lost_issues
 
-# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BWwXBAuls9a0HhscR0WlGQ
+Type: has_many
+
+Related object: L<Koha::Schema::Result::ItemsLostIssue>
+
+=cut
+
+__PACKAGE__->has_many(
+  "items_lost_issues",
+  "Koha::Schema::Result::ItemsLostIssue",
+  { "foreign.issue_id" => "self.issue_id" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-23 07:00:41
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RYZFozdomZ0NrvimL6+YZQ
 
 __PACKAGE__->add_columns(
     '+auto_renew'      => { is_boolean => 1 },
-- 
2.20.1