From 3332c152b6d481e529643f30d3a284d6a307fe29 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 17 Mar 2025 15:13:05 +0000 Subject: [PATCH] Bug 39190: Update polymorhpic base class to identify itself This patch adds _polymorphic_field and _polymorphic_map private methods to the Koha::File::Transports class to more clearly identify this as a polymorphic class base for TestBuilder. Signed-off-by: Kyle M Hall --- Koha/SFTP/Servers.pm | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Koha/SFTP/Servers.pm b/Koha/SFTP/Servers.pm index 6859bbe2e45..992e6349d2d 100644 --- a/Koha/SFTP/Servers.pm +++ b/Koha/SFTP/Servers.pm @@ -42,6 +42,29 @@ sub _type { return 'SftpServer'; } +=head3 _polymorphic_field + +Return the field in the table that defines the polymorphic class to be built + +=cut + +sub _polymorphic_field { + return 'transport'; # This field defines which subclass to use +} + +=head3 _polymorphic_map + +Return the mapping for field value to class name for the polymorphic class + +=cut + +sub _polymorphic_map { + return { + sftp => 'Koha::File::Transport::SFTP', + ftp => 'Koha::File::Transport::FTP', + }; +} + =head3 object_class Return object class @@ -49,7 +72,14 @@ Return object class =cut sub object_class { - return 'Koha::SFTP::Server'; + my ( $self, $object ) = @_; + + return 'Koha::File::Transport' unless $object; + + my $field = $self->_polymorphic_field; + my $map = $self->_polymorphic_map; + + return $map->{ lc( $object->$field ) } || 'Koha::File::Transport'; } 1; -- 2.49.0