@@ -, +, @@ --- C4/Stats.pm | 7 ++++--- t/db_dependent/Koha/Pseudonymization.t | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) --- a/C4/Stats.pm +++ a/C4/Stats.pm @@ -124,9 +124,6 @@ sub UpdateStats { my $location = exists $params->{location} ? $params->{location} : undef; my $ccode = exists $params->{ccode} ? $params->{ccode} : ''; - # If $branch is set to an invalid branchcode, like 'OPACRenew' - $branch = undef if $branch && ! Koha::Libraries->find($branch); - my $dtf = Koha::Database->new->schema->storage->datetime_parser; my $statistic = Koha::Statistic->new( { @@ -143,6 +140,10 @@ sub UpdateStats { } )->store; + + # If $branch is set to an invalid branchcode, like 'OPACRenew' + $statistic->branch(undef) if $branch && ! Koha::Libraries->find($branch); + Koha::PseudonymizedTransaction->new_from_statistic($statistic)->store if C4::Context->preference('Pseudonymization') && $borrowernumber # Not a real transaction if the patron does not exist --- a/t/db_dependent/Koha/Pseudonymization.t +++ a/t/db_dependent/Koha/Pseudonymization.t @@ -212,7 +212,7 @@ subtest 'PseudonymizedBorrowerAttributes tests' => sub { }; subtest 'invalid branchcode' => sub { - plan tests => 1; + plan tests => 2; $schema->storage->txn_begin; @@ -239,7 +239,10 @@ subtest 'invalid branchcode' => sub { ); my $stat = Koha::Statistics->search({itemnumber => $item->itemnumber}); - is( $stat->next->branch, undef, 'UpdateStats does not explode if branchcode is invalid' ); + is( $stat->next->branch, $branchcode, 'UpdateStats does not explode if branchcode is invalid, and stat logs the branchcode as it' ); + + my $p = Koha::PseudonymizedTransactions->search({itemnumber => $item->itemnumber}); + is( $p->next->transaction_branchcode, undef, 'Pseudonymized transactions logged branchcode=NULL if invalid branchcode passed' ); $schema->storage->txn_rollback; }; --