Browse Source

Bug 15446: Rename Koha::Object[s]->type with _type

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 <veron@veron.ch>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
new_12478_elasticsearch
Jonathan Druart 8 years ago
committed by Jesse Weaver
parent
commit
de3289506d
  1. 2
      Koha/AudioAlert.pm
  2. 2
      Koha/AudioAlerts.pm
  3. 2
      Koha/AuthorisedValue.pm
  4. 2
      Koha/AuthorisedValues.pm
  5. 2
      Koha/Biblio.pm
  6. 2
      Koha/Biblioitem.pm
  7. 2
      Koha/Biblioitems.pm
  8. 2
      Koha/Biblios.pm
  9. 2
      Koha/Borrower.pm
  10. 2
      Koha/Borrowers.pm
  11. 2
      Koha/Cities.pm
  12. 2
      Koha/City.pm
  13. 2
      Koha/Config/SysPref.pm
  14. 2
      Koha/Config/SysPrefs.pm
  15. 2
      Koha/Hold.pm
  16. 2
      Koha/Holds.pm
  17. 2
      Koha/Item.pm
  18. 2
      Koha/Items.pm
  19. 2
      Koha/Localization.pm
  20. 2
      Koha/Localizations.pm
  21. 22
      Koha/Object.pm
  22. 14
      Koha/Objects.pm
  23. 2
      Koha/Patron/Categories.pm
  24. 2
      Koha/Patron/Category.pm
  25. 2
      Koha/Serial.pm
  26. 2
      Koha/Serials.pm
  27. 2
      Koha/Virtualshelf.pm
  28. 2
      Koha/Virtualshelfcontent.pm
  29. 2
      Koha/Virtualshelfcontents.pm
  30. 2
      Koha/Virtualshelfshare.pm
  31. 2
      Koha/Virtualshelfshares.pm
  32. 2
      Koha/Virtualshelves.pm

2
Koha/AudioAlert.pm

@ -66,7 +66,7 @@ sub move {
=cut
sub type {
sub _type {
return 'AudioAlert';
}

2
Koha/AudioAlerts.pm

@ -136,7 +136,7 @@ sub fix_precedences {
=cut
sub type {
sub _type {
return 'AudioAlert';
}

2
Koha/AuthorisedValue.pm

@ -164,7 +164,7 @@ sub _avb_resultset {
=cut
sub type {
sub _type {
return 'AuthorisedValue';
}

2
Koha/AuthorisedValues.pm

@ -79,7 +79,7 @@ sub categories {
=cut
sub type {
sub _type {
return 'AuthorisedValue';
}

2
Koha/Biblio.pm

@ -58,7 +58,7 @@ sub subtitles {
=cut
sub type {
sub _type {
return 'Biblio';
}

2
Koha/Biblioitem.pm

@ -37,7 +37,7 @@ Koha::Biblioitem - Koha Biblioitem Object class
=cut
sub type {
sub _type {
return 'Biblioitem';
}

2
Koha/Biblioitems.pm

@ -39,7 +39,7 @@ Koha::Biblioitem - Koha Biblioitem Object class
=cut
sub type {
sub _type {
return 'Biblioitem';
}

2
Koha/Biblios.pm

@ -41,7 +41,7 @@ Koha::Biblios - Koha Biblio object set class
=cut
sub type {
sub _type {
return 'Biblio';
}

2
Koha/Borrower.pm

@ -51,7 +51,7 @@ sub guarantor {
=cut
sub type {
sub _type {
return 'Borrower';
}

2
Koha/Borrowers.pm

@ -41,7 +41,7 @@ Koha::Borrower - Koha Borrower Object class
=cut
sub type {
sub _type {
return 'Borrower';
}

2
Koha/Cities.pm

@ -39,7 +39,7 @@ Koha::Cities - Koha City Object set class
=cut
sub type {
sub _type {
return 'City';
}

2
Koha/City.pm

@ -37,7 +37,7 @@ Koha::City - Koha City Object class
=cut
sub type {
sub _type {
return 'City';
}

2
Koha/Config/SysPref.pm

@ -39,7 +39,7 @@ Koha::Config::SysPref - Koha System Preference Object class
=cut
sub type {
sub _type {
return 'Systempreference';
}

2
Koha/Config/SysPrefs.pm

@ -41,7 +41,7 @@ Koha::Config::SysPrefs - Koha System Preference object set class
=cut
sub type {
sub _type {
return 'Systempreference';
}

2
Koha/Hold.pm

@ -251,7 +251,7 @@ sub is_suspended {
=cut
sub type {
sub _type {
return 'Reserve';
}

2
Koha/Holds.pm

@ -53,7 +53,7 @@ sub waiting {
=cut
sub type {
sub _type {
return 'Reserve';
}

2
Koha/Item.pm

@ -111,7 +111,7 @@ sub last_returned_by {
=cut
sub type {
sub _type {
return 'Item';
}

2
Koha/Items.pm

@ -41,7 +41,7 @@ Koha::Items - Koha Item object set class
=cut
sub type {
sub _type {
return 'Item';
}

2
Koha/Localization.pm

@ -21,7 +21,7 @@ use Koha::Database;
use base qw(Koha::Object);
sub type {
sub _type {
return 'Localization';
}

2
Koha/Localizations.pm

@ -23,7 +23,7 @@ use Koha::Localization;
use base qw(Koha::Objects);
sub type {
sub _type {
return 'Localization';
}

22
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 { }

14
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

2
Koha/Patron/Categories.pm

@ -39,7 +39,7 @@ Koha::Patron::Categories - Koha Patron Category Object set class
=cut
sub type {
sub _type {
return 'Category';
}

2
Koha/Patron/Category.pm

@ -181,7 +181,7 @@ sub _catb_resultset {
=cut
sub type {
sub _type {
return 'Category';
}

2
Koha/Serial.pm

@ -39,7 +39,7 @@ Koha::Serial - Koha Serial Object class
=cut
sub type {
sub _type {
return 'Serial';
}

2
Koha/Serials.pm

@ -41,7 +41,7 @@ Koha::Serial - Koha Serial Object class
=cut
sub type {
sub _type {
return 'Serial';
}

2
Koha/Virtualshelf.pm

@ -273,7 +273,7 @@ sub can_biblios_be_removed {
return 0;
}
sub type {
sub _type {
return 'Virtualshelve';
}

2
Koha/Virtualshelfcontent.pm

@ -38,7 +38,7 @@ Koha::Virtualshelfcontent - Koha Virtualshelfcontent Object class
=cut
sub type {
sub _type {
return 'Virtualshelfcontent';
}

2
Koha/Virtualshelfcontents.pm

@ -39,7 +39,7 @@ Koha::Virtualshelfcontents - Koha Virtualshelfcontents Object class
=cut
sub type {
sub _type {
return 'Virtualshelfcontent';
}

2
Koha/Virtualshelfshare.pm

@ -67,7 +67,7 @@ sub has_expired {
return $has_expired == 1 ? 1 : 0
}
sub type {
sub _type {
return 'Virtualshelfshare';
}

2
Koha/Virtualshelfshares.pm

@ -39,7 +39,7 @@ Koha::Virtualshelfshares - Koha Virtualshelfshares Object class
=cut
sub type {
sub _type {
return 'Virtualshelfshare';
}

2
Koha/Virtualshelves.pm

@ -119,7 +119,7 @@ sub get_some_shelves {
);
}
sub type {
sub _type {
return 'Virtualshelve';
}

Loading…
Cancel
Save