|
Line 0
Link Here
|
|
|
1 |
package Koha::ShibbolethConfig; |
| 2 |
|
| 3 |
use Modern::Perl; |
| 4 |
use base qw(Koha::Object); |
| 5 |
|
| 6 |
use Koha::ShibbolethFieldMappings; |
| 7 |
|
| 8 |
=head1 NAME |
| 9 |
|
| 10 |
Koha::ShibbolethConfig - Koha ShibbolethConfig Object class |
| 11 |
|
| 12 |
=head1 API |
| 13 |
|
| 14 |
=head2 Class Methods |
| 15 |
|
| 16 |
=cut |
| 17 |
|
| 18 |
=head3 _type |
| 19 |
|
| 20 |
=cut |
| 21 |
|
| 22 |
sub _type { |
| 23 |
return 'ShibbolethConfig'; |
| 24 |
} |
| 25 |
|
| 26 |
=head3 store |
| 27 |
|
| 28 |
Override store method to ensure we always update the single config row |
| 29 |
|
| 30 |
=cut |
| 31 |
|
| 32 |
sub store { |
| 33 |
my ($self) = @_; |
| 34 |
|
| 35 |
# Force ID to be 1 |
| 36 |
$self->shibboleth_config_id(1); |
| 37 |
|
| 38 |
# If record exists, update it |
| 39 |
if ( my $existing = Koha::ShibbolethConfigs->find(1) ) { |
| 40 |
foreach my $field (qw( force_opac_sso force_staff_sso autocreate sync welcome )) { |
| 41 |
$existing->$field( $self->$field ) if defined $self->$field; |
| 42 |
} |
| 43 |
return $existing->SUPER::store(); |
| 44 |
} |
| 45 |
|
| 46 |
# Otherwise create new record with ID 1 |
| 47 |
return $self->SUPER::store(); |
| 48 |
} |
| 49 |
|
| 50 |
=head3 mappings |
| 51 |
|
| 52 |
Returns field mappings associated with this config |
| 53 |
|
| 54 |
=cut |
| 55 |
|
| 56 |
sub mappings { |
| 57 |
my ($self) = @_; |
| 58 |
return Koha::ShibbolethFieldMappings->new; |
| 59 |
} |
| 60 |
|
| 61 |
=head3 get_combined_config |
| 62 |
|
| 63 |
Returns complete configuration including mappings |
| 64 |
|
| 65 |
=cut |
| 66 |
|
| 67 |
sub get_combined_config { |
| 68 |
my ($self) = @_; |
| 69 |
|
| 70 |
my $config = $self->unblessed; |
| 71 |
my ( $success, $mapping_config ) = $self->mappings->get_mapping_config; |
| 72 |
|
| 73 |
if ($success) { |
| 74 |
|
| 75 |
# Merge mapping config with base config |
| 76 |
$config->{matchpoint} = $mapping_config->{matchpoint}; |
| 77 |
$config->{mapping} = $mapping_config->{mapping}; |
| 78 |
return $config; |
| 79 |
} |
| 80 |
|
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
=head3 get_field_mappings |
| 85 |
|
| 86 |
Returns a hashref of field mappings in config format |
| 87 |
|
| 88 |
=cut |
| 89 |
|
| 90 |
sub get_field_mappings { |
| 91 |
my ($self) = @_; |
| 92 |
my ( $success, $mapping_config ) = $self->mappings->get_mapping_config; |
| 93 |
return $mapping_config->{mapping} if $success; |
| 94 |
return {}; |
| 95 |
} |
| 96 |
|
| 97 |
=head3 get_value |
| 98 |
|
| 99 |
Returns the value of a specific configuration column. |
| 100 |
|
| 101 |
@param string $column The name of the configuration column to retrieve |
| 102 |
@return mixed The value of the configuration column or undef if not found |
| 103 |
|
| 104 |
=cut |
| 105 |
|
| 106 |
sub get_value { |
| 107 |
my ( $self, $column ) = @_; |
| 108 |
return unless $column; |
| 109 |
return unless $self->_result->result_source->has_column($column); |
| 110 |
return $self->$column; |
| 111 |
} |
| 112 |
|
| 113 |
1; |