diff --git a/C4/SIP/SIPServer.pm b/C4/SIP/SIPServer.pm index 545c19b90f..97f452e2cb 100644 --- a/C4/SIP/SIPServer.pm +++ b/C4/SIP/SIPServer.pm @@ -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 diff --git a/C4/SIP/Sip/Configuration.pm b/C4/SIP/Sip/Configuration.pm index 7d1179da65..41b4288577 100644 --- a/C4/SIP/Sip/Configuration.pm +++ b/C4/SIP/Sip/Configuration.pm @@ -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 diff --git a/Koha/REST/V1/SIP2/Accounts.pm b/Koha/REST/V1/SIP2/Accounts.pm index 8103ef395a..e57f4c652f 100644 --- a/Koha/REST/V1/SIP2/Accounts.pm +++ b/Koha/REST/V1/SIP2/Accounts.pm @@ -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($_); }; diff --git a/Koha/REST/V1/SIP2/Institutions.pm b/Koha/REST/V1/SIP2/Institutions.pm index 74173427dd..f63acfdc01 100644 --- a/Koha/REST/V1/SIP2/Institutions.pm +++ b/Koha/REST/V1/SIP2/Institutions.pm @@ -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 diff --git a/Koha/SIP2/Account/CustomItemField.pm b/Koha/SIP2/Account/CustomItemField.pm index 0c9a0e67d9..00732413e1 100644 --- a/Koha/SIP2/Account/CustomItemField.pm +++ b/Koha/SIP2/Account/CustomItemField.pm @@ -41,9 +41,9 @@ sub get_for_config { my ($self) = @_; return { - 'field' => $self->field, + 'field' => $self->field, 'template' => $self->template, - } + }; } =head2 Internal methods diff --git a/Koha/SIP2/Account/ItemField.pm b/Koha/SIP2/Account/ItemField.pm index 3012e4bb0e..132d3e0154 100644 --- a/Koha/SIP2/Account/ItemField.pm +++ b/Koha/SIP2/Account/ItemField.pm @@ -42,8 +42,8 @@ sub get_for_config { return { 'field' => $self->field, - 'code' => $self->code, - } + 'code' => $self->code, + }; } =head2 Internal methods diff --git a/Koha/SIP2/Accounts.pm b/Koha/SIP2/Accounts.pm index 880fee6dab..33d1430aa4 100644 --- a/Koha/SIP2/Accounts.pm +++ b/Koha/SIP2/Accounts.pm @@ -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 diff --git a/Koha/SIP2/Institutions.pm b/Koha/SIP2/Institutions.pm index e14d1de643..0e2476d875 100644 --- a/Koha/SIP2/Institutions.pm +++ b/Koha/SIP2/Institutions.pm @@ -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 diff --git a/Koha/SIP2/Object.pm b/Koha/SIP2/Object.pm index 082a7562cd..a4d7cd3ede 100644 --- a/Koha/SIP2/Object.pm +++ b/Koha/SIP2/Object.pm @@ -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; diff --git a/sip2/sip2.pl b/sip2/sip2.pl old mode 100644 new mode 100755 diff --git a/t/db_dependent/Koha/SIP2/SIP2ModuleMigration.t b/t/db_dependent/Koha/SIP2/SIP2ModuleMigration.t old mode 100644 new mode 100755 index cc53517e93..56f399751c --- a/t/db_dependent/Koha/SIP2/SIP2ModuleMigration.t +++ b/t/db_dependent/Koha/SIP2/SIP2ModuleMigration.t @@ -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");