From c4c752d10109438faf985e8a6211de4baad8e3d2 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. --- Koha/File/Transports.pm | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/Koha/File/Transports.pm b/Koha/File/Transports.pm index 1c37ea76c59..932a7248696 100644 --- a/Koha/File/Transports.pm +++ b/Koha/File/Transports.pm @@ -43,6 +43,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 dynamically based on transport @@ -54,12 +77,10 @@ sub object_class { return 'Koha::File::Transport' unless $object; - my %class_map = ( - sftp => 'Koha::File::Transport::SFTP', - ftp => 'Koha::File::Transport::FTP', - ); + my $field = $self->_polymorphic_field; + my $map = $self->_polymorphic_map; - return $class_map{ lc( $object->transport ) } || 'Koha::File::Transport'; + return $map->{ lc( $object->$field ) } || 'Koha::File::Transport'; } 1; -- 2.48.1