Bug 37893: (QA follow-up): Address qa script complaints

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 2025-10-10 15:59:12 +00:00 committed by Lucas Gass
parent ab7684ca2b
commit f70d7a5405
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
11 changed files with 57 additions and 51 deletions

View File

@ -213,11 +213,17 @@ sub post_accept_hook {
}
}
# Check if the configuration is up to date. Returns 1 if the configuration is up to date, 0 otherwise.
#
# This method is used to check if the configuration stored in the database is different from
# the one stored in the object. If the configuration in the database is newer, the method
# returns 0 and the object must be updated.
=head2 _config_up_to_date
$server->_config_up_to_date();
Check if the configuration is up to date. Returns 1 if the configuration is up to date, 0 otherwise.
This method is used to check if the configuration stored in the database is different from
the one stored in the object. If the configuration in the database is newer, the method
returns 0 and the object must be updated.
=cut
sub _config_up_to_date {
my ($self) = @_;
@ -248,7 +254,7 @@ sub process_request {
$self->{config} = $config;
unless ( $self->_config_up_to_date() ) {
$self->{config} = C4::SIP::Sip::Configuration->get_configuration();
$self->{config} = C4::SIP::Sip::Configuration->get_configuration( undef, $self->{config} );
}
# Flushing L1 to make sure the request will be processed using the correct data

View File

@ -13,6 +13,7 @@ use List::MoreUtils qw(uniq);
use C4::SIP::Sip qw(siplog);
use Koha::Caches;
use Koha::DateUtils qw( dt_from_string );
use Koha::Libraries;
use Koha::SIP2::Institutions;
use Koha::SIP2::Accounts;
@ -38,7 +39,7 @@ my $parser = XML::Simple->new(
);
sub get_configuration {
my ( $class, $config_file ) = @_;
my ( $class, $config_file, $current_config ) = @_;
my $cache = Koha::Caches->get_instance();
my $sip2_resource_last_modified = $cache->get_from_cache("sip2_resource_last_modified");
@ -46,10 +47,15 @@ sub get_configuration {
if ($sip2_resource_last_modified) {
$cache->set_in_cache( 'sip2_config_read_timestamp', $sip2_resource_last_modified );
} else {
$cache->set_in_cache( 'sip2_config_read_timestamp', DateTime->now->epoch );
$cache->set_in_cache( 'sip2_config_read_timestamp', dt_from_string()->epoch );
}
my $cfg = $parser->XMLin($config_file) if $config_file;
my $cfg;
if ($config_file) {
$cfg = $parser->XMLin($config_file);
} else {
$cfg = $current_config;
}
my %listeners;
# The key to the listeners hash is the 'port' component of the

View File

@ -36,8 +36,8 @@ sub list {
my $c = shift->openapi->valid_input or return;
return try {
my $insitutions = $c->objects->search( Koha::SIP2::Accounts->new );
return $c->render( status => 200, openapi => $insitutions );
my $accounts = $c->objects->search( Koha::SIP2::Accounts->new );
return $c->render( status => 200, openapi => $accounts );
} catch {
$c->unhandled_exception($_);
};

View File

@ -38,8 +38,7 @@ sub list {
return try {
my $institutions = $c->objects->search( Koha::SIP2::Institutions->new );
return $c->render( status => 200, openapi => $institutions );
}
catch {
} catch {
$c->unhandled_exception($_);
};
@ -64,8 +63,7 @@ sub get {
status => 200,
openapi => $institution
);
}
catch {
} catch {
$c->unhandled_exception($_);
};
}
@ -87,15 +85,14 @@ sub add {
my $institution = Koha::SIP2::Institution->new_from_api($body)->store;
$c->res->headers->location($c->req->url->to_string . '/' . $institution->sip_institution_id);
$c->res->headers->location( $c->req->url->to_string . '/' . $institution->sip_institution_id );
return $c->render(
status => 201,
openapi => $c->objects->to_api($institution),
);
}
);
}
catch {
} catch {
my $to_api_mapping = Koha::SIP2::Institution->new->to_api_mapping;
@ -105,15 +102,10 @@ sub add {
status => 409,
openapi => { error => $_->error, conflict => $_->duplicate_id }
);
}
elsif ( $_->isa('Koha::Exceptions::BadParameter') ) {
} elsif ( $_->isa('Koha::Exceptions::BadParameter') ) {
return $c->render(
status => 400,
openapi => {
error => "Given "
. $to_api_mapping->{ $_->parameter }
. " does not exist"
}
openapi => { error => "Given " . $to_api_mapping->{ $_->parameter } . " does not exist" }
);
}
}
@ -144,33 +136,28 @@ sub update {
$institution->set_from_api($body)->store;
$c->res->headers->location($c->req->url->to_string . '/' . $institution->sip_institution_id);
$c->res->headers->location( $c->req->url->to_string . '/' . $institution->sip_institution_id );
return $c->render(
status => 200,
openapi => $c->objects->to_api($institution),
);
}
);
}
catch {
} catch {
my $to_api_mapping = Koha::SIP2::Institution->new->to_api_mapping;
if ( blessed $_ ) {
if ( $_->isa('Koha::Exceptions::BadParameter') ) {
return $c->render(
status => 400,
openapi => {
error => "Given "
. $to_api_mapping->{ $_->parameter }
. " does not exist"
}
openapi => { error => "Given " . $to_api_mapping->{ $_->parameter } . " does not exist" }
);
}
}
$c->unhandled_exception($_);
};
};
}
=head3 delete

View File

@ -41,9 +41,9 @@ sub get_for_config {
my ($self) = @_;
return {
'field' => $self->field,
'field' => $self->field,
'template' => $self->template,
}
};
}
=head2 Internal methods

View File

@ -42,8 +42,8 @@ sub get_for_config {
return {
'field' => $self->field,
'code' => $self->code,
}
'code' => $self->code,
};
}
=head2 Internal methods

View File

@ -43,9 +43,10 @@ sub get_for_config {
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;
while ( my $sip2_account = $accounts->next() ) {
$return_hash->{ $sip2_account->login_id } = $sip2_account->get_for_config();
}
return $return_hash;
}
=head3 type

View File

@ -43,9 +43,10 @@ sub get_for_config {
my $institutions = $self->search();
my $return_hash;
while (my $sip2_institution = $institutions->next()) {
$return_hash->{$sip2_institution->name} = $sip2_institution->get_for_config();
} return $return_hash;
while ( my $sip2_institution = $institutions->next() ) {
$return_hash->{ $sip2_institution->name } = $sip2_institution->get_for_config();
}
return $return_hash;
}
=head3 type

View File

@ -19,6 +19,7 @@ use Modern::Perl;
use base qw(Koha::Object);
use Koha::Caches;
use Koha::DateUtils qw( dt_from_string );
use DateTime;
@ -58,7 +59,7 @@ sub delete {
sub _update_config_timestamp {
my $cache = Koha::Caches->get_instance();
$cache->set_in_cache( 'sip2_resource_last_modified', DateTime->now->epoch );
$cache->set_in_cache( 'sip2_resource_last_modified', dt_from_string()->epoch );
}
1;

0
sip2/sip2.pl Normal file → Executable file
View File

16
t/db_dependent/Koha/SIP2/SIP2ModuleMigration.t Normal file → Executable file
View File

@ -17,7 +17,8 @@
use Modern::Perl;
use Test::More tests => 2;
use Test::More tests => 3;
use Test::NoWarnings;
use t::lib::TestBuilder;
@ -81,6 +82,10 @@ subtest 'config_timestamp is updated when database configuration changes' => sub
plan tests => 3;
my $koha_instance = $ENV{KOHA_CONF} =~ m!^.+/sites/([^/]+)/koha-conf\.xml$! ? $1 : undef;
my $SIPconfigXMLFile = "/etc/koha/sites/$koha_instance/SIPconfig.xml";
my $fileSIPconfig = C4::SIP::Sip::Configuration->new($SIPconfigXMLFile);
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
@ -88,9 +93,8 @@ subtest 'config_timestamp is updated when database configuration changes' => sub
Koha::SIP2::Accounts->delete;
Koha::SIP2::SystemPreferenceOverrides->delete;
my $builder = t::lib::TestBuilder->new();
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
my ( $response, $findpatron );
my $builder = t::lib::TestBuilder->new();
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
my $seen_patron = $builder->build_object(
{
class => 'Koha::Patrons',
@ -128,7 +132,7 @@ subtest 'config_timestamp is updated when database configuration changes' => sub
}
)->store();
my $cfg = C4::SIP::Sip::Configuration->get_configuration();
my $cfg = C4::SIP::Sip::Configuration->get_configuration( undef, $fileSIPconfig );
is(
$cfg->{accounts}->{ $sip_account->login_id }->{allow_fields}, '',
@ -140,7 +144,7 @@ subtest 'config_timestamp is updated when database configuration changes' => sub
sleep 1;
$sip_account->allow_fields('AB')->store();
$cfg = C4::SIP::Sip::Configuration->get_configuration();
$cfg = C4::SIP::Sip::Configuration->get_configuration( undef, $fileSIPconfig );
my $last_timestamp = $cache->get_from_cache("sip2_resource_last_modified");