From 3360dee4486cff709deb69efe0ef4fd11d360fe2 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 27 Apr 2022 17:07:01 -0300 Subject: [PATCH] Bug 30275: (QA follow-up) Rename columns to match API This patch performs the following column renames: * id => renewal_id * issue_id => checkout_id The idea is that no translation is needed for the API, and also, being a new table, we can educate the users into the 'to be' terminology we are leaning towards, instead of having them learn one naming to create reports and then need to translate them once we normalize things in a future. That said, this is simple to review. Apply this patch and repeat the test plan. Signed-off-by: Tomas Cohen Arazi --- C4/Circulation.pm | 8 +++--- Koha/Checkouts/Renewal.pm | 27 +++++-------------- Koha/Schema/Result/Borrower.pm | 4 +-- Koha/Schema/Result/CheckoutRenewal.pm | 22 +++++++-------- Koha/Schema/Result/Issue.pm | 2 +- Koha/Schema/Result/OldIssue.pm | 2 +- .../data/mysql/atomicupdate/bug_30275.pl | 6 ++--- installer/data/mysql/kohastructure.sql | 6 ++--- 8 files changed, 31 insertions(+), 46 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 655da8cefc..58e374d524 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3215,10 +3215,10 @@ sub AddRenewal { # Add renewal record my $renewal = Koha::Checkouts::Renewal->new( { - issue_id => $issue->issue_id, - renewer_id => C4::Context->userenv->{'number'}, - seen => $seen, - interface => C4::Context->interface + checkout_id => $issue->issue_id, + renewer_id => C4::Context->userenv->{'number'}, + seen => $seen, + interface => C4::Context->interface } )->store(); diff --git a/Koha/Checkouts/Renewal.pm b/Koha/Checkouts/Renewal.pm index e8a513d650..bb8c54992a 100644 --- a/Koha/Checkouts/Renewal.pm +++ b/Koha/Checkouts/Renewal.pm @@ -21,12 +21,11 @@ use Modern::Perl; use base qw(Koha::Object); -use Koha::Checkout; use Koha::Checkouts; -use Koha::Exceptions; use Koha::Exceptions::Checkouts::Renewals; +use Koha::Exceptions::Object; use Koha::Old::Checkouts; -use Koha::Patron; +use Koha::Patrons; =head1 NAME @@ -54,13 +53,13 @@ sub store { Koha::Exceptions::Checkouts::Renewals::NoRenewerID->throw(); } - unless ( ( !$self->issue_id && $self->in_storage ) - || Koha::Checkouts->find( $self->issue_id ) - || Koha::Old::Checkouts->find( $self->issue_id ) ) + unless ( ( !$self->checkout_id && $self->in_storage ) + || Koha::Checkouts->find( $self->checkout_id ) + || Koha::Old::Checkouts->find( $self->checkout_id ) ) { Koha::Exceptions::Object::FKConstraint->throw( error => 'Broken FK constraint', - broken_fk => 'issue_id' + broken_fk => 'checkout_id' ); } @@ -102,20 +101,6 @@ sub renewer { return Koha::Patron->_new_from_dbic( $renewer ) if $renewer; } -=head3 to_api_mapping - -This method returns the mapping for representing a Koha::Checkouts::Renewal object -on the API. - -=cut - -sub to_api_mapping { - return { - id => 'renewal_id', - issue_id => 'checkout_id' - }; -} - =head2 Internal methods =head3 _type diff --git a/Koha/Schema/Result/Borrower.pm b/Koha/Schema/Result/Borrower.pm index be9748e59e..2c7512e14b 100644 --- a/Koha/Schema/Result/Borrower.pm +++ b/Koha/Schema/Result/Borrower.pm @@ -1980,8 +1980,8 @@ Composing rels: L -> permission __PACKAGE__->many_to_many("permissions", "user_permissions", "permission"); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-05-06 19:32:13 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:lGlRQ4XvRdsrqTye6sDpYg +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-04-27 19:43:17 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:75KmxqXqexvJ93e4awqwbw __PACKAGE__->has_many( "extended_attributes", diff --git a/Koha/Schema/Result/CheckoutRenewal.pm b/Koha/Schema/Result/CheckoutRenewal.pm index 2e230ca9a6..67a17aa132 100644 --- a/Koha/Schema/Result/CheckoutRenewal.pm +++ b/Koha/Schema/Result/CheckoutRenewal.pm @@ -23,18 +23,18 @@ __PACKAGE__->table("checkout_renewals"); =head1 ACCESSORS -=head2 id +=head2 renewal_id data_type: 'integer' is_auto_increment: 1 is_nullable: 0 -=head2 issue_id +=head2 checkout_id data_type: 'integer' is_nullable: 1 -the id of the issue this renewal pertains to +the id of the checkout this renewal pertains to =head2 renewer_id @@ -72,9 +72,9 @@ the date and time the renewal took place =cut __PACKAGE__->add_columns( - "id", + "renewal_id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, - "issue_id", + "checkout_id", { data_type => "integer", is_nullable => 1 }, "renewer_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, @@ -95,13 +95,13 @@ __PACKAGE__->add_columns( =over 4 -=item * L +=item * L =back =cut -__PACKAGE__->set_primary_key("id"); +__PACKAGE__->set_primary_key("renewal_id"); =head1 RELATIONS @@ -126,8 +126,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-03-11 16:33:50 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:agLgLnVeKYB5wdWS06xD0A +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-04-27 19:43:17 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7mjiEx634L5FZyjroACUkg =head2 checkout @@ -140,7 +140,7 @@ Related object: L __PACKAGE__->belongs_to( "checkout", "Koha::Schema::Result::Issue", - { issue_id => "issue_id" }, + { issue_id => "checkout_id" }, { is_deferrable => 1, join_type => "LEFT", @@ -158,7 +158,7 @@ Related object: L __PACKAGE__->belongs_to( "old_checkout", "Koha::Schema::Result::OldIssue", - { issue_id => "issue_id" }, + { issue_id => "checkout_id" }, { is_deferrable => 1, join_type => "LEFT", diff --git a/Koha/Schema/Result/Issue.pm b/Koha/Schema/Result/Issue.pm index 44debc944b..cd024b9de5 100644 --- a/Koha/Schema/Result/Issue.pm +++ b/Koha/Schema/Result/Issue.pm @@ -384,7 +384,7 @@ Related object: L __PACKAGE__->has_many( "renewals", "Koha::Schema::Result::CheckoutRenewal", - { "foreign.issue_id" => "self.issue_id" }, + { "foreign.checkout_id" => "self.issue_id" }, { cascade_copy => 0, cascade_delete => 0 }, ); diff --git a/Koha/Schema/Result/OldIssue.pm b/Koha/Schema/Result/OldIssue.pm index 1383033d31..759f7185e1 100644 --- a/Koha/Schema/Result/OldIssue.pm +++ b/Koha/Schema/Result/OldIssue.pm @@ -354,7 +354,7 @@ Related object: L __PACKAGE__->has_many( "renewals", "Koha::Schema::Result::CheckoutRenewal", - { "foreign.issue_id" => "self.issue_id" }, + { "foreign.checkout_id" => "self.issue_id" }, { cascade_copy => 0, cascade_delete => 0 }, ); diff --git a/installer/data/mysql/atomicupdate/bug_30275.pl b/installer/data/mysql/atomicupdate/bug_30275.pl index a77882c0dc..68ea87f83b 100755 --- a/installer/data/mysql/atomicupdate/bug_30275.pl +++ b/installer/data/mysql/atomicupdate/bug_30275.pl @@ -9,13 +9,13 @@ return { unless ( TableExists('checkout_renewals') ) { $dbh->do(q{ CREATE TABLE `checkout_renewals` ( - `id` int(11) NOT NULL auto_increment, - `issue_id` int(11) DEFAULT NULL COMMENT 'the id of the issue this renewal pertains to', + `renewal_id` int(11) NOT NULL auto_increment, + `checkout_id` int(11) DEFAULT NULL COMMENT 'the id of the checkout this renewal pertains to', `renewer_id` int(11) DEFAULT NULL COMMENT 'the id of the user who processed the renewal', `seen` tinyint(1) DEFAULT 0 COMMENT 'boolean denoting whether the item was present or not', `interface` varchar(16) NOT NULL COMMENT 'the interface this renewal took place on', `timestamp` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'the date and time the renewal took place', - PRIMARY KEY(`id`), + PRIMARY KEY(`renewal_id`), KEY `renewer_id` (`renewer_id`), CONSTRAINT `renewals_renewer_id` FOREIGN KEY (`renewer_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 317388f303..7dbfcd96aa 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1698,13 +1698,13 @@ DROP TABLE IF EXISTS `checkout_renewals`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `checkout_renewals` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `issue_id` int(11) DEFAULT NULL COMMENT 'the id of the issue this renewal pertains to', + `renewal_id` int(11) NOT NULL AUTO_INCREMENT, + `checkout_id` int(11) DEFAULT NULL COMMENT 'the id of the checkout this renewal pertains to', `renewer_id` int(11) DEFAULT NULL COMMENT 'the id of the user who processed the renewal', `seen` tinyint(1) DEFAULT 0 COMMENT 'boolean denoting whether the item was present or not', `interface` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'the interface this renewal took place on', `timestamp` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'the date and time the renewal took place', - PRIMARY KEY (`id`), + PRIMARY KEY (`renewal_id`), KEY `renewer_id` (`renewer_id`), CONSTRAINT `renewals_renewer_id` FOREIGN KEY (`renewer_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- 2.20.1