Bug 37893: SIP accounts - Koha classes

Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Pedro Amorim 2024-10-14 15:55:09 +00:00 committed by Lucas Gass
parent c84cfa3b50
commit deebeb2817
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 162 additions and 0 deletions

95
Koha/SIP2/Account.pm Normal file
View File

@ -0,0 +1,95 @@
package Koha::SIP2::Account;
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use base qw(Koha::SIP2::Object Koha::Object);
use Koha::SIP2::Institution;
=head1 NAME
Koha::SIP2::Account- Koha SipAccount Object class
=head1 API
=head2 Class Methods
=cut
=head3 get_for_config
Returns the account hashref as expected by C4/SIP/Sip/Configuration->new;
=cut
sub get_for_config {
my ($self) = @_;
my $unblessed = $self->unblessed;
foreach my $key ( keys %$unblessed ) {
# Remove all undef entries
if ( !defined $unblessed->{$key} ) {
delete $unblessed->{$key};
next;
}
# Convert all integer values to strings
if ( $unblessed->{$key} =~ /^[0-9]+$/ ) {
$unblessed->{$key} = $unblessed->{$key} . '';
}
}
# Delete fields unused by C4/SIP
delete $unblessed->{sip_institution_id};
delete $unblessed->{sip_account_id};
# Map database columns to their expected C4/SIP counterparts
$unblessed->{institution} = $self->institution->name;
$unblessed->{id} = delete $unblessed->{login_id};
$unblessed->{password} = delete $unblessed->{login_password};
if ( $unblessed->{error_detect} ) {
$unblessed->{'error-detect'} = 'enabled';
delete $unblessed->{error_detect};
}
return $unblessed;
}
=head3 institution
Return the institution for this account
=cut
sub institution {
my ($self) = @_;
my $institution_rs = $self->_result->sip_institution;
return unless $institution_rs;
return Koha::SIP2::Institution->_new_from_dbic($institution_rs);
}
=head3 type
=cut
sub _type {
return 'SipAccount';
}
1;

67
Koha/SIP2/Accounts.pm Normal file
View File

@ -0,0 +1,67 @@
package Koha::SIP2::Accounts;
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Koha::SIP2::Account;
use base qw(Koha::Objects);
=head1 NAME
Koha::SIP2::Accounts- Koha SipAccount Object set class
=head1 API
=head2 Class Methods
=cut
=head3 get_for_config
Returns the accounts hashref as expected by C4/SIP/Sip/Configuration->new;
=cut
sub get_for_config {
my ($self) = @_;
my $accounts = $self->search();
my $return_hash;
while (my $sip2_account = $accounts->next()) {
$return_hash->{$sip2_account->login_id} = $sip2_account->get_for_config();
} return $return_hash;
}
=head3 type
=cut
sub _type {
return 'SipAccount';
}
=head3 object_class
=cut
sub object_class {
return 'Koha::SIP2::Account';
}
1;