From de3289506dcda91510dc9c7a867558a29ebefd57 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 30 Dec 2015 17:15:31 +0000 Subject: [PATCH] Bug 15446: Rename Koha::Object[s]->type with _type MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In a few case (at least systempreferences and export_format (csv profiles), the type method of Koha::Object and Koha::Objects can be in conflict with the column names. Indeed systempreferences.type exists and so the method will return 'Systempreference' (the name of the module) instead of the value of the row in DB. I have found at least 1 place where it can cause issue: In C4::Context->set_preference: 601 my $syspref = Koha::Config::SysPrefs->find( $var ); 602 my $type = $syspref ? $syspref->type() : undef; 603 604 $value = 0 if ( $type && $type eq 'YesNo' && $value eq '' ); type will always be 'Systempreference' and the YesNo pref will be set to an empty string '' instead of 0. I am not sure about the consequences of this, but it is preferable to fix it ASAP. To reproduce: 0/ Do not apply this patch 1/ Edit a YesNo prefs, AutoEmailOpacUser for instance 2/ Set it to "Don't sent" 3/ Check the value in DB, it should be set to an empty string, instead of 0 4/ Apply this patch and try again. Now the value should be 0 Followed test plan, value is now 0 as expected. Signed-off-by: Marc Véron Signed-off-by: Kyle M Hall Signed-off-by: Jesse Weaver --- Koha/AudioAlert.pm | 2 +- Koha/AudioAlerts.pm | 2 +- Koha/AuthorisedValue.pm | 2 +- Koha/AuthorisedValues.pm | 2 +- Koha/Biblio.pm | 2 +- Koha/Biblioitem.pm | 2 +- Koha/Biblioitems.pm | 2 +- Koha/Biblios.pm | 2 +- Koha/Borrower.pm | 2 +- Koha/Borrowers.pm | 2 +- Koha/Cities.pm | 2 +- Koha/City.pm | 2 +- Koha/Config/SysPref.pm | 2 +- Koha/Config/SysPrefs.pm | 2 +- Koha/Hold.pm | 2 +- Koha/Holds.pm | 2 +- Koha/Item.pm | 2 +- Koha/Items.pm | 2 +- Koha/Localization.pm | 2 +- Koha/Localizations.pm | 2 +- Koha/Object.pm | 22 +++++++++++----------- Koha/Objects.pm | 14 ++++++-------- Koha/Patron/Categories.pm | 2 +- Koha/Patron/Category.pm | 2 +- Koha/Serial.pm | 2 +- Koha/Serials.pm | 2 +- Koha/Virtualshelf.pm | 2 +- Koha/Virtualshelfcontent.pm | 2 +- Koha/Virtualshelfcontents.pm | 2 +- Koha/Virtualshelfshare.pm | 2 +- Koha/Virtualshelfshares.pm | 2 +- Koha/Virtualshelves.pm | 2 +- 32 files changed, 47 insertions(+), 49 deletions(-) diff --git a/Koha/AudioAlert.pm b/Koha/AudioAlert.pm index e6873f4312..e23e46b534 100644 --- a/Koha/AudioAlert.pm +++ b/Koha/AudioAlert.pm @@ -66,7 +66,7 @@ sub move { =cut -sub type { +sub _type { return 'AudioAlert'; } diff --git a/Koha/AudioAlerts.pm b/Koha/AudioAlerts.pm index d21a982165..be4f51a9ee 100644 --- a/Koha/AudioAlerts.pm +++ b/Koha/AudioAlerts.pm @@ -136,7 +136,7 @@ sub fix_precedences { =cut -sub type { +sub _type { return 'AudioAlert'; } diff --git a/Koha/AuthorisedValue.pm b/Koha/AuthorisedValue.pm index ec7abe55be..71758a940c 100644 --- a/Koha/AuthorisedValue.pm +++ b/Koha/AuthorisedValue.pm @@ -164,7 +164,7 @@ sub _avb_resultset { =cut -sub type { +sub _type { return 'AuthorisedValue'; } diff --git a/Koha/AuthorisedValues.pm b/Koha/AuthorisedValues.pm index e690d8ceca..718b8f8c6a 100644 --- a/Koha/AuthorisedValues.pm +++ b/Koha/AuthorisedValues.pm @@ -79,7 +79,7 @@ sub categories { =cut -sub type { +sub _type { return 'AuthorisedValue'; } diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 48c959d08f..97adf62b5b 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -58,7 +58,7 @@ sub subtitles { =cut -sub type { +sub _type { return 'Biblio'; } diff --git a/Koha/Biblioitem.pm b/Koha/Biblioitem.pm index b71cfd8c43..8d353c8f0b 100644 --- a/Koha/Biblioitem.pm +++ b/Koha/Biblioitem.pm @@ -37,7 +37,7 @@ Koha::Biblioitem - Koha Biblioitem Object class =cut -sub type { +sub _type { return 'Biblioitem'; } diff --git a/Koha/Biblioitems.pm b/Koha/Biblioitems.pm index c21c64daa9..c4d61446e0 100644 --- a/Koha/Biblioitems.pm +++ b/Koha/Biblioitems.pm @@ -39,7 +39,7 @@ Koha::Biblioitem - Koha Biblioitem Object class =cut -sub type { +sub _type { return 'Biblioitem'; } diff --git a/Koha/Biblios.pm b/Koha/Biblios.pm index cba48ea682..29f32fc190 100644 --- a/Koha/Biblios.pm +++ b/Koha/Biblios.pm @@ -41,7 +41,7 @@ Koha::Biblios - Koha Biblio object set class =cut -sub type { +sub _type { return 'Biblio'; } diff --git a/Koha/Borrower.pm b/Koha/Borrower.pm index 6604b8afcb..d058301110 100644 --- a/Koha/Borrower.pm +++ b/Koha/Borrower.pm @@ -51,7 +51,7 @@ sub guarantor { =cut -sub type { +sub _type { return 'Borrower'; } diff --git a/Koha/Borrowers.pm b/Koha/Borrowers.pm index 9fb01f0f37..f532d6f423 100644 --- a/Koha/Borrowers.pm +++ b/Koha/Borrowers.pm @@ -41,7 +41,7 @@ Koha::Borrower - Koha Borrower Object class =cut -sub type { +sub _type { return 'Borrower'; } diff --git a/Koha/Cities.pm b/Koha/Cities.pm index 6e578b029c..29b5f89c43 100644 --- a/Koha/Cities.pm +++ b/Koha/Cities.pm @@ -39,7 +39,7 @@ Koha::Cities - Koha City Object set class =cut -sub type { +sub _type { return 'City'; } diff --git a/Koha/City.pm b/Koha/City.pm index 69f451e9e9..b84b5c3c7f 100644 --- a/Koha/City.pm +++ b/Koha/City.pm @@ -37,7 +37,7 @@ Koha::City - Koha City Object class =cut -sub type { +sub _type { return 'City'; } diff --git a/Koha/Config/SysPref.pm b/Koha/Config/SysPref.pm index e18c222524..e1850b5c60 100644 --- a/Koha/Config/SysPref.pm +++ b/Koha/Config/SysPref.pm @@ -39,7 +39,7 @@ Koha::Config::SysPref - Koha System Preference Object class =cut -sub type { +sub _type { return 'Systempreference'; } diff --git a/Koha/Config/SysPrefs.pm b/Koha/Config/SysPrefs.pm index 552d0c7933..dbf43abec6 100644 --- a/Koha/Config/SysPrefs.pm +++ b/Koha/Config/SysPrefs.pm @@ -41,7 +41,7 @@ Koha::Config::SysPrefs - Koha System Preference object set class =cut -sub type { +sub _type { return 'Systempreference'; } diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 0ecded9370..e54bc13c8d 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -251,7 +251,7 @@ sub is_suspended { =cut -sub type { +sub _type { return 'Reserve'; } diff --git a/Koha/Holds.pm b/Koha/Holds.pm index 41ab3f6a24..d1d8b292e7 100644 --- a/Koha/Holds.pm +++ b/Koha/Holds.pm @@ -53,7 +53,7 @@ sub waiting { =cut -sub type { +sub _type { return 'Reserve'; } diff --git a/Koha/Item.pm b/Koha/Item.pm index 3aa261d1b0..0199f37a75 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -111,7 +111,7 @@ sub last_returned_by { =cut -sub type { +sub _type { return 'Item'; } diff --git a/Koha/Items.pm b/Koha/Items.pm index 072113fdb7..7b86c5a5e0 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -41,7 +41,7 @@ Koha::Items - Koha Item object set class =cut -sub type { +sub _type { return 'Item'; } diff --git a/Koha/Localization.pm b/Koha/Localization.pm index 013db3a427..32bbeaf1ca 100644 --- a/Koha/Localization.pm +++ b/Koha/Localization.pm @@ -21,7 +21,7 @@ use Koha::Database; use base qw(Koha::Object); -sub type { +sub _type { return 'Localization'; } diff --git a/Koha/Localizations.pm b/Koha/Localizations.pm index bcbd8c225c..deed6b8652 100644 --- a/Koha/Localizations.pm +++ b/Koha/Localizations.pm @@ -23,7 +23,7 @@ use Koha::Localization; use base qw(Koha::Objects); -sub type { +sub _type { return 'Localization'; } diff --git a/Koha/Object.pm b/Koha/Object.pm index 34776a124c..9d23fb421e 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -57,12 +57,12 @@ sub new { if ($attributes) { $self->{_result} = - Koha::Database->new()->schema()->resultset( $class->type() ) + Koha::Database->new()->schema()->resultset( $class->_type() ) ->new($attributes); } - croak("No type found! Koha::Object must be subclassed!") - unless $class->type(); + croak("No _type found! Koha::Object must be subclassed!") + unless $class->_type(); bless( $self, $class ); @@ -81,11 +81,11 @@ sub _new_from_dbic { # DBIC result row $self->{_result} = $dbic_row; - croak("No type found! Koha::Object must be subclassed!") - unless $class->type(); + croak("No _type found! Koha::Object must be subclassed!") + unless $class->_type(); - croak( "DBIC result type " . ref( $self->{_result} ) . " isn't of the type " . $class->type() ) - unless ref( $self->{_result} ) eq "Koha::Schema::Result::" . $class->type(); + croak( "DBIC result _type " . ref( $self->{_result} ) . " isn't of the _type " . $class->_type() ) + unless ref( $self->{_result} ) eq "Koha::Schema::Result::" . $class->_type(); bless( $self, $class ); @@ -230,7 +230,7 @@ sub _result { # If we don't have a dbic row at this point, we need to create an empty one $self->{_result} ||= - Koha::Database->new()->schema()->resultset( $self->type() )->new({}); + Koha::Database->new()->schema()->resultset( $self->_type() )->new({}); return $self->{_result}; } @@ -279,14 +279,14 @@ sub AUTOLOAD { return; } -=head3 type +=head3 _type This method must be defined in the child class. The value is the name of the DBIC resultset. -For example, for borrowers, the type method will return "Borrower". +For example, for borrowers, the _type method will return "Borrower". =cut -sub type { } +sub _type { } sub DESTROY { } diff --git a/Koha/Objects.pm b/Koha/Objects.pm index 8312949fcf..8bf15f693e 100644 --- a/Koha/Objects.pm +++ b/Koha/Objects.pm @@ -23,8 +23,6 @@ use Carp; use Koha::Database; -our $type; - =head1 NAME Koha::Objects - Koha Object set base class @@ -229,24 +227,24 @@ sub _resultset { if ( ref($self) ) { $self->{_resultset} ||= - Koha::Database->new()->schema()->resultset( $self->type() ); + Koha::Database->new()->schema()->resultset( $self->_type() ); return $self->{_resultset}; } else { - return Koha::Database->new()->schema()->resultset( $self->type() ); + return Koha::Database->new()->schema()->resultset( $self->_type() ); } } -=head3 type +=head3 _type -The type method must be set for all child classes. +The _type method must be set for all child classes. The value returned by it should be the DBIC resultset name. -For example, for holds, type should return 'Reserve'. +For example, for holds, _type should return 'Reserve'. =cut -sub type { } +sub _type { } =head3 object_class diff --git a/Koha/Patron/Categories.pm b/Koha/Patron/Categories.pm index f220028f45..482da86e28 100644 --- a/Koha/Patron/Categories.pm +++ b/Koha/Patron/Categories.pm @@ -39,7 +39,7 @@ Koha::Patron::Categories - Koha Patron Category Object set class =cut -sub type { +sub _type { return 'Category'; } diff --git a/Koha/Patron/Category.pm b/Koha/Patron/Category.pm index 1a81bc3d72..7b17c8c084 100644 --- a/Koha/Patron/Category.pm +++ b/Koha/Patron/Category.pm @@ -181,7 +181,7 @@ sub _catb_resultset { =cut -sub type { +sub _type { return 'Category'; } diff --git a/Koha/Serial.pm b/Koha/Serial.pm index d6342cc87d..67b32ec5a3 100644 --- a/Koha/Serial.pm +++ b/Koha/Serial.pm @@ -39,7 +39,7 @@ Koha::Serial - Koha Serial Object class =cut -sub type { +sub _type { return 'Serial'; } diff --git a/Koha/Serials.pm b/Koha/Serials.pm index 5d16628b94..e970448320 100644 --- a/Koha/Serials.pm +++ b/Koha/Serials.pm @@ -41,7 +41,7 @@ Koha::Serial - Koha Serial Object class =cut -sub type { +sub _type { return 'Serial'; } diff --git a/Koha/Virtualshelf.pm b/Koha/Virtualshelf.pm index 7ce2738a55..4049e564af 100644 --- a/Koha/Virtualshelf.pm +++ b/Koha/Virtualshelf.pm @@ -273,7 +273,7 @@ sub can_biblios_be_removed { return 0; } -sub type { +sub _type { return 'Virtualshelve'; } diff --git a/Koha/Virtualshelfcontent.pm b/Koha/Virtualshelfcontent.pm index d7fc0c75cb..999cc51c87 100644 --- a/Koha/Virtualshelfcontent.pm +++ b/Koha/Virtualshelfcontent.pm @@ -38,7 +38,7 @@ Koha::Virtualshelfcontent - Koha Virtualshelfcontent Object class =cut -sub type { +sub _type { return 'Virtualshelfcontent'; } diff --git a/Koha/Virtualshelfcontents.pm b/Koha/Virtualshelfcontents.pm index 2a6b77770e..684ad9d847 100644 --- a/Koha/Virtualshelfcontents.pm +++ b/Koha/Virtualshelfcontents.pm @@ -39,7 +39,7 @@ Koha::Virtualshelfcontents - Koha Virtualshelfcontents Object class =cut -sub type { +sub _type { return 'Virtualshelfcontent'; } diff --git a/Koha/Virtualshelfshare.pm b/Koha/Virtualshelfshare.pm index d1a7ffae59..09e383f656 100644 --- a/Koha/Virtualshelfshare.pm +++ b/Koha/Virtualshelfshare.pm @@ -67,7 +67,7 @@ sub has_expired { return $has_expired == 1 ? 1 : 0 } -sub type { +sub _type { return 'Virtualshelfshare'; } diff --git a/Koha/Virtualshelfshares.pm b/Koha/Virtualshelfshares.pm index e49e335139..370dcbb4b2 100644 --- a/Koha/Virtualshelfshares.pm +++ b/Koha/Virtualshelfshares.pm @@ -39,7 +39,7 @@ Koha::Virtualshelfshares - Koha Virtualshelfshares Object class =cut -sub type { +sub _type { return 'Virtualshelfshare'; } diff --git a/Koha/Virtualshelves.pm b/Koha/Virtualshelves.pm index 152d51787f..75ccfa8297 100644 --- a/Koha/Virtualshelves.pm +++ b/Koha/Virtualshelves.pm @@ -119,7 +119,7 @@ sub get_some_shelves { ); } -sub type { +sub _type { return 'Virtualshelve'; } -- 2.39.5